Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Animate change in position and bearing QML Map using setBearing and alignCoordinateToPoint
QtWS25 Last Chance

Animate change in position and bearing QML Map using setBearing and alignCoordinateToPoint

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 443 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jenny R
    wrote on 12 Apr 2024, 13:03 last edited by
    #1

    I have a project where I display a map using the MapView component. I use the Map component's functions alignCoordinateToPoint and setBearing to "center" the map with an offset and rotate around a certain point. When I update the position and bearing I would prefer using alignCoordinateToPoint and setBearing to keep the offset centering. All this works well, but I would like the change in position and bearing to be animated, to make it look smoother. However, I cannot find a way to animate the change caused by calling these two functions.

    Is there a way to do this?

    Thanks!

    J 1 Reply Last reply 19 Apr 2024, 07:17
    0
    • J Jenny R
      12 Apr 2024, 13:03

      I have a project where I display a map using the MapView component. I use the Map component's functions alignCoordinateToPoint and setBearing to "center" the map with an offset and rotate around a certain point. When I update the position and bearing I would prefer using alignCoordinateToPoint and setBearing to keep the offset centering. All this works well, but I would like the change in position and bearing to be animated, to make it look smoother. However, I cannot find a way to animate the change caused by calling these two functions.

      Is there a way to do this?

      Thanks!

      J Offline
      J Offline
      Jenny R
      wrote on 19 Apr 2024, 07:17 last edited by
      #2

      @Jenny-R I solved the problem by using this solution: https://stackoverflow.com/questions/58874314/animating-bearing-property-change-with-qml-map.

      Some additions and clarifications: I placed the RotationAnimation component on the same level as the MapView and placed the property "myBearing" and "onMyBearingChanged" inside the MapView component. The animation is then called from whereever the change should be triggered. I.e., a separate property (myBearing) is animated and every time the property is changed, setBearing() is called. alignCoordinateToPoint is handled in a similar way.

      Code example:

      MapView {
              id: mapView
      
              property real myBearing
              property geoCoordinate myCenter
      
              anchors.fill: parent
              z: 0
      
              map {
                  plugin: mapPlugin
                  zoomLevel: 14
                  center: QtPositioning.coordinate(51.507622, -0.127855) 
              }
      
              onMyBearingChanged: {
                  mapView.map.setBearing(myBearing, predefinedAlignmentPoint)
              }
      
              onMyCenterChanged: {
                  mapView.map.alignCoordinateToPoint(myCenter, predefinedAlignmentPoint)
              }
          }
      
      RotationAnimation {
          id: bearingAnimation
          target: mapView
          property: "myBearing"
          direction: RotationAnimation.Shortest
          duration: 1000
      
          function startBearingAnimation(to)
          {
              bearingAnimation.stop()
              bearingAnimation.from = mapView.map.bearing
              bearingAnimation.to = to
              if (bearingAnimation.from  !== bearingAnimation.to) {
                  bearingAnimation.start()
              }
          }
      }
      
      CoordinateAnimation{
          id: centerAnimation
          target: mapView
          property: "myCenter"
          to: QtPositioning.coordinate(newLatitude, newLongitude)
          duration: 1000
      }
      
      1 Reply Last reply
      0
      • J Jenny R has marked this topic as solved on 19 Apr 2024, 07:17

      2/2

      19 Apr 2024, 07:17

      • Login

      • Login or register to search.
      2 out of 2
      • First post
        2/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved