×
Namespaces

Variants
Actions
(Difference between revisions)

Dynamic objects Adding/removal with Qt Quick Map API

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Addition to article of: Category:MeeGo Category:Symbian. (Add platform categories))
hamishwillee (Talk | contribs)
m (Text replace - "Category:MeeGo" to "Category:MeeGo Harmattan")
Line 51: Line 51:
 
</code>
 
</code>
 
   
 
   
With the snippeds the "Script.myCirclesArray" is javascript array. Full example for the workaround can be found from [[Media:QML_DynamicPolyline.zip | QML_DynamicPolyline.zip]] example.[[Category:MeeGo]] [[Category:Symbian]]
+
With the snippeds the "Script.myCirclesArray" is javascript array. Full example for the workaround can be found from [[Media:QML_DynamicPolyline.zip | QML_DynamicPolyline.zip]] example.[[Category:MeeGo Harmattan]] [[Category:Symbian]]

Revision as of 13:52, 13 June 2012

With QML Map element you can add following items to the Map element:

  • MapPolygon: for general polygon objects
  • MapPolyline: for general polyline objects
  • MapCircle: for Circle objects (polygon)
  • MapRectangle: for Rectangle objects (polygon)
  • MapText: for textual map objects
  • MapImage: for Icon (marker/pushpin) objects.


Basically if you know the elements to be shown on coding time, you can easily define the objects inside the Map element and use the visible variable to set them hidden/visible. This would mean that no actual dynamic handling is required. Here’s simple code example on toggling the visibility of a polyline objec

if(polylines.visible)
polylines.visible = false;
else
polylines.visible = true;

Full examples on this kind of content handling can be found from QML_SimpleMapContent.zip‎ and QML_MoreMapContent.zip‎ examples.

You can also manage map objects in groups by using the MapGroup element. Note though that with some versions there is a bug that prevents the visible variable working for MapGroup. The workaround is to use the objects array, and to loop the items inside the MapGroup one by one and set their visibility individually:

for (var i = 0; i < icons.objects.length; ++i) {
icons.objects[i].visible = icons.visible;
}


Full example for the workaround is also shown in QML_SimpleMapContent.zip‎ example with MapImages inside a MapGroup.

If the objects need to be specified on run time, or if real dynamic handling of the content objects is required, you can use the addMapObject/removeMapObject functions defined for the Map element. Already added objects should be visible in objects, though note a bug effecting some versions, where the objects is not defined, and thus can not be used.

One possible workaround for the missing objects array, is to define own javascript array and use it to track the objects added to the Map. For example adding a new circle object into the Map could be handled as follows:

var newCircle = Qt.createQmlObject('import QtQuick 1.1;import QtMobility.location 1.2; MapCircle {color: "#40FF0000"; radius: 3000; }',map, "dynamicSnippet1");
newCircle.center = map.toCoordinate(Qt.point(mouse.x,(mouse.y - titleBar.height)));
 
Script.myCirclesArray.push(newCircle);
map.addMapObject(newCircle);

Removing of the object could then be handled for example like this

map.removeMapObject(Script.myCirclesArray[__SelectedCircle]);
Script.myCirclesArray.splice(__SelectedCircle,1)

With the snippeds the "Script.myCirclesArray" is javascript array. Full example for the workaround can be found from QML_DynamicPolyline.zip example.

91 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×