summaryrefslogtreecommitdiff
path: root/src/location/declarativemaps/qdeclarativegeomap.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/location/declarativemaps/qdeclarativegeomap.cpp')
-rw-r--r--src/location/declarativemaps/qdeclarativegeomap.cpp101
1 files changed, 63 insertions, 38 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeomap.cpp b/src/location/declarativemaps/qdeclarativegeomap.cpp
index 106c4dae..1b5ea11c 100644
--- a/src/location/declarativemaps/qdeclarativegeomap.cpp
+++ b/src/location/declarativemaps/qdeclarativegeomap.cpp
@@ -399,8 +399,8 @@ void QDeclarativeGeoMap::pluginReady()
QGeoServiceProvider *provider = m_plugin->sharedGeoServiceProvider();
m_mappingManager = provider->mappingManager();
- if (provider->error() != QGeoServiceProvider::NoError) {
- setError(provider->error(), provider->errorString());
+ if (provider->mappingError() != QGeoServiceProvider::NoError) {
+ setError(provider->mappingError(), provider->mappingErrorString());
return;
}
@@ -1317,7 +1317,7 @@ void QDeclarativeGeoMap::setVisibleRegion(const QGeoShape &shape)
return;
}
- fitViewportToGeoShape();
+ fitViewportToGeoShape(m_visibleRegion);
}
QGeoShape QDeclarativeGeoMap::visibleRegion() const
@@ -1457,39 +1457,6 @@ QMargins QDeclarativeGeoMap::mapMargins() const
, height() - va.height() - va.y());
}
-// TODO: offer the possibility to specify the margins.
-void QDeclarativeGeoMap::fitViewportToGeoShape()
-{
- if (m_map->geoProjection().projectionType() == QGeoProjection::ProjectionWebMercator) {
- // This case remains handled here, and not inside QGeoMap*::fitViewportToGeoRectangle,
- // in order to honor animations on center and zoomLevel
- const QGeoProjectionWebMercator &p = static_cast<const QGeoProjectionWebMercator&>(m_map->geoProjection());
- const int borderSize = 10;
- const QMargins borders(borderSize, borderSize, borderSize, borderSize);
-
- if (!m_map || !m_visibleRegion.isValid())
- return;
-
- const QMargins margins = borders + mapMargins();
- const QPair<QGeoCoordinate, qreal> fitData = p.fitViewportToGeoRectangle(m_visibleRegion,
- margins);
- if (!fitData.first.isValid())
- return;
-
- // position camera to the center of bounding box
- setProperty("center", QVariant::fromValue(fitData.first)); // not using setCenter(centerCoordinate) to honor a possible animation set on the center property
-
- if (!qIsFinite(fitData.second))
- return;
- double newZoom = qMax<double>(minimumZoomLevel(), fitData.second);
- setProperty("zoomLevel", QVariant::fromValue(newZoom)); // not using setZoomLevel(newZoom) to honor a possible animation set on the zoomLevel property
- } else if (m_map->capabilities() & QGeoMap::SupportsFittingViewportToGeoRectangle) {
- // Animations cannot be honored in this case, as m_map acts as a black box
- m_map->fitViewportToGeoRectangle(m_visibleRegion);
- }
-}
-
-
/*!
\qmlproperty list<MapType> QtLocation::Map::supportedMapTypes
@@ -1616,6 +1583,64 @@ void QDeclarativeGeoMap::clearData()
}
/*!
+ \qmlmethod void QtLocation::Map::fitViewportToGeoShape(geoShape, margins)
+
+ Fits the viewport to a specific geo shape.
+ The margins are in screen pixels.
+
+ \note If the projection used by the plugin is not WebMercator, and the plugin does not have fitting to
+ shape capability, this method will do nothing.
+
+ \sa visibleRegion
+ \since 5.13
+*/
+void QDeclarativeGeoMap::fitViewportToGeoShape(const QGeoShape &shape, QVariant margins)
+{
+ QMargins m(10, 10, 10, 10); // lets defaults to 10 if margins is invalid
+ switch (margins.type()) {
+ case QMetaType::Int:
+ case QMetaType::Double: {
+ const int value = int(margins.toDouble());
+ m = QMargins(value, value, value, value);
+ }
+ break;
+ // ToDo: Support distinct margins in some QML form. Perhaps QRect?
+ default:
+ break;
+ }
+ fitViewportToGeoShape(shape, m);
+}
+
+void QDeclarativeGeoMap::fitViewportToGeoShape(const QGeoShape &shape, const QMargins &borders)
+{
+ if (!m_map || !shape.isValid())
+ return;
+
+ if (m_map->geoProjection().projectionType() == QGeoProjection::ProjectionWebMercator) {
+ // This case remains handled here, and not inside QGeoMap*::fitViewportToGeoRectangle,
+ // in order to honor animations on center and zoomLevel
+ const QMargins margins = borders + mapMargins();
+ const QGeoProjectionWebMercator &p = static_cast<const QGeoProjectionWebMercator&>(m_map->geoProjection());
+ const QPair<QGeoCoordinate, qreal> fitData = p.fitViewportToGeoRectangle(shape.boundingGeoRectangle(),
+ margins);
+ if (!fitData.first.isValid())
+ return;
+
+ // position camera to the center of bounding box
+ setProperty("center", QVariant::fromValue(fitData.first)); // not using setCenter(centerCoordinate) to honor a possible animation set on the center property
+
+ if (!qIsFinite(fitData.second))
+ return;
+ double newZoom = qMax<double>(minimumZoomLevel(), fitData.second);
+ setProperty("zoomLevel", QVariant::fromValue(newZoom)); // not using setZoomLevel(newZoom) to honor a possible animation set on the zoomLevel property
+ } else if (m_map->capabilities() & QGeoMap::SupportsFittingViewportToGeoRectangle) {
+ // Animations cannot be honored in this case, as m_map acts as a black box
+ m_map->fitViewportToGeoRectangle(m_visibleRegion, borders);
+ }
+ // else out of luck
+}
+
+/*!
\qmlproperty string QtLocation::Map::errorString
This read-only property holds the textual presentation of the latest mapping provider error.
@@ -2213,7 +2238,7 @@ void QDeclarativeGeoMap::geometryChanged(const QRectF &newGeometry, const QRectF
Multiple fitViewportTo*() calls replace each other.
*/
if (m_pendingFitViewport && width() && height()) {
- fitViewportToGeoShape();
+ fitViewportToGeoShape(m_visibleRegion);
m_pendingFitViewport = false;
}
@@ -2441,7 +2466,7 @@ void QDeclarativeGeoMap::wheelEvent(QWheelEvent *event)
*/
bool QDeclarativeGeoMap::childMouseEventFilter(QQuickItem *item, QEvent *event)
{
- Q_UNUSED(item)
+ Q_UNUSED(item);
if (!isVisible() || !isEnabled() || !isInteractive())
return QQuickItem::childMouseEventFilter(item, event);