Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

Map

The Map element displays a map. More...

Inherits Item

This type was introduced in Qt Location 5.0.

Properties

Methods

Detailed Description

The Map element is used to display a map or image of the Earth, with the capability to also display interactive objects tied to the map's surface.

There are a variety of different ways to visualize the Earth's surface in a 2-dimensional manner, but all of them involve some kind of projection: a mathematical relationship between the 3D coordinates (latitude, longitude and altitude) and 2D coordinates (X and Y in pixels) on the screen.

Different sources of map data can use different projections, and from the point of view of the Map element, we treat these as one replaceable unit: the Map plugin. A Map plugin consists of a data source, as well as all other details needed to display its data on-screen.

The current Map plugin in use is contained in the plugin property of the Map item. In order to display any image in a Map item, you will need to set this property. See the Plugin element for a description of how to retrieve an appropriate plugin for use.

The geographic region displayed in the Map item is referred to as its viewport, and this is defined by the properties center, and zoomLevel. The center property contains a Coordinate specifying the center of the viewport, while zoomLevel controls the scale of the map. See each of these properties for further details about their values.

When the map is displayed, each possible geographic Coordinate that is visible will map to some pixel X and Y coordinate on the screen. To perform conversions between these two, Map provides the toCoordinate and toScreenPosition functions, which are of general utility.

Map Objects

Map objects can be declared within the body of a Map element in QML and will automatically appear on the Map. To add objects programmatically, first be sure they are created with the Map as their parent (for example in an argument to Component::createObject), and then call the addMapItem method on the Map. A corresponding removeMapItem method also exists to do the opposite and remove an object from the Map.

Moving Map objects around, resizing them or changing their shape normally does not involve any special interaction with Map itself -- changing these details about a map object will automatically update the display.

Interaction

The Map element includes support for pinch and flick gestures to control zooming and panning. These are disabled by default, but available at any time by using the flick and pinch objects. These properties themselves are read-only: the actual Flickable and PinchArea are constructed specially at startup and cannot be replaced or destroyed. Their properties can be altered, however, to control their behavior.

Mouse and touch interaction with Maps and map objects is slightly different to ordinary QML elements. In a Map or Map object, you will need to make use of the MapMouseArea element instead of the normal Qt Quick MouseArea. MapMouseArea is, in almost all respects, a drop-in replacement for MouseArea, but the documentation for that element should be referred to for further details.

Performance

Maps are rendered using OpenGL (ES) and the Qt Scene Graph stack, and as a result perform quite well where GL accelerated hardware is available.

For "online" Map plugins, network bandwidth and latency can be major contributors to the user's perception of performance. Extensive caching is performed to mitigate this, but such mitigation is not always perfect. For "offline" plugins, the time spent retrieving the stored geographic data and rendering the basic map features can often play a dominant role. Some offline plugins may use hardware acceleration themselves to (partially) avert this.

In general, large and complex Map items such as polygons and polylines with large numbers of vertices can have an adverse effect on UI performance. Further, more detailed notes on this are in the documentation for each map item element.

Example Usage

The following snippet shows a simple Map and the necessary Plugin element to use it. The map is centered near Brisbane, Australia, zoomed out to the minimum zoom level, with Flickable panning enabled.

 Plugin {
     id: somePlugin
     // code here to choose the plugin as necessary
 }

 Map {
     id: map

     plugin: somePlugin

     center: Coordinate { latitude: -27; longitude: 153 }
     zoomLevel: map.minimumZoomLevel

     flick.enabled: true
 }

Property Documentation

activeMapType : MapType

This property can be set to change the active map type. See the supportedMapTypes property for possible values.

See also MapType.


bearing : real

This property holds the current bearing (starting from 0 and increasing clockwise to 359,9 degrees) pointing up.

For example setting bearing to 10 will set bearing 10 to point up, which visually looks like rotating the map counter-clockwise.

You can also assign negative values, which will internally get translated into positive bearing (for example -10 equals 350). This is primarily for convenience (for example you can decrement bearing without worrying about it). Assigning values greater than abs(360) will be mod'd (for example 365 will result in 5).

