【问题标题】:How to rotate map in qml?如何在qml中旋转地图?
【发布时间】:2021-04-17 00:09:13
【问题描述】:

如何使用 MouseArea(按下 MidButton)在 qml 中旋转地图?

Map {
    id: map
    z: 0.1
    anchors.fill: parent

    property bool mapIsEmpty: submap && (submap.plugin.name === "itemsoverlay")
    property string provider: "itemsoverlay"

    // need for called outside
    function openWizzardAddImage() {
        wizzardAddImage.show();
    }

    zoomLevel: 14
    maximumZoomLevel: 20
    minimumZoomLevel: 14
    gesture.enabled: gestureEnabled
    gesture.acceptedGestures: MapGestureArea.PanGesture
                              | MapGestureArea.PinchGesture
                              | MapGestureArea.RotationGesture
    color: "transparent"
    plugin: Plugin { name: "itemsoverlay" }
    MouseArea {
        id: _mouseArea
        anchors.fill: parent
        hoverEnabled: true
        acceptedButtons: Qt.AllButtons

        function coord(mouse) {
            return map.toCoordinate(Qt.point(mouse.x,mouse.y),false)
        }

        onClicked: {
            if (mouse.button == Qt.RightButton) {
                map.clickedContextMenu(coord(mouse))
            }
            else if (mouse.button == Qt.LeftButton) {
                map.clicked(coord(mouse))
            }

        }
        onPositionChanged: {
            if (mouse.button == Qt.RightButton)
                coordText.coordinate = coord(mouse)
        }
        onDoubleClicked: {
            if (mouse.button == Qt.LeftButton)
                map.doubleClicked(_mouseArea.coord(mouse))
        }
        onWheel: {
            if (wheel.modifiers && Qt.ControlModifier )
                return

            wheel.accepted = map.noWheel
        }
    }
 }

我启用了 MouseArea 和类似手势,但是当按下鼠标中键时如何围绕光标旋转地图? 附:我用谷歌搜索了 MapGesture,但它仅在您点击屏幕时才有效(有点)。

【问题讨论】:

    标签: qt qml qt5 qt6


    【解决方案1】:

    使用 Map QML 类型的方位属性

    例如

    Map {
            id: map
            anchors.fill: parent
            plugin:Plugin {
                name: "osm"
            }
            zoomLevel: 15
            bearing: 20        // for rotating map
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-10
      • 2021-08-08
      • 2015-01-14
      • 2020-05-26
      • 1970-01-01
      相关资源
      最近更新 更多