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 :

    @var component = Qt.createComponent("Station.qml");
    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



  • 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.



  • Thanks for your reply.

    The component.errorString() unfortunately reports an empty string.

    Any hint ?

    Olivier


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.