The default value is 0 corresponding North pointing up.


center : Coordinate

This property holds the coordinate which occupies the center of the mapping viewport.

The default value is an arbitrary valid coordinate.


read-onlyflick : MapFlickable

Contains the MapFlickable created with the Map. Use flick.enabled: true to enable basic flick gestures, or see MapFlickable for further details. This object will be deprecated, use the gesture object instead.


read-onlygesture : MapPinchArea

Contains the MapGestureArea created with the Map. This covers pan, flick and pinch gestures. Use gesture.enabled: true to enable basic gestures, or see MapGestureArea for further details.


read-onlymapItems : list<MapItem>

Returns the list of all map items in no particular order. These items include items that were declared statically as part of the element declaration, as well as dynamical items (addMapItem, MapItemView).

See also addMapItem, removeMapItem, and clearMapItems.


read-onlymaximumZoomLevel : real

This property holds the maximum valid zoom level for the map.

The maximum zoom level is defined by the plugin used. If a plugin supporting mapping is not set, -1.0 is returned.


read-onlyminimumZoomLevel : real

This property holds the minimum valid zoom level for the map.

The minimum zoom level is defined by the plugin used. If a plugin supporting mapping is not set, -1.0 is returned.


read-onlypinch : MapPinchArea

Contains the MapPinchArea created with the Map. Use pinch.enabled: true to enable basic pinch gestures, or see MapPinchArea for further details. This object will be deprecated, use the gesture object instead.


plugin : Plugin

This property holds the plugin which provides the mapping functionality.

This is a write-once property. Once the map has a plugin associated with it, any attempted modifications of the plugin will be ignored.


read-onlysupportedMapTypes : list<MapType>

This read-only property holds the set of map types supported by this map.

See also activeMapType.


tilt : real

This property holds the current tilt (starting from 0 and increasing to 85 degrees).

The tilt gives the map a 2.5D feel. Certain map objects may be rendered in 3D if the tilt is different from 0.

The default value is 0 corresponding to no tilt.


zoomLevel : real

This property holds the zoom level for the map.

Larger values for the zoom level provide more detail. Zoom levels are always non-negative. The default value is 8.0.


Method Documentation

Map::addMapItem(MapItem item)

Adds the given item to the Map (for example MapQuickItem, MapCircle). If the object already is on the Map, it will not be added again.

As an example, consider the case where you have a MapCircle representing your current position:

 import QtQuick 2.0
 import QtLocation 5.0

 PositionSource {
     id: positionSource
 }

 Map {
     id: map
     property MapCircle circle

     Component.onCompleted: {
         circle = Qt.createQmlObject('import QtLocation 5.0; MapCircle {}')
         circle.center = positionSource.position.coordinate
         circle.radius = 5000.0
         circle.color = 'green'
         circle.border.width = 3
         map.addMapItem(circle)
     }
 }

Note: MapItemViews cannot be added with this method.

See also mapitems, removeMapItem, and clearMapItems.


Map::fitViewportToMapItems()

Fits the current viewport to the boundary of all map items. The camera is positioned in the center of the map items, and at the largest integral zoom level possible which allows all map items to be visible on screen


Map::toCoordinate(QPointF screenPosition)

Returns the coordinate which corresponds to the screen position screenPosition.

Returns an invalid coordinate if screenPosition is not within the current viewport.


Map::toScreenPosition(Coordinate coordinate)

Returns the screen position which corresponds to the coordinate coordinate.

Returns an invalid QPointF if coordinate is not within the current viewport.


void Map::clearMapItems()

Removes all items from the map.

See also mapitems, addMapItem, and clearMapItems.


void Map::removeMapItem(MapItem item)

Removes the given item from the Map (for example MapQuickItem, MapCircle). If the MapItem does not exist or was not previously added to the map, the method does nothing.

See also mapitems, addMapItem, and clearMapItems.


Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 5.0-snapshot
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web