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); }
void QDeclarativeGeoMap::onSupportedMapTypesChanged() { QList<QDeclarativeGeoMapType *> supportedMapTypes; QList<QGeoMapType> types = m_mappingManager->supportedMapTypes(); for (int i = 0; i < types.size(); ++i) { // types that are present and get removed will be deleted at QObject destruction QDeclarativeGeoMapType *type = findMapType(m_supportedMapTypes, types[i]); if (!type) type = new QDeclarativeGeoMapType(types[i], this); supportedMapTypes.append(type); } m_supportedMapTypes.swap(supportedMapTypes); if (m_supportedMapTypes.isEmpty()) { m_map->setActiveMapType(QGeoMapType()); // no supported map types: setting an invalid one } else { bool hasMapType = false; foreach (QDeclarativeGeoMapType *declarativeType, m_supportedMapTypes) { if (declarativeType->mapType() == m_map->activeMapType()) hasMapType = true; } if (!hasMapType) { QDeclarativeGeoMapType *type = m_supportedMapTypes.at(0); m_activeMapType = type; m_map->setActiveMapType(type->mapType()); } } emit supportedMapTypesChanged(); }
QGeoMapDataPrivate::QGeoMapDataPrivate(QGeoMappingManagerEngine *engine, QGeoMapData *parent) : width_(0), height_(0), aspectRatio_(0.0), camera_(new QGLCamera()), map_(parent), engine_(engine), controller_(0), activeMapType_(QGeoMapType()) { pluginString_ = engine_->managerName() + QLatin1String("_") + QString::number(engine_->managerVersion()); }
QGeoTiledMappingManagerEngineQGC::QGeoTiledMappingManagerEngineQGC(const QVariantMap ¶meters, QGeoServiceProvider::Error *error, QString *errorString) : QGeoTiledMappingManagerEngine() { QGeoCameraCapabilities cameraCaps; cameraCaps.setMinimumZoomLevel(2.0); cameraCaps.setMaximumZoomLevel(MAX_MAP_ZOOM); cameraCaps.setSupportsBearing(true); setCameraCapabilities(cameraCaps); setTileSize(QSize(256, 256)); QList<QGeoMapType> mapTypes; mapTypes << QGeoMapType(QGeoMapType::StreetMap, tr("Google Street Map"), tr("Google street map"), false, false, OpenPilot::GoogleMap); mapTypes << QGeoMapType(QGeoMapType::SatelliteMapDay, tr("Google Satellite Map"),tr("Google satellite map"), false, false, OpenPilot::GoogleSatellite); mapTypes << QGeoMapType(QGeoMapType::TerrainMap, tr("Google Terrain Map"), tr("Google terrain map"), false, false, OpenPilot::GoogleTerrain); // TODO: // Proper google hybrid maps requires collecting two separate bimaps and overlaying them. //mapTypes << QGeoMapType(QGeoMapType::HybridMap, tr("Google Hybrid Map"), tr("Google hybrid map"), false, false, OpenPilot::GoogleHybrid); // Bing mapTypes << QGeoMapType(QGeoMapType::StreetMap, tr("Bing Street Map"), tr("Bing street map"), false, false, OpenPilot::BingMap); mapTypes << QGeoMapType(QGeoMapType::SatelliteMapDay, tr("Bing Satellite Map"), tr("Bing satellite map"), false, false, OpenPilot::BingSatellite); mapTypes << QGeoMapType(QGeoMapType::HybridMap, tr("Bing Hybrid Map"), tr("Bing hybrid map"), false, false, OpenPilot::BingHybrid); mapTypes << QGeoMapType(QGeoMapType::StreetMap, tr("Open Street Map"), tr("Open Street map"), false, false, OpenPilot::OpenStreetMap); setSupportedMapTypes(mapTypes); QGeoTileFetcherQGC *tileFetcher = new QGeoTileFetcherQGC(this); if (parameters.contains(QStringLiteral("useragent"))) { const QByteArray ua = parameters.value(QStringLiteral("useragent")).toString().toLatin1(); tileFetcher->setUserAgent(ua); } else // QGC Default tileFetcher->setUserAgent("Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7"); #if QT_VERSION >= 0x050500 _setCache(parameters); #endif setTileFetcher(tileFetcher); *error = QGeoServiceProvider::NoError; errorString->clear(); #if QT_VERSION >= 0x050500 if (parameters.contains(QStringLiteral("mapping.copyright"))) m_customCopyright = parameters.value(QStringLiteral("mapping.copyright")).toString().toLatin1(); #endif }
QT_BEGIN_NAMESPACE QGeoTiledMappingManagerEngineMapbox::QGeoTiledMappingManagerEngineMapbox(const QVariantMap ¶meters, QGeoServiceProvider::Error *error, QString *errorString) : QGeoTiledMappingManagerEngine() { QGeoCameraCapabilities cameraCaps; cameraCaps.setMinimumZoomLevel(0.0); cameraCaps.setMaximumZoomLevel(19.0); setCameraCapabilities(cameraCaps); setTileSize(QSize(256, 256)); QList<QGeoMapType> mapTypes; mapTypes << QGeoMapType(QGeoMapType::CustomMap, tr("Custom"), tr("Mapbox custom map"), false, false, 0); setSupportedMapTypes(mapTypes); QGeoTileFetcherMapbox *tileFetcher = new QGeoTileFetcherMapbox(this); if (parameters.contains(QStringLiteral("useragent"))) { const QByteArray ua = parameters.value(QStringLiteral("useragent")).toString().toLatin1(); tileFetcher->setUserAgent(ua); } if (parameters.contains(QStringLiteral("mapbox.map_id"))) { const QString id = parameters.value(QStringLiteral("mapbox.map_id")).toString(); tileFetcher->setMapId(id); } if (parameters.contains(QStringLiteral("mapbox.format"))) { const QString format = parameters.value(QStringLiteral("mapbox.format")).toString(); tileFetcher->setFormat(format); } if (parameters.contains(QStringLiteral("mapbox.access_token"))) { const QString token = parameters.value(QStringLiteral("mapbox.access_token")).toString(); tileFetcher->setAccessToken(token); } setTileFetcher(tileFetcher); *error = QGeoServiceProvider::NoError; errorString->clear(); }
/*! \internal this function will only be ever called once */ void QDeclarativeGeoMap::mappingManagerInitialized() { m_mappingManagerInitialized = true; m_map = m_mappingManager->createMap(this); m_gestureArea->setMap(m_map); // once mappingManagerInitilized_ is set zoomLevel() returns the default initialised // zoom level of the map controller. Overwrite it here to whatever the user chose. m_map->mapController()->setZoom(m_zoomLevel); //The zoom level limits are only restricted by the plugins values, if the user has set a more //strict zoom level limit before initialization nothing is done here. if (m_mappingManager->cameraCapabilities().minimumZoomLevel() > m_gestureArea->minimumZoomLevel()) setMinimumZoomLevel(m_mappingManager->cameraCapabilities().minimumZoomLevel()); if (m_gestureArea->maximumZoomLevel() < 0 || m_mappingManager->cameraCapabilities().maximumZoomLevel() < m_gestureArea->maximumZoomLevel()) setMaximumZoomLevel(m_mappingManager->cameraCapabilities().maximumZoomLevel()); m_map->setActiveMapType(QGeoMapType()); m_copyrights = new QDeclarativeGeoMapCopyrightNotice(this); connect(m_map, SIGNAL(copyrightsChanged(QImage)), m_copyrights.data(), SLOT(copyrightsChanged(QImage))); connect(m_map, SIGNAL(copyrightsChanged(QString)), m_copyrights.data(), SLOT(copyrightsChanged(QString))); connect(m_copyrights.data(), SIGNAL(linkActivated(QString)), this, SIGNAL(copyrightLinkActivated(QString))); connect(m_map, SIGNAL(updateRequired()), this, SLOT(update())); connect(m_map->mapController(), SIGNAL(centerChanged(QGeoCoordinate)), this, SLOT(mapCenterChanged(QGeoCoordinate))); connect(m_map->mapController(), SIGNAL(zoomChanged(qreal)), this, SLOT(mapZoomLevelChanged(qreal))); m_map->mapController()->setCenter(m_center); QList<QGeoMapType> types = m_mappingManager->supportedMapTypes(); for (int i = 0; i < types.size(); ++i) { QDeclarativeGeoMapType *type = new QDeclarativeGeoMapType(types[i], this); m_supportedMapTypes.append(type); } if (!m_supportedMapTypes.isEmpty()) { QDeclarativeGeoMapType *type = m_supportedMapTypes.at(0); m_activeMapType = type; m_map->setActiveMapType(type->mapType()); } // Map tiles are built in this call m_map->resize(width(), height()); // This prefetches a buffer around the map m_map->prefetchData(); m_map->update(); connect(m_mappingManager, SIGNAL(supportedMapTypesChanged()), this, SLOT(onSupportedMapTypesChanged())); emit minimumZoomLevelChanged(); emit maximumZoomLevelChanged(); emit supportedMapTypesChanged(); emit activeMapTypeChanged(); // Any map items that were added before the plugin was ready // need to have setMap called again foreach (const QPointer<QDeclarativeGeoMapItemBase> &item, m_mapItems) { if (item) item.data()->setMap(this, m_map); } }
/*! \internal this function will only be ever called once */ void QDeclarativeGeoMap::mappingManagerInitialized() { mappingManagerInitialized_ = true; map_ = mappingManager_->createMap(this); gestureArea_->setMap(map_); //The zoom level limits are only restricted by the plugins values, if the user has set a more //strict zoom level limit before initialization nothing is done here. if (mappingManager_->cameraCapabilities().minimumZoomLevel() > gestureArea_->minimumZoomLevel()) setMinimumZoomLevel(mappingManager_->cameraCapabilities().minimumZoomLevel()); if (gestureArea_->maximumZoomLevel() < 0 || mappingManager_->cameraCapabilities().maximumZoomLevel() < gestureArea_->maximumZoomLevel()) setMaximumZoomLevel(mappingManager_->cameraCapabilities().maximumZoomLevel()); map_->setActiveMapType(QGeoMapType()); copyrightsWPtr_ = new QDeclarativeGeoMapCopyrightNotice(this); connect(map_, SIGNAL(copyrightsChanged(QImage,QPoint)), copyrightsWPtr_.data(), SLOT(copyrightsChanged(QImage,QPoint))); connect(map_, SIGNAL(updateRequired()), this, SLOT(update())); connect(map_->mapController(), SIGNAL(centerChanged(QGeoCoordinate)), this, SIGNAL(centerChanged(QGeoCoordinate))); connect(map_->mapController(), SIGNAL(zoomChanged(qreal)), this, SLOT(mapZoomLevelChanged(qreal))); map_->mapController()->setCenter(center_); map_->mapController()->setZoom(zoomLevel_); QList<QGeoMapType> types = mappingManager_->supportedMapTypes(); for (int i = 0; i < types.size(); ++i) { QDeclarativeGeoMapType *type = new QDeclarativeGeoMapType(types[i], this); supportedMapTypes_.append(type); } if (!supportedMapTypes_.isEmpty()) { QDeclarativeGeoMapType *type = supportedMapTypes_.at(0); activeMapType_ = type; map_->setActiveMapType(type->mapType()); } // Map tiles are built in this call map_->resize(width(), height()); // This prefetches a buffer around the map map_->cameraStopped(); map_->update(); emit minimumZoomLevelChanged(); emit maximumZoomLevelChanged(); emit supportedMapTypesChanged(); emit activeMapTypeChanged(); // Any map items that were added before the plugin was ready // need to have setMap called again foreach (const QPointer<QDeclarativeGeoMapItemBase> &item, mapItems_) { if (item) item.data()->setMap(this, map_); } }
QGeoTiledMappingManagerEngineQGC::QGeoTiledMappingManagerEngineQGC(const QVariantMap ¶meters, QGeoServiceProvider::Error *error, QString *errorString) : QGeoTiledMappingManagerEngine() { QGeoCameraCapabilities cameraCaps; cameraCaps.setMinimumZoomLevel(2.0); cameraCaps.setMaximumZoomLevel(MAX_MAP_ZOOM); cameraCaps.setSupportsBearing(true); setCameraCapabilities(cameraCaps); setTileSize(QSize(256, 256)); QList<QGeoMapType> mapTypes; mapTypes << QGeoMapType(QGeoMapType::StreetMap, tr("Google Street Map"), tr("Google street map"), false, false, OpenPilot::GoogleMap); mapTypes << QGeoMapType(QGeoMapType::SatelliteMapDay, tr("Google Satellite Map"),tr("Google satellite map"), false, false, OpenPilot::GoogleSatellite); mapTypes << QGeoMapType(QGeoMapType::TerrainMap, tr("Google Terrain Map"), tr("Google terrain map"), false, false, OpenPilot::GoogleTerrain); // TODO: // Proper hybrid maps requires collecting two separate bimaps and overlaying them. //mapTypes << QGeoMapType(QGeoMapType::HybridMap, tr("Google Hybrid Map"), tr("Google hybrid map"), false, false, OpenPilot::GoogleHybrid); // Bing mapTypes << QGeoMapType(QGeoMapType::StreetMap, tr("Bing Street Map"), tr("Bing street map"), false, false, OpenPilot::BingMap); mapTypes << QGeoMapType(QGeoMapType::SatelliteMapDay, tr("Bing Satellite Map"), tr("Bing satellite map"), false, false, OpenPilot::BingSatellite); mapTypes << QGeoMapType(QGeoMapType::HybridMap, tr("Bing Hybrid Map"), tr("Bing hybrid map"), false, false, OpenPilot::BingHybrid); mapTypes << QGeoMapType(QGeoMapType::StreetMap, tr("Open Street Map"), tr("Open Street map"), false, false, OpenPilot::OpenStreetMap); setSupportedMapTypes(mapTypes); QGeoTileFetcherQGC *tileFetcher = new QGeoTileFetcherQGC(this); if (parameters.contains(QStringLiteral("useragent"))) { const QByteArray ua = parameters.value(QStringLiteral("useragent")).toString().toLatin1(); tileFetcher->setUserAgent(ua); } else // QGC Default tileFetcher->setUserAgent("Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7"); setTileFetcher(tileFetcher); QString cacheDir; if (parameters.contains(QStringLiteral("mapping.cache.directory"))) cacheDir = parameters.value(QStringLiteral("mapping.cache.directory")).toString(); else { cacheDir = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QLatin1String("/QGCMapCache"); if(!QDir::root().mkpath(cacheDir)) { qWarning() << "Could not create mapping disk cache directory: " << cacheDir; cacheDir = QDir::homePath() + QLatin1String("/.qgcmapscache/"); } } if(!QDir::root().mkpath(cacheDir)) { qWarning() << "Could not create mapping disk cache directory: " << cacheDir; cacheDir.clear(); } //else { // qDebug() << "Mapping cache directory:" << cacheDir; //} QGeoTileCache* pTileCache = tileCache(); if(pTileCache) { int cacheLimit = 0; //-- Disk Cache if (parameters.contains(QStringLiteral("mapping.cache.disk.size"))) { bool ok = false; cacheLimit = parameters.value(QStringLiteral("mapping.cache.disk.size")).toString().toInt(&ok); if (!ok) cacheLimit = 0; } if(!cacheLimit) { #ifdef __mobile__ cacheLimit = 128 * 1024 * 1024; #else cacheLimit = 1024 * 1024 * 1024; #endif } pTileCache->setMaxDiskUsage(cacheLimit); //-- Memory Cache cacheLimit = 0; if (parameters.contains(QStringLiteral("mapping.cache.memory.size"))) { bool ok = false; cacheLimit = parameters.value(QStringLiteral("mapping.cache.memory.size")).toString().toInt(&ok); if (!ok) cacheLimit = 0; } if(!cacheLimit) { #ifdef __mobile__ cacheLimit = 16 * 1024 * 1024; #else cacheLimit = 128 * 1024 * 1024; #endif } pTileCache->setMaxMemoryUsage(cacheLimit); } *error = QGeoServiceProvider::NoError; errorString->clear(); #if QT_VERSION >= 0x050500 if (parameters.contains(QStringLiteral("mapping.copyright"))) m_customCopyright = parameters.value(QStringLiteral("mapping.copyright")).toString().toLatin1(); #endif }
void tst_MapType::comparison_data() { QTest::addColumn<QGeoMapType>("type1"); QTest::addColumn<QGeoMapType>("type2"); QTest::addColumn<bool>("expected"); QTest::newRow("null") << QGeoMapType() << QGeoMapType() << true; QTest::newRow("equal") << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name"), QStringLiteral("street desc"), false, false, 42) << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name"), QStringLiteral("street desc"), false, false, 42) << true; QTest::newRow("style") << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name"), QStringLiteral("street desc"), false, false, 42) << QGeoMapType(QGeoMapType::TerrainMap, QStringLiteral("street name"), QStringLiteral("street desc"), false, false, 42) << false; QTest::newRow("name") << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name"), QStringLiteral("street desc"), false, false, 42) << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("different name"), QStringLiteral("street desc"), false, false, 42) << false; QTest::newRow("description") << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name"), QStringLiteral("street desc"), false, false, 42) << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name"), QStringLiteral("different desc"), false, false, 42) << false; QTest::newRow("mobile") << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name"), QStringLiteral("street desc"), false, false, 42) << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name"), QStringLiteral("street desc"), true, false, 42) << false; QTest::newRow("night") << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name"), QStringLiteral("street desc"), false, false, 42) << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name"), QStringLiteral("street desc"), false, true, 42) << false; QTest::newRow("id") << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name"), QStringLiteral("street desc"), false, false, 42) << QGeoMapType(QGeoMapType::StreetMap, QStringLiteral("street name"), QStringLiteral("street desc"), false, false, 99) << false; }
//----------------------------------------------------------------------------- QGeoTiledMappingManagerEngineQGC::QGeoTiledMappingManagerEngineQGC(const QVariantMap ¶meters, QGeoServiceProvider::Error *error, QString *errorString) : QGeoTiledMappingManagerEngine() { QGeoCameraCapabilities cameraCaps; cameraCaps.setMinimumZoomLevel(2.0); cameraCaps.setMaximumZoomLevel(MAX_MAP_ZOOM); cameraCaps.setSupportsBearing(true); setCameraCapabilities(cameraCaps); setTileSize(QSize(256, 256)); /* * Most of these don't seem kosher at all. This was based on original code from OpenPilot and heavily modified to be used in QGC. */ //-- IMPORTANT // Changes here must reflect those in QGCMapEngine.cpp QList<QGeoMapType> mapTypes; mapTypes << QGeoMapType(QGeoMapType::StreetMap, "Google Street Map", "Google street map", false, false, UrlFactory::GoogleMap); mapTypes << QGeoMapType(QGeoMapType::SatelliteMapDay, "Google Satellite Map", "Google satellite map", false, false, UrlFactory::GoogleSatellite); mapTypes << QGeoMapType(QGeoMapType::TerrainMap, "Google Terrain Map", "Google terrain map", false, false, UrlFactory::GoogleTerrain); /* TODO: * Proper google hybrid maps requires collecting two separate bimaps and overlaying them. * * mapTypes << QGeoMapType(QGeoMapType::HybridMap, "Google Hybrid Map", "Google hybrid map", false, false, UrlFactory::GoogleHybrid); * */ // Bing mapTypes << QGeoMapType(QGeoMapType::StreetMap, "Bing Street Map", "Bing street map", false, false, UrlFactory::BingMap); mapTypes << QGeoMapType(QGeoMapType::SatelliteMapDay, "Bing Satellite Map", "Bing satellite map", false, false, UrlFactory::BingSatellite); mapTypes << QGeoMapType(QGeoMapType::HybridMap, "Bing Hybrid Map", "Bing hybrid map", false, false, UrlFactory::BingHybrid); /* See: https://wiki.openstreetmap.org/wiki/Tile_usage_policy mapTypes << QGeoMapType(QGeoMapType::StreetMap, "Open Street Map", "Open Street map", false, false, UrlFactory::OpenStreetMap); */ // MapQuest mapTypes << QGeoMapType(QGeoMapType::StreetMap, "MapQuest Street Map", "MapQuest street map", false, false, UrlFactory::MapQuestMap); mapTypes << QGeoMapType(QGeoMapType::SatelliteMapDay, "MapQuest Satellite Map", "MapQuest satellite map", false, false, UrlFactory::MapQuestSat); /* * These are OK as you need your own token for accessing it. Out-of-the box, QGC does not even offer these unless you enter a proper MapBox token. */ mapTypes << QGeoMapType(QGeoMapType::StreetMap, "MapBox Street Map", "MapBox Street Map", false, false, UrlFactory::MapBoxStreets); mapTypes << QGeoMapType(QGeoMapType::SatelliteMapDay, "MapBox Satellite Map", "MapBox Satellite Map", false, false, UrlFactory::MapBoxSatellite); mapTypes << QGeoMapType(QGeoMapType::CustomMap, "MapBox High Contrast Map", "MapBox High Contrast Map", false, false, UrlFactory::MapBoxHighContrast); mapTypes << QGeoMapType(QGeoMapType::CustomMap, "MapBox Light Map", "MapBox Light Map", false, false, UrlFactory::MapBoxLight); mapTypes << QGeoMapType(QGeoMapType::CustomMap, "MapBox Dark Map", "MapBox Dark Map", false, false, UrlFactory::MapBoxDark); mapTypes << QGeoMapType(QGeoMapType::HybridMap, "MapBox Hybrid Map", "MapBox Hybrid Map", false, false, UrlFactory::MapBoxHybrid); mapTypes << QGeoMapType(QGeoMapType::CustomMap, "MapBox Wheat Paste Map", "MapBox Wheat Paste Map", false, false, UrlFactory::MapBoxWheatPaste); mapTypes << QGeoMapType(QGeoMapType::StreetMap, "MapBox Streets Basic Map", "MapBox Streets Basic Map", false, false, UrlFactory::MapBoxStreetsBasic); mapTypes << QGeoMapType(QGeoMapType::CustomMap, "MapBox Comic Map", "MapBox Comic Map", false, false, UrlFactory::MapBoxComic); mapTypes << QGeoMapType(QGeoMapType::CustomMap, "MapBox Outdoors Map", "MapBox Outdoors Map", false, false, UrlFactory::MapBoxOutdoors); mapTypes << QGeoMapType(QGeoMapType::CycleMap, "MapBox Run, Byke and Hike Map", "MapBox Run, Byke and Hike Map", false, false, UrlFactory::MapBoxRunBikeHike); mapTypes << QGeoMapType(QGeoMapType::CustomMap, "MapBox Pencil Map", "MapBox Pencil Map", false, false, UrlFactory::MapBoxPencil); mapTypes << QGeoMapType(QGeoMapType::CustomMap, "MapBox Pirates Map", "MapBox Pirates Map", false, false, UrlFactory::MapBoxPirates); mapTypes << QGeoMapType(QGeoMapType::CustomMap, "MapBox Emerald Map", "MapBox Emerald Map", false, false, UrlFactory::MapBoxEmerald); setSupportedMapTypes(mapTypes); //-- Users (QML code) can define a different user agent if (parameters.contains(QStringLiteral("useragent"))) { getQGCMapEngine()->setUserAgent(parameters.value(QStringLiteral("useragent")).toString().toLatin1()); } #if QT_VERSION >= 0x050500 _setCache(parameters); #endif setTileFetcher(new QGeoTileFetcherQGC(this)); *error = QGeoServiceProvider::NoError; errorString->clear(); #if QT_VERSION >= 0x050500 if (parameters.contains(QStringLiteral("mapping.copyright"))) m_customCopyright = parameters.value(QStringLiteral("mapping.copyright")).toString().toLatin1(); #endif }
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 fromCoordinate 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 */ /*! \qmlsignal QtLocation::Map::copyrightLinkActivated(string link) This signal is emitted when the user clicks on a \a link in the copyright notice. The application should open the link in a browser or display its contents to the user. */ 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(0), m_map(0), m_error(QGeoServiceProvider::NoError), m_zoomLevel(8.0), m_componentCompleted(false), m_mappingManagerInitialized(false), m_pendingFitViewport(false) { setAcceptHoverEvents(false); setAcceptedMouseButtons(Qt::LeftButton); setFlags(QQuickItem::ItemHasContents | QQuickItem::ItemClipsChildrenToShape); setFiltersChildMouseEvents(true); connect(this, SIGNAL(childrenChanged()), this, SLOT(onMapChildrenChanged()), Qt::QueuedConnection); // Create internal flickable and pinch area. m_gestureArea = new QDeclarativeGeoMapGestureArea(this, this); m_activeMapType = new QDeclarativeGeoMapType(QGeoMapType(QGeoMapType::NoMap, tr("No Map"), tr("No Map"), false, false, 0), this); }
void tst_MapType::descTest() { QGeoMapType testObj = QGeoMapType(QGeoMapType::StreetMap, "street name", "street desc", false, 0); QVERIFY2(testObj.description() == "street desc", "Wrong value returned"); }
void tst_MapType::styleTest() { QGeoMapType testObj = QGeoMapType(QGeoMapType::StreetMap, "street name", "street desc", false, 0); QVERIFY2(testObj.style() == QGeoMapType::StreetMap, "Wrong value returned"); }
void tst_MapType::comparison() { // TODO Tried using data function but couldn't make QFETCH work QGeoMapType t1 = QGeoMapType(QGeoMapType::StreetMap, "street name", "street desc", false, 42); QGeoMapType t2 = QGeoMapType(QGeoMapType::StreetMap, "street name", "street desc", false, 42); QCOMPARE(t1 == t2, true); QCOMPARE(t1 != t2, false); t1 = QGeoMapType(); t2 = QGeoMapType(); QCOMPARE(t1 == t2, true); t1 = QGeoMapType(QGeoMapType::StreetMap, "street name", "street desc", false, 42); t2 = QGeoMapType(QGeoMapType::TerrainMap, "street name", "street desc", false, 42); QCOMPARE(t1 == t2, false); t1 = QGeoMapType(QGeoMapType::StreetMap, "street name", "street desc", false, 42); t2 = QGeoMapType(QGeoMapType::StreetMap, "different name", "street desc", false, 42); QCOMPARE(t1 == t2, false); t1 = QGeoMapType(QGeoMapType::StreetMap, "street name", "street desc", false, 42); t2 = QGeoMapType(QGeoMapType::StreetMap, "street name", "different desc", false, 42); QCOMPARE(t1 == t2, false); t1 = QGeoMapType(QGeoMapType::StreetMap, "street name", "street desc", false, 42); t2 = QGeoMapType(QGeoMapType::StreetMap, "street name", "street desc", true, 42); QCOMPARE(t1 == t2, false); t1 = QGeoMapType(QGeoMapType::StreetMap, "street name", "street desc", false, 42); t2 = QGeoMapType(QGeoMapType::StreetMap, "street name", "street desc", false, 99); QCOMPARE(t1 == t2, false); }
void tst_MapType::mapIdTest() { QGeoMapType testObj = QGeoMapType(QGeoMapType::StreetMap, "mobile street name", "mobile street desc", true, 42); QVERIFY2(testObj.mapId() == 42, "Wrong value returned"); }
void tst_MapType::mobileTest() { QGeoMapType testObj = QGeoMapType(QGeoMapType::StreetMap, "mobile street name", "mobile street desc", true, 0); QVERIFY2(testObj.mobile() == true, "Wrong value returned"); }