summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2017-06-06 15:37:49 +0200
committerPaolo Angelelli <paolo.angelelli@qt.io>2017-08-03 10:33:11 +0000
commit61776400fe4b18a62fd9b4880fc1e799cf0f2cde (patch)
tree1fbc21b5fb4db9689008c7818e40a027354bcd9d
parent11da6dec6d47e7670482ed146cced92573cc0b85 (diff)
downloadqtlocation-61776400fe4b18a62fd9b4880fc1e799cf0f2cde.tar.gz
Add setBearing overload to rotate around a coordinate
This patch adds an overload for setBearing in QDeclarativeGeoMap to rotate the map around a specific QGeoCoordinate. [ChangeLog][QtLocation][QDeclarativeGeoMap] Added setBearing overload to rotate the map around a given QGeoCoordinate. Change-Id: I5d2428d852b0c3537f4a1cdb1925c059788c45c5 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r--src/location/declarativemaps/qdeclarativegeomap.cpp27
-rw-r--r--src/location/declarativemaps/qdeclarativegeomap_p.h2
-rw-r--r--tests/auto/declarative_ui/tst_map.qml27
3 files changed, 56 insertions, 0 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeomap.cpp b/src/location/declarativemaps/qdeclarativegeomap.cpp
index cb991341..47283d85 100644
--- a/src/location/declarativemaps/qdeclarativegeomap.cpp
+++ b/src/location/declarativemaps/qdeclarativegeomap.cpp
@@ -1460,6 +1460,33 @@ QQmlListProperty<QDeclarativeGeoMapType> QDeclarativeGeoMap::supportedMapTypes()
}
/*!
+ \qmlmethod void QtLocation::Map::setBearing(real bearing, coordinate coordinate)
+
+ Sets the bearing for the map to \a bearing, rotating it around \a coordinate.
+ If the Plugin used for the Map supports bearing, the valid range for \a bearing is between 0 and 360.
+ If the Plugin used for the Map does not support bearing, or if the map is tilted and \a coordinate happens
+ to be behind the camera, or if the map is not ready (see \l mapReady), calling this method will have no effect.
+
+ \since 5.10
+*/
+void QDeclarativeGeoMap::setBearing(qreal bearing, const QGeoCoordinate &coordinate)
+{
+ if (!m_map)
+ return;
+
+ const QDoubleVector2D coordWrapped = m_map->geoProjection().geoToWrappedMapProjection(coordinate);
+ if (!m_map->geoProjection().isProjectable(coordWrapped))
+ return;
+
+ const QPointF rotationPoint = m_map->geoProjection().wrappedMapProjectionToItemPosition(coordWrapped).toPointF();
+
+ // First set bearing
+ setBearing(bearing);
+ // then reanchor
+ setCenter(m_map->geoProjection().anchorCoordinateToPoint(coordinate, rotationPoint));
+}
+
+/*!
\qmlmethod coordinate QtLocation::Map::toCoordinate(QPointF position, bool clipToViewPort)
Returns the coordinate which corresponds to the \a position relative to the map item.
diff --git a/src/location/declarativemaps/qdeclarativegeomap_p.h b/src/location/declarativemaps/qdeclarativegeomap_p.h
index f07a2e7f..2f20e3ae 100644
--- a/src/location/declarativemaps/qdeclarativegeomap_p.h
+++ b/src/location/declarativemaps/qdeclarativegeomap_p.h
@@ -155,6 +155,8 @@ public:
QQmlListProperty<QDeclarativeGeoMapType> supportedMapTypes();
+ Q_INVOKABLE void setBearing(qreal bearing, const QGeoCoordinate &coordinate);
+
Q_INVOKABLE void removeMapItem(QDeclarativeGeoMapItemBase *item);
Q_INVOKABLE void addMapItem(QDeclarativeGeoMapItemBase *item);
diff --git a/tests/auto/declarative_ui/tst_map.qml b/tests/auto/declarative_ui/tst_map.qml
index cd79952c..18d7c2d3 100644
--- a/tests/auto/declarative_ui/tst_map.qml
+++ b/tests/auto/declarative_ui/tst_map.qml
@@ -515,6 +515,33 @@ Item {
compare(mapTiltBearing.tilt, 25.0)
}
+ function test_map_setbearing()
+ {
+ var zeroCoord = QtPositioning.coordinate(0,0)
+ mapTiltBearing.bearing = 0.0
+ mapTiltBearing.tilt = 0.0
+ mapTiltBearing.zoomLevel = 3
+ mapTiltBearing.center = zeroCoord
+ compare(mapTiltBearing.bearing, 0.0)
+ compare(mapTiltBearing.tilt, 0.0)
+ compare(mapTiltBearing.zoomLevel, 3)
+ compare(mapTiltBearing.center, zeroCoord)
+
+ var fulcrum = QtPositioning.coordinate(20,-20)
+ var fulcrumPos = mapTiltBearing.fromCoordinate(fulcrum)
+ var bearing = 90.0
+ mapTiltBearing.setBearing(bearing, fulcrum)
+ var fulcrumPosAfter = mapTiltBearing.fromCoordinate(fulcrum)
+ compare(mapTiltBearing.bearing, bearing)
+ compare(fulcrumPos, fulcrumPosAfter)
+
+ // resetting
+ mapTiltBearing.center = coordinate1
+ mapTiltBearing.zoomLevel = 4
+ mapTiltBearing.bearing = 45.0
+ mapTiltBearing.tilt = 25.0
+ }
+
function test_coordinate_conversion()
{
wait(1000)