QT地图:沿地图路线动画图像

时间:2016-10-02 23:41:02

标签: c++ qt

你好亲爱的程序员。 我正在寻找一个很容易让汽车沿着qt地图上的路线行驶。 汽车是一些图像打包在MapQuickItem中。 Qt Route Model给出了一条路径,它作为路径属性,本质上是一个点列表。我想要做的是沿着这条路径动画MapQuickItem。

ApplicationWindow {

 Location {
        id: mapCentre
        coordinate {
            latitude: -27.5
            longitude: 153.1
        }
    }
     Image {
            id: homeImage
            source: "home.png"
    }
    Map {
        id: map
        anchors.centerIn: parent;
        anchors.fill: parent
        zoomLevel: 11
        objectName: "mainMap"

        plugin: Plugin {
          name: "here"
          PluginParameter { name: "here.app_id"; value: "R9qav4Kw6gO5XKSxNiOO" }
          PluginParameter { name: "here.token"; value: "58UCNRCr1dZxhLL2Bmmz3Q" }
          PluginParameter { name: "here.proxy"; value: "system" }
      }
       MapQuickItem {
            id: marker
            sourceItem: homeImage
            anchorPoint.x: homeImage.width/4
            anchorPoint.y: homeImage.height
            coordinate {
                latitude: mapCentre.coordinate.latitude;
                longitude:  mapCentre.coordinate.longitude;
            }
     function calculateCoordinateRoute(startCoordinate, endCoordinate)
       {
           // clear away any old data in the query
           routeQuery.clearWaypoints();

           // add the start and end coords as waypoints on the route
           routeQuery.addWaypoint(startCoordinate)
           routeQuery.addWaypoint(endCoordinate)
           routeQuery.travelModes = RouteQuery.PedestrianTravel
           routeQuery.routeOptimizations = RouteQuery.FastestRoute
           routeModel.update();

           /*for (var i=0; i<9; i++) {
               routeQuery.setFeatureWeight(i, 0)
           }
           //for (var i=0; i<routeDialog.features.length; i++) {
           //    map.routeQuery.setFeatureWeight(routeDialog.features[i], RouteQuery.AvoidFeatureWeight)
           //}*/
           // center the map on the start coord
           map.center = startCoordinate;
       }
     RouteModel {
        id: routeModel
        plugin : map.plugin
        query:  RouteQuery {
            id: routeQuery
        }
        onStatusChanged: {
            if(routeModel.status == RouteModel.Ready && routeModel.count > 0){
               console.log("loaded");
               var route =routeModel.get(0);
               var path = route.path;
               var start = path[0];
            }
        }
    }
}

简短说明:路线模型更新是异步的,所以我必须在onStatusChanged回调中做我的东西。

我想沿着地图上的路径移动MapQuickItem标记。

0 个答案:

没有答案