QDeclarativeGeoMap::QDeclarativeGeoMap(QQuickItem *parent) : QQuickItem(parent), m_plugin(0), m_serviceProvider(0), m_mappingManager(0), m_center(51.5073,-0.1277), //London city center m_activeMapType(0), m_gestureArea(new QQuickGeoMapGestureArea(this)), m_map(0), m_error(QGeoServiceProvider::NoError), m_zoomLevel(8.0), m_componentCompleted(false), m_mappingManagerInitialized(false), m_color(QColor::fromRgbF(0.9, 0.9, 0.9)), m_pendingFitViewport(false), m_validRegion(false) { setAcceptHoverEvents(false); setAcceptedMouseButtons(Qt::LeftButton); setFlags(QQuickItem::ItemHasContents | QQuickItem::ItemClipsChildrenToShape); setFiltersChildMouseEvents(true); connect(this, SIGNAL(childrenChanged()), this, SLOT(onMapChildrenChanged()), Qt::QueuedConnection); m_activeMapType = new QDeclarativeGeoMapType(QGeoMapType(QGeoMapType::NoMap, tr("No Map"), tr("No Map"), false, false, 0), this); }
QT_BEGIN_NAMESPACE /*! \qmltype Map \instantiates QDeclarativeGeoMap \inqmlmodule QtLocation \ingroup qml-QtLocation5-maps \since Qt Location 5.0 \brief The Map type displays a map. The Map type 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 type, 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 \l 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 \l Plugin type 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 \l center, and \l zoomLevel. The \l center property contains a \l {coordinate} specifying the center of the viewport, while \l 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 \l toCoordinate and \l toScreenPosition functions, which are of general utility. \section2 Map Objects Map related objects can be declared within the body of a Map object in Qt Quick 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 \l addMapItem method on the Map. A corresponding \l 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. \section2 Interaction The Map type includes support for pinch and flick gestures to control zooming and panning. These are enabled by default, and available at any time by using the \l gesture object. The actual GestureArea is constructed specially at startup and cannot be replaced or destroyed. Its properties can be altered, however, to control its behavior. \section2 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 type. \section2 Example Usage The following snippet shows a simple Map and the necessary Plugin type to use it. The map is centered near Brisbane, Australia, zoomed out to the minimum zoom level, with gesture interaction enabled. \code Plugin { id: somePlugin // code here to choose the plugin as necessary } Map { id: map plugin: somePlugin center { latitude: -27 longitude: 153 } zoomLevel: map.minimumZoomLevel gesture.enabled: true } \endcode \image api-map.png */ QDeclarativeGeoMap::QDeclarativeGeoMap(QQuickItem *parent) : QQuickItem(parent), plugin_(0), serviceProvider_(0), mappingManager_(0), zoomLevel_(8.0), center_(51.5073,-0.1277), //London city center activeMapType_(0), componentCompleted_(false), mappingManagerInitialized_(false), touchTimer_(-1), map_(0) { QLOC_TRACE0; setAcceptHoverEvents(false); setAcceptedMouseButtons(Qt::LeftButton | Qt::MidButton | Qt::RightButton); setFlags(QQuickItem::ItemHasContents | QQuickItem::ItemClipsChildrenToShape); setFiltersChildMouseEvents(true); connect(this, SIGNAL(childrenChanged()), this, SLOT(onMapChildrenChanged()), Qt::QueuedConnection); // Create internal flickable and pinch area. gestureArea_ = new QDeclarativeGeoMapGestureArea(this, this); }