On Tue, 6 Sep 2016 19:04:34 +0530 Kishore J <kitts.mailingli...@gmail.com> wrote:
> Hi > > I am inching forward with using QML maps in my C++ application. Now > i'm interested in dynamically adding multiple MapItemView objects to > a given map. > > > import QtQuick 2.5 > import QtLocation 5.6 > > Map { > id: map > objectName: "MyMap" > // zoomLevel: (maximumZoomLevel - minimumZoomLevel)/2 > zoomLevel: minimumZoomLevel > > plugin: Plugin { > name: "here" > PluginParameter {name: "here.app_id"; value: "xxxxx"} > PluginParameter {name: "here.token"; value: "xxxxx"} > } > // activeMapType: supportedMapTypes[3] > center { > latitude: 10 > longitude: 20 > } > > MapCircle { > id: staticCircle > center { > latitude: 5 > longitude: 10 > } > radius: 500000.0 > color: 'yellow' > border.width: 4 > border.color: 'yellow' > Component.onCompleted: { > console.debug("Loaded static MapCircle") > console.debug(center + ' radius: ' + radius) > } > Component.onDestruction: { > console.debug("Unloaded static MapCircle") > } > } > > MapItemView { > id: mapitemview > objectName: "MyMapItemView" > model: ListModel { > id: list > ListElement{lat: 10; lon: 20; rad: 800000} > ListElement{lat: 30; lon: 40; rad: 700000} > } > delegate: Component { > id: delegate > > MapCircle { > id: dynmapcircle > center { > latitude: lat; > longitude: lon; > } > radius: 500000.0 > color: 'black' > border.width: 4 > border.color: 'black' > Component.onCompleted: { > console.count("Loaded a MapCircle") > map.addMapItem(dynmapcircle) > } > } > } > > Component.onCompleted: { > console.debug("Loaded first MapItemView") > console.debug(model.count) > } > Component.onDestruction: { > console.debug("Unloaded first MapItemView") > } > } > > MapItemView { > id: mapitemview2 > objectName: "MyMapItemView2" > model: ListModel { > id: list2 > ListElement{lat: -10; lon: 20; rad: 800000} > ListElement{lat: -30; lon: 40; rad: 700000} > } > delegate: Component { > id: delegate2 > > MapCircle { > id: dynmapcircle2 > center { > latitude: lat; > longitude: lon; > } > radius: 500000.0 > color: 'blue' > border.width: 4 > border.color: 'blue' > Component.onCompleted: { > console.count("Loaded a MapCircle2") > map.addMapItem(dynmapcircle2) > } > } > } > > Component.onCompleted: { > console.debug("Loaded second MapItemView") > } > Component.onDestruction: { > console.debug("Unloaded second MapItemView") > } > } > > Component.onCompleted:{ > center.latitude = 10 > center.longitude = 20 > console.debug('Loaded map ' + map.center) > } > Component.onDestruction:{ > console.debug('Unloaded map') > } > } > > Further, i do not understand why i have to call the map.addMapItem() > function for each MapItem. I suspect that, that is the source of my > problem. I am currently able to define a separate qml file containing > the second MapItemView which i instantiate in C++ and set the map as > it's parent but that does not work. > > Any help would be appreciated. > -- > Regards, > Kishore > > PS: I also seem to be facing another issue where the center value > specified in the map initialization does not work and I have to set > the center in the onCompleted() slot. Funnily, it only considers the > Latitude or Longitude value in the initialization depending on which > is first specified! Hi, for the first question, the answer is "you can't". This is a limitation of the current API, and something that might be worthwile extending. So feel free to send a feature request to jira. For the second question, please have a look if the (now merged) patch fixes your bug best, Paolo _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest