summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@qt.io>2017-09-25 18:55:20 +0200
committerOswald Buddenhagen <oswald.buddenhagen@qt.io>2017-09-25 18:55:20 +0200
commitd919f47308b209c798e50d8ca1b9abd48ba94718 (patch)
treec62566331b35659e46439cb2531f70e5ccc43739
parentb6f174ebfdc32110dab495217481481dbff5670d (diff)
parent6ba14c6d2a6b7eb325cd975393306c4fe6809acd (diff)
downloadqtlocation-d919f47308b209c798e50d8ca1b9abd48ba94718.tar.gz
Merge 5.9 into 5.9.2v5.9.25.9.2
Change-Id: I69598f5f4c5c7c8fec58c6ff41f353fe4e042762
-rw-r--r--src/location/maps/qgeoprojection.cpp20
-rw-r--r--tests/auto/declarative_ui/tst_map.qml22
2 files changed, 37 insertions, 5 deletions
diff --git a/src/location/maps/qgeoprojection.cpp b/src/location/maps/qgeoprojection.cpp
index 013a8c33..fcf9a350 100644
--- a/src/location/maps/qgeoprojection.cpp
+++ b/src/location/maps/qgeoprojection.cpp
@@ -225,6 +225,9 @@ QDoubleVector2D QGeoProjectionWebMercator::itemPositionToWrappedMapProjection(co
/* Default implementations */
QGeoCoordinate QGeoProjectionWebMercator::itemPositionToCoordinate(const QDoubleVector2D &pos, bool clipToViewport) const
{
+ if (qIsNaN(pos.x()) || qIsNaN(pos.y()))
+ return QGeoCoordinate();
+
if (clipToViewport) {
int w = m_viewportWidth;
int h = m_viewportHeight;
@@ -242,7 +245,14 @@ QGeoCoordinate QGeoProjectionWebMercator::itemPositionToCoordinate(const QDouble
QDoubleVector2D QGeoProjectionWebMercator::coordinateToItemPosition(const QGeoCoordinate &coordinate, bool clipToViewport) const
{
- QDoubleVector2D pos = wrappedMapProjectionToItemPosition(wrapMapProjection(geoToMapProjection(coordinate)));
+ if (!coordinate.isValid())
+ return QDoubleVector2D(qQNaN(), qQNaN());
+
+ QDoubleVector2D wrappedProjection = wrapMapProjection(geoToMapProjection(coordinate));
+ if (!isProjectable(wrappedProjection))
+ return QDoubleVector2D(qQNaN(), qQNaN());
+
+ QDoubleVector2D pos = wrappedMapProjectionToItemPosition(wrappedProjection);
if (clipToViewport) {
int w = m_viewportWidth;
@@ -339,10 +349,10 @@ QDoubleVector2D QGeoProjectionWebMercator::viewportToWrappedMapProjection(const
pos *= QDoubleVector2D(m_halfWidth, m_halfHeight);
QDoubleVector3D p = m_centerNearPlane;
- p -= m_up * pos.y();
- p -= m_side * pos.x();
+ p += m_up * pos.y();
+ p += m_side * pos.x();
- QDoubleVector3D ray = p - m_eye;
+ QDoubleVector3D ray = m_eye - p;
ray.normalize();
return (xyPlane.lineIntersection(m_eye, ray, s) / m_sideLength).toVector2D();
@@ -461,7 +471,7 @@ void QGeoProjectionWebMercator::setupCamera()
m_quickItemTransformation = m_transformation;
m_transformation.scale(m_sideLength, m_sideLength, 1.0);
- m_centerNearPlane = m_eye + m_viewNormalized;
+ m_centerNearPlane = m_eye - m_viewNormalized;
m_centerNearPlaneMercator = m_eyeMercator - m_viewNormalized * m_nearPlaneMercator;
// The method does not support tilting angles >= 90.0 or < 0.
diff --git a/tests/auto/declarative_ui/tst_map.qml b/tests/auto/declarative_ui/tst_map.qml
index c36ebc0e..8821f55e 100644
--- a/tests/auto/declarative_ui/tst_map.qml
+++ b/tests/auto/declarative_ui/tst_map.qml
@@ -72,6 +72,7 @@ Item {
&& coordinateMap.mapReady
&& mapTiltBearing.mapReady
&& mapTiltBearingHere.mapReady
+ && mapTestProjection.mapReady
Map { id: mapZoomOnCompleted; width: 200; height: 200;
zoomLevel: 3; center: coordinate1; plugin: testPlugin;
@@ -113,6 +114,13 @@ Item {
plugin: testPluginLazyParameter
}
+ Map {
+ id: mapTestProjection
+ plugin: testPlugin
+ width: 200
+ height: 200
+ }
+
MapParameter {
id: testParameter
type: "cameraCenter_test"
@@ -593,6 +601,20 @@ Item {
coord = coordinateMap.toCoordinate(Qt.point(-5, -6))
verify(isNaN(coord.latitude))
verify(isNaN(coord.longitde))
+
+ // test with tilting
+ coord = QtPositioning.coordinate(45.6, 17.67)
+ var pos = mapTestProjection.fromCoordinate(coord, false)
+ compare(Math.floor(pos.x), 3339)
+ compare(Math.floor(pos.y), 1727)
+ mapTestProjection.tilt = 6
+ pos = mapTestProjection.fromCoordinate(coord, false)
+ compare(Math.floor(pos.x), 11066)
+ compare(Math.floor(pos.y), 5577)
+ mapTestProjection.tilt = 12
+ pos = mapTestProjection.fromCoordinate(coord, false)
+ verify(isNaN(pos.latitude))
+ verify(isNaN(pos.longitde))
}
}
}