【问题标题】:Launch filterAcceptsRow after a displacement/zoom of a qml map is stabilized在 qml 地图的位移/缩放稳定后启动 filterAcceptsRow
【发布时间】:2018-01-04 20:33:31
【问题描述】:

在 QML 地图上,使用“onCenterChanged”捕获用户激活的移动,要显示的点的过滤过程在移动启动后立即开始。

鉴于在此操作期间要处理大量数据,我希望它仅在地图完全稳定后开始(停止滑动/缩放,释放鼠标左键和鼠标滚轮不活动)。

这是 QML Map 的 sn-p

Map {
    id: mainMap
    anchors.centerIn: parent;
    anchors.fill: parent
    plugin: Plugin {name: "osm"}
    center: startingPoint
    zoomLevel: 4.5

    onCenterChanged: {
        updateBoundingBox()
    }

    MapItemView {
        id:viewPointOnMap
        model: navaidsFilter
        delegate: Marker{}
    }

    onMapReadyChanged: {
        updateBoundingBox()
    }

    function updateBoundingBox(){
        navaidsFilter.bBox = mainMap.visibleRegion.boundingGeoRectangle() //boundingBox
    }

}//Map

和过滤器 sn-ps :

void NavaidsFilter::setBBox(const QGeoRectangle &bbox)
{
    if(m_processedZone.isEmpty()|| !m_processedZone.contains(bbox)){  //First bbox or displacement/zoom out of the previous box
        m_processedZone = bbox;
        m_boundaryZone = bbox;
        invalidateFilter();
    }
}

bool NavaidsFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
    if(!m_boundaryZone.isValid()){
        return false;
    }

    QModelIndex ix = sourceModel()->index(sourceRow, 0, sourceParent);
    QGeoCoordinate pos = ix.data(NavaidsModel::PositionRole).value<QGeoCoordinate>();
    return m_boundaryZone.contains(pos);
}

我们怎样才能做到这一点?

感谢您的帮助

【问题讨论】:

    标签: qt location qml


    【解决方案1】:

    我从未与Map 合作过,所以我不知道具体的解决方案。以下是两种适用于许多情况的通用解决方案:

    1. 引入一个聚合所有相关状态的属性

      readonly property bool moving: mainMap.gesture.rotationActive
                                     | mainMap.gesture.tiltingActive
                                     | ...`
      

      一旦此属性更改为false,请执行必要的操作。 (onMovingChanged)


    1. 使用Timer 重新启动,每当发生变化时。如果在某些 ms 内没有任何变化,让它触发并执行必要的操作。

    【讨论】:

    • 感谢 derM。因此尝试使用 magGestureArea 并添加gesture.enabled: true 和gesture.acceptedGestures: MapGestureArea.PanGesture 以便使用onPanFinished 来启动更新而不是onCenterChanged。但是我面临这个问题:无法分配给不存在的属性“onPanFinished”。你有删除它的提示吗?
    猜你喜欢
    • 2019-07-10
    • 1970-01-01
    • 2016-11-04
    • 1970-01-01
    • 2014-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多