0

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
        }
    }
}
fullon
  • 11
  • 1
  • 5
  • Then create another RouteModel – eyllanesc Apr 20 '18 at 16:32
  • I did, and I created another MapItemView for the new RouteModel. Only one route was displayed... – fullon Apr 20 '18 at 17:18
  • Show that intent, to indicate what was the problem, I think that will serve you more. – eyllanesc Apr 20 '18 at 17:19
  • I edited the question if you could please look at it again, thank you – fullon Apr 20 '18 at 17:29
  • 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 Apr 20 '18 at 17:32
  • I have a list of routes with startCoordinates and endCoordinates in a csv file and I'm just hardcoding some of the coordinates to see if I can display more than one route simultaneously... This is the github link if you can check it out, https://github.com/hindaljabr/routemaps – fullon Apr 20 '18 at 17:40
  • Share your .csv in your question. – eyllanesc Apr 20 '18 at 17:43
  • the idea is to dynamically create the routes, or do you plan to count the routes, modify the .qml so that they have the n-routes and launch it? I think the code should read the .csv routes and create everything dynamically. – eyllanesc Apr 20 '18 at 17:45
  • Ok but It's too long so I just uploaded it in the github link – fullon Apr 20 '18 at 17:46
  • My end goal is to display multiple colored routes from this file – fullon Apr 20 '18 at 17:47
  • I understand that each row is a different route, am I right? – eyllanesc Apr 20 '18 at 17:49
  • Exactly, each row is a route – fullon Apr 20 '18 at 17:50
  • Any idea how to view multiple routes simultaneously? without worrying about the csv file for now, I just have 3 routes – fullon Apr 20 '18 at 18:21
  • I'm working on it, when I have something workable I'll publish it. – eyllanesc Apr 20 '18 at 18:23
  • According to my tests I see that since the RouteModel are using the same plugin all are notified when the data is obtained, so they will all have the same data, so that behavior is observed. A possible solution is to do the query one by one, and save the data. – eyllanesc Apr 22 '18 at 09:33
  • can someone fix that question? there's no such routeData1, routeData2, ... – Pa_ May 21 '18 at 10:53

2 Answers2

0

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.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
-1

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.

Pa_
  • 641
  • 1
  • 5
  • 17