Can I dynamically add a MapGroup to a Map?
I have managed to dynamically add MapImages to a map but fail to add MapGroups. Is there something I am missing ?
the javascript code used to add the component is the following :
- for(var i=0;i<stationsXMLModel.count;i++){
- var object = component.createObject(mapview, {
- "latitude": stationsXMLModel.get(i).latitude,
- "longitude": stationsXMLModel.get(i).longitude,
- "number":stationsXMLModel.get(i).number});
- if (object.status == Component.Ready) {
- stationsArray.push(object);
- }
- if (object.status == Component.Error) {
- console.log("Error: " + component.errorString());
- }
- }
When “Station.qml” contains a MapImage (see below), everything works as expected
- MapImage {
- source: "images/station.png"
- property alias latitude: mapMarkerCoordinate.latitude
- property alias longitude: mapMarkerCoordinate.longitude
- property int number
- coordinate: Coordinate { id: mapMarkerCoordinate }
- offset.x: -24
- offset.y: -48
- }
But if it is a MapGroup (see below), “object.status” reads “undefined”.
- MapGroup {
- property alias latitude: mapMarkerCoordinate.latitude
- property alias longitude: mapMarkerCoordinate.longitude
- property int number
- MapImage{
- source: "images/station.png"
- coordinate: Coordinate { id: mapMarkerCoordinate }
- offset.x: -24
- offset.y: -48
- }
- }
What am Missing ? Is there any restriction on the type of QML that can be loaded dynamically ?
Thanks for your help,
Olivier
2 replies
After calling Qt.createComponent, can you console.log(component.errorString()) to ensure that it was compiled correctly? I don’t know much/anything about the location/maps module, so I don’t know what specifically could be wrong.
/edit: presumably MapImage has a “status” property, while the MapGroup element does not? I’m not sure.
You must log in to post a reply. Not a member yet? Register here!
