×
Namespaces

Variants
Actions
(Difference between revisions)

Dynamic objects Adding/removal with Qt Quick Map API

From Nokia Developer Wiki
Jump to: navigation, search
jasfox (Talk | contribs)
m (Jasfox - Corrected Category)
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Add ArticleMetadata)
(2 intermediate revisions by one user not shown)
Line 1: Line 1:
 +
{{ArticleMetaData <!-- v1.2 -->
 +
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
 +
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 +
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
 +
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Qt SDK 1.1.4]) -->
 +
|platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later -->
 +
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 +
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase -->
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20111004
 +
|author= [[User:Symbianyucca]]
 +
}}
 
[[Category:Qt Quick]][[Category:Qt Mobility]][[Category:Nokia Maps]][[Category:Code Snippet]]
 
[[Category:Qt Quick]][[Category:Qt Mobility]][[Category:Nokia Maps]][[Category:Code Snippet]]
 
With QML Map element you can add following items to the Map element:   
 
With QML Map element you can add following items to the Map element:   
Line 19: Line 41:
 
</code>
 
</code>
 
   
 
   
Full examples on this kind of content handling can be found from [[Media:QML_SimpleMapContent.zip | QML_SimpleMapContent.zip‎]] and [[Media:QML_MoreMapContent.zip | QML_MoreMapContent.zip‎]] examples.
+
Full examples on this kind of content handling can be found from [[Media:QML SimpleMapContent.zip | QML SimpleMapContent.zip‎]] and [[Media:QML MoreMapContent.zip | QML MoreMapContent.zip‎]] examples.
 
   
 
   
 
You can also manage map objects in groups by using the MapGroup element. Note though that
 
You can also manage map objects in groups by using the MapGroup element. Note though that
Line 31: Line 53:
  
  
Full example for the workaround is also shown in [[Media:QML_SimpleMapContent.zip | QML_SimpleMapContent.zip‎]] example with MapImages inside a MapGroup.  
+
Full example for the workaround is also shown in [[Media:QML SimpleMapContent.zip | 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 [https://bugreports.qt.nokia.com/browse/QTMOBILITY-1879 a bug] effecting some versions, where the objects is not defined, and thus can not be used.
 
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 [https://bugreports.qt.nokia.com/browse/QTMOBILITY-1879 a bug] effecting some versions, where the objects is not defined, and thus can not be used.
Line 51: Line 73:
 
</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.
+
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]]
 +
[[Category:Code Examples]]

Revision as of 09:16, 20 July 2012

Article Metadata
Compatibility
Platform(s):
Symbian
Article
Created: symbianyucca (04 Oct 2011)
Last edited: hamishwillee (20 Jul 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.

131 page views in the last 30 days.
×