0
votes

I want to display a list of routes on a map using Qt Location properties, I was able to display one route, but I don't know how to display multiple ones. Here's my code:

RouteModel {
    id: routeModel
    plugin: somePlugin

    query: RouteQuery {}
    Component.onCompleted: {
        query.addWaypoint(QtPositioning.coordinate(26.328045523310905, 50.080033033011546));
        query.addWaypoint(QtPositioning.coordinate(26.333615791655415, 50.097984054173025));
        routeModel.update();
        query.addWaypoint(QtPositioning.coordinate(26.291584, 50.199094));
        query.addWaypoint(QtPositioning.coordinate(26.288128, 50.188725));
        routeModel.update();
    }

    onStatusChanged: console.debug("current route model status", status, count, errorString)
}

I wish for each couple of addWayPoints to be a distinct route. How canI achieve that?

I added multiple models with their correspondent mapitemview, still it didn't work.

RouteModel {
    id: routeModel
    plugin: somePlugin
    query: RouteQuery {}
    Component.onCompleted: {
        query.addWaypoint(QtPositioning.coordinate(26.328045523310905, 50.080033033011546));
        query.addWaypoint(QtPositioning.coordinate(26.333615791655415, 50.097984054173025));
        routeModel.update();
    }
}

RouteModel {
    id: rm
    plugin: somePlugin
    query: RouteQuery {}
    Component.onCompleted: {
        query.addWaypoint(QtPositioning.coordinate(26.291584, 50.199094));
        query.addWaypoint(QtPositioning.coordinate(26.288128, 50.188725));
        rm.update();
    }
}

RouteModel {
    id: rm1
    plugin: somePlugin
    query: RouteQuery {}
    Component.onCompleted: {
        query.addWaypoint(QtPositioning.coordinate(26.278496, 50.203740));
        query.addWaypoint(QtPositioning.coordinate(26.272351, 50.185939));
        rm.update();
    }
}

Map {
    id: map
    anchors.fill: parent
    plugin: somePlugin
    center: magione
    gesture.enabled: true
    zoomLevel: 13


    MapItemView {
        model: routeModel
        delegate: MapRoute {
            route: routeData
            line.color: "blue"
            line.width: 5
            smooth: true
        }
    }

    MapItemView {
        model: rm
        delegate: MapRoute {
            route: routeData1
            line.color: "green"
            line.width: 5
            smooth: true
        }
    }

    MapItemView {
        model: rm2
        delegate: MapRoute {
            route: routeData2
            line.color: "black"
            line.width: 5
            smooth: true
        }
    }
}
2
Then create another RouteModeleyllanesc
I did, and I created another MapItemView for the new RouteModel. Only one route was displayed...fullon
Show that intent, to indicate what was the problem, I think that will serve you more.eyllanesc
I edited the question if you could please look at it again, thank youfullon
A query, I understand that you require n-routes, not just a few. Am I correct? If so, how do you identify a route? Do the routes have an id?eyllanesc

2 Answers

0
votes

I was just trying to do the same task, just accomplished IT. As in your first attempt, you should add multiple addWayPoints, but update the model only once at the end. Here is an example of a route visiting the following places A->B->C->A

    Component.onCompleted:
    {
        query.addWaypoint(QtPositioning.coordinate(-25.402340, -49.248682));
        query.addWaypoint(QtPositioning.coordinate(-25.392142, -49.202556));
        query.addWaypoint(QtPositioning.coordinate(-25.372512, -49.227785));
        query.addWaypoint(QtPositioning.coordinate(-25.402340, -49.248682));
        routeModel.update();
    }

Results in: Multiple routes:
Multiple routes

Just wondering now how do I get pinpoints at each route stoppoint.

-1
votes

Showing all routes returned from a query normally works out of the box (assuming the plugin you are using gives you more than one result per route request).

If you want to simultaneously display routes for multiple requests, you need one model/view per request you want to simultaneously display

I finish pointing out that, in your example, you are using the model roles wrong. There is no such routeData1 or routeData2, but only routeData, and you should use this role every time you try to access the route data from a route model.