summaryrefslogtreecommitdiff
path: root/src
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 /src
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>
Diffstat (limited to 'src')
-rw-r--r--src/location/declarativemaps/qdeclarativegeomap.cpp27
-rw-r--r--src/location/declarativemaps/qdeclarativegeomap_p.h2
2 files changed, 29 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);