1

我正在尝试为 Qml 地图上的方位属性更改设置动画:

Map {
    id: map
    Behavior on bearing {
        enabled: true
        RotationAnimation {
            direction: RotationAnimation.Shortest
            duration: 500
            easing.type: Easing.Linear
        }
    }

    Button {
        onClicked: map.bearing = 100 // animation works. Map rotation is animated
    }

    Button {
        onClicked: map.setBearing(100, Qt.point(10,10)) // animation does not work. Map rotates immediately to the bearing
    }
}

当直接使用设置方位时map.bearing,动画将起作用。但是当使用辅助方法时map.setBearing,动画不起作用。有没有办法将动画与map.setBearing方法一起获取?

问候,

4

1 回答 1

1

我敢打赌,您需要另一个单独的 setBearing 可调用动画。您在行为中拥有的那个不能涵盖您添加的用例,因为它在属性上运行,而 setBearing 重载,严格来说,绕过属性并且仅在完成后触发更新的信号。

就像是

        RotationAnimation {
            id: bearingAnimation
            target: <yourmap>
            property: "myBearing"
            direction: RotationAnimation.Shortest
            duration: 360

            function distance(a, b)
            {
                var mx = Math.max(a, b)
                var mn = Math.min(a, b)

                return Math.min( mx - mn, mn + 360 - mx)
            }

            function startBearingAnimation(to)
            {
                bearingAnimation.stop()
                bearingAnimation.from = <yourmap>.bearing
                bearingAnimation.to = to
                if (bearingAnimation.from  !== bearingAnimation.to) {
                    bearingAnimation.duration = distance(bearingAnimation.from, bearingAnimation.to) * 2
                    bearingAnimation.start()
                }
            }
        }

接着

    property real myBearing
    onMyBearingChanged {
         <yourmap>.setBearing(myBearing, <thepoint>)
    }
于 2019-11-15T18:36:49.020 回答