diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2016-10-11 13:36:06 +0200 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2017-01-25 13:25:38 +0000 |
commit | a66306d3d8eab810b769a536095dbfa2a0eb6ce2 (patch) | |
tree | 61843e32114732b10c238d25535c89c95911d0c1 /src/location/maps | |
parent | be13464a488ccc2837b0c178ff16086be341e570 (diff) | |
download | qtlocation-a66306d3d8eab810b769a536095dbfa2a0eb6ce2.tar.gz |
Add rotation and tilt controls to QDeclarativeGeoMap
QDeclarativeGeoMap currently does not provide any mean to set bearing
and tilt into qgeocameradata.
It has been not a problem since QGeoTiledMap and sons did not support
it.
External renderers however support it, so this patch adds QML api
calls to control these parameters, and adapt the existing logic
to take them into consideration in camera-related
calls, as well as in the afterViewportChange handlers of the Map
Items.
This patch also sligthly modifies the QML api to make the handling
of all the bounded camera property more homogeneous.
Minimum and maximum zoom levels prior plugin initialization
aren't -1 anymore, but are some valid lower and upper bounds
for this property, that is 0 and 30.
in this way all the 2 bounded properties (zoomLevel and
tilt) behave the same, in that they can be freely set before plugin
initialization, within reasonable predefined bounds, and, after that,
they may be clamped depending on the actual plugin capabilities.
Autotests for the QML part of the API included.
Change-Id: I9d09e32698a7330388e465e8ea7523ee39577d34
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/location/maps')
-rw-r--r-- | src/location/maps/qgeocameracapabilities.cpp | 2 | ||||
-rw-r--r-- | src/location/maps/qgeocameradata.cpp | 2 | ||||
-rw-r--r-- | src/location/maps/qgeomap.cpp | 4 | ||||
-rw-r--r-- | src/location/maps/qgeomap_p.h | 4 | ||||
-rw-r--r-- | src/location/maps/qgeoprojection.cpp | 15 | ||||
-rw-r--r-- | src/location/maps/qgeoprojection_p.h | 4 | ||||
-rw-r--r-- | src/location/maps/qgeotiledmapscene.cpp | 3 |
7 files changed, 18 insertions, 16 deletions
diff --git a/src/location/maps/qgeocameracapabilities.cpp b/src/location/maps/qgeocameracapabilities.cpp index 97ff5790..fca12a5c 100644 --- a/src/location/maps/qgeocameracapabilities.cpp +++ b/src/location/maps/qgeocameracapabilities.cpp @@ -62,6 +62,7 @@ public: bool supportsTilting_; // this is mutable so that it can be set from accessor functions that are const + // TODO: remove the mutable here mutable bool valid_; double minZoom_; @@ -95,6 +96,7 @@ QGeoCameraCapabilitiesPrivate::QGeoCameraCapabilitiesPrivate(const QGeoCameraCap maxTilt_(other.maxTilt_), tileSize_(other.tileSize_) {} + QGeoCameraCapabilitiesPrivate::~QGeoCameraCapabilitiesPrivate() {} QGeoCameraCapabilitiesPrivate &QGeoCameraCapabilitiesPrivate::operator = (const QGeoCameraCapabilitiesPrivate &other) diff --git a/src/location/maps/qgeocameradata.cpp b/src/location/maps/qgeocameradata.cpp index 909145fe..0d4c273e 100644 --- a/src/location/maps/qgeocameradata.cpp +++ b/src/location/maps/qgeocameradata.cpp @@ -82,7 +82,7 @@ QGeoCameraDataPrivate &QGeoCameraDataPrivate::operator = (const QGeoCameraDataPr m_center = rhs.m_center; m_bearing = rhs.m_bearing; m_tilt = rhs.m_tilt; - m_roll = rhs.m_roll; + m_roll = rhs.m_roll;; m_zoomLevel = rhs.m_zoomLevel; return *this; diff --git a/src/location/maps/qgeomap.cpp b/src/location/maps/qgeomap.cpp index 325ca83f..6c9c2b7f 100644 --- a/src/location/maps/qgeomap.cpp +++ b/src/location/maps/qgeomap.cpp @@ -118,10 +118,10 @@ double QGeoMap::minimumZoom() const return d->m_geoProjection->minimumZoom(); } -double QGeoMap::maximumCenterLatitudeAtZoom(double zoomLevel) const +double QGeoMap::maximumCenterLatitudeAtZoom(const QGeoCameraData &cameraData) const { Q_D(const QGeoMap); - return d->m_geoProjection->maximumCenterLatitudeAtZoom(zoomLevel); + return d->m_geoProjection->maximumCenterLatitudeAtZoom(cameraData); } double QGeoMap::mapWidth() const diff --git a/src/location/maps/qgeomap_p.h b/src/location/maps/qgeomap_p.h index b5e51014..7f9fca8c 100644 --- a/src/location/maps/qgeomap_p.h +++ b/src/location/maps/qgeomap_p.h @@ -49,6 +49,7 @@ #include <QtLocation/private/qgeocameradata_p.h> #include <QtLocation/private/qgeomaptype_p.h> +#include <QtLocation/private/qgeocameracapabilities_p.h> #include <QtCore/QObject> #include <QtPositioning/private/qdoublevector2d_p.h> #include <QtLocation/private/qgeoprojection_p.h> @@ -58,7 +59,6 @@ QT_BEGIN_NAMESPACE class QGeoMappingManagerEngine; class QGeoMapPrivate; class QGeoMapController; -class QGeoCameraCapabilities; class QGeoCoordinate; class QSGNode; class QQuickWindow; @@ -87,7 +87,7 @@ public: // returns the minimum zoom at the current viewport size double minimumZoom() const; - double maximumCenterLatitudeAtZoom(double zoomLevel) const; + double maximumCenterLatitudeAtZoom(const QGeoCameraData &cameraData) const; // returns the size of the underlying map, at the current zoom level. Unrelated to width()/height()/size(). double mapWidth() const; diff --git a/src/location/maps/qgeoprojection.cpp b/src/location/maps/qgeoprojection.cpp index dc7e78f8..b33f180f 100644 --- a/src/location/maps/qgeoprojection.cpp +++ b/src/location/maps/qgeoprojection.cpp @@ -98,9 +98,9 @@ double QGeoProjectionWebMercator::minimumZoom() const // the amount of pixels between the center and the borders changes // 2) when the zoom level changes, because the amount of pixels between the center // and the borders stays the same, but the meters per pixel change -double QGeoProjectionWebMercator::maximumCenterLatitudeAtZoom(double zoomLevel) const +double QGeoProjectionWebMercator::maximumCenterLatitudeAtZoom(const QGeoCameraData &cameraData) const { - double mapEdgeSize = std::pow(2.0, zoomLevel) * defaultTileSize; + double mapEdgeSize = std::pow(2.0, cameraData.zoomLevel()) * defaultTileSize; // At init time weird things happen int clampedWindowHeight = (m_viewportHeight > mapEdgeSize) ? mapEdgeSize : m_viewportHeight; @@ -187,7 +187,7 @@ QDoubleVector2D QGeoProjectionWebMercator::wrappedMapProjectionToItemPosition(co QDoubleVector2D QGeoProjectionWebMercator::itemPositionToWrappedMapProjection(const QDoubleVector2D &itemPosition) const { QDoubleVector2D pos = itemPosition; - pos /= QDoubleVector2D(m_viewportWidth, m_viewportHeight); + pos *= QDoubleVector2D(m_1_viewportWidth, m_1_viewportHeight); pos *= 2.0; pos -= QDoubleVector2D(1.0,1.0); pos *= QDoubleVector2D(m_halfWidth, m_halfHeight); @@ -262,10 +262,9 @@ void QGeoProjectionWebMercator::setupCamera() double z = std::pow(2.0, m_cameraData.zoomLevel() - intZoomLevel) * defaultTileSize; double altitude = f / (2.0 * z) ; + //aperture(90 / 2) = 1 + m_aperture = 0.41421356237309503; // For a field of view of 45 degrees, as 90 is loading too many tiles // calculate eye - // TODO: support field of view with apertureSize = tan(QLocationUtils::radians(m_cameraData.fieldOfView()) * 0.5); - double m_aperture = 1.0; //aperture(90 / 2) = 1 - m_eye = m_center; m_eye.setZ(altitude * defaultTileSize / m_aperture); @@ -300,8 +299,8 @@ void QGeoProjectionWebMercator::setupCamera() double aspectRatio = 1.0 * m_viewportWidth / m_viewportHeight; - m_halfWidth = 1 * m_aperture; - m_halfHeight = 1 * m_aperture; + m_halfWidth = m_aperture; + m_halfHeight = m_aperture; if (aspectRatio > 1.0) { m_halfWidth *= aspectRatio; } else if (aspectRatio > 0.0 && aspectRatio < 1.0) { diff --git a/src/location/maps/qgeoprojection_p.h b/src/location/maps/qgeoprojection_p.h index 61059fdd..c31f806b 100644 --- a/src/location/maps/qgeoprojection_p.h +++ b/src/location/maps/qgeoprojection_p.h @@ -65,7 +65,7 @@ public: // returns the minimum zoom at the current viewport size virtual double minimumZoom() const = 0; - virtual double maximumCenterLatitudeAtZoom(double zoomLevel) const = 0; + virtual double maximumCenterLatitudeAtZoom(const QGeoCameraData &cameraData) const = 0; // returns the size of the underlying map, at the current zoom level. virtual double mapWidth() const = 0; @@ -95,7 +95,7 @@ public: ~QGeoProjectionWebMercator(); double minimumZoom() const Q_DECL_OVERRIDE; - double maximumCenterLatitudeAtZoom(double zoomLevel) const Q_DECL_OVERRIDE; + double maximumCenterLatitudeAtZoom(const QGeoCameraData &cameraData) const Q_DECL_OVERRIDE; // The size of the underlying map, at the current zoom level. double mapWidth() const Q_DECL_OVERRIDE; diff --git a/src/location/maps/qgeotiledmapscene.cpp b/src/location/maps/qgeotiledmapscene.cpp index 404dcd19..3e75cece 100644 --- a/src/location/maps/qgeotiledmapscene.cpp +++ b/src/location/maps/qgeotiledmapscene.cpp @@ -111,6 +111,7 @@ public: bool buildGeometry(const QGeoTileSpec &spec, QSGImageNode *imageNode); void setTileBounds(const QSet<QGeoTileSpec> &tiles); void setupCamera(); + inline bool isTiltedOrRotated() { return (m_cameraData.tilt() > 0.0) || (m_cameraData.bearing() > 0.0); } }; QGeoTiledMapScene::QGeoTiledMapScene(QObject *parent) @@ -140,7 +141,7 @@ void QGeoTiledMapScene::setCameraData(const QGeoCameraData &cameraData) d->m_cameraData = cameraData; d->m_intZoomLevel = static_cast<int>(std::floor(d->m_cameraData.zoomLevel())); float delta = cameraData.zoomLevel() - d->m_intZoomLevel; - d->m_linearScaling = qAbs(delta) > 0.05; + d->m_linearScaling = qAbs(delta) > 0.05 || d->isTiltedOrRotated(); d->m_sideLength = 1 << d->m_intZoomLevel; } |