May 1, 2012

0livier 0livier
Lab Rat
1 posts

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 :

  1. var component = Qt.createComponent("Station.qml");
  2. for(var i=0;i<stationsXMLModel.count;i++){
  3.     var object = component.createObject(mapview, {
  4.                                             "latitude": stationsXMLModel.get(i).latitude,
  5.                                             "longitude": stationsXMLModel.get(i).longitude,
  6.                                             "number":stationsXMLModel.get(i).number});
  7.     if (object.status == Component.Ready) {
  8.         stationsArray.push(object);
  9.     }
  10.     if (object.status == Component.Error) {
  11.         console.log("Error: " + component.errorString());
  12.     }
  13. }

When “Station.qml” contains a MapImage (see below), everything works as expected

  1. MapImage {
  2.     source:  "images/station.png"
  3.     property alias latitude: mapMarkerCoordinate.latitude
  4.     property alias longitude: mapMarkerCoordinate.longitude
  5.     property int number
  6.     coordinate: Coordinate { id: mapMarkerCoordinate }
  7.     offset.x: -24
  8.     offset.y: -48
  9. }

But if it is a MapGroup (see below), “object.status” reads “undefined”.

  1. MapGroup {
  2.     property alias latitude: mapMarkerCoordinate.latitude
  3.     property alias longitude: mapMarkerCoordinate.longitude
  4.     property int number
  5.  
  6.     MapImage{
  7.     source:  "images/station.png"
  8.     coordinate: Coordinate { id: mapMarkerCoordinate }
  9.     offset.x: -24
  10.     offset.y: -48
  11.     }
  12. }

What am Missing ? Is there any restriction on the type of QML that can be loaded dynamically ?

Thanks for your help,

Olivier

2 replies

May 3, 2012

chriadam chriadam
Lab Rat
178 posts

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.

May 4, 2012

0livier 0livier
Lab Rat
1 posts

Thanks for your reply.

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

Any hint ?

Olivier

 
  ‹‹ Error:QtSdk-offline-linux-x86-v1.2.1.run: cannot connect to X server      Why does QtQuick does not have TouchArea (like MouseArea) ? ››

You must log in to post a reply. Not a member yet? Register here!