summaryrefslogtreecommitdiff
path: root/src/location/declarativemaps
diff options
context:
space:
mode:
Diffstat (limited to 'src/location/declarativemaps')
-rw-r--r--src/location/declarativemaps/qdeclarativegeomap.cpp136
-rw-r--r--src/location/declarativemaps/qdeclarativegeomap_p.h6
-rw-r--r--src/location/declarativemaps/qdeclarativegeomapitemview.cpp3
-rw-r--r--src/location/declarativemaps/qdeclarativegeomapitemview_p.h1
-rw-r--r--src/location/declarativemaps/qdeclarativegeomaptype.cpp115
-rw-r--r--src/location/declarativemaps/qdeclarativegeomaptype_p.h30
-rw-r--r--src/location/declarativemaps/qdeclarativegeoroutemodel.cpp1
-rw-r--r--src/location/declarativemaps/qdeclarativegeoroutemodel_p.h3
-rw-r--r--src/location/declarativemaps/qdeclarativepolylinemapitem.cpp21
-rw-r--r--src/location/declarativemaps/qdeclarativepolylinemapitem_p.h1
-rw-r--r--src/location/declarativemaps/qquickgeomapgesturearea.cpp45
11 files changed, 328 insertions, 34 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeomap.cpp b/src/location/declarativemaps/qdeclarativegeomap.cpp
index 2ed482e3..34885f54 100644
--- a/src/location/declarativemaps/qdeclarativegeomap.cpp
+++ b/src/location/declarativemaps/qdeclarativegeomap.cpp
@@ -46,6 +46,7 @@
#include <QtPositioning/QGeoCircle>
#include <QtPositioning/QGeoRectangle>
#include <QtPositioning/QGeoPath>
+#include <QtPositioning/QGeoPolygon>
#include <QtQuick/QQuickWindow>
#include <QtQuick/QSGRectangleNode>
#include <QtQuick/private/qquickwindow_p.h>
@@ -190,7 +191,11 @@ QDeclarativeGeoMap::QDeclarativeGeoMap(QQuickItem *parent)
m_activeMapType = new QDeclarativeGeoMapType(QGeoMapType(QGeoMapType::NoMap,
tr("No Map"),
- tr("No Map"), false, false, 0, QByteArrayLiteral("")), this);
+ tr("No Map"),
+ false, false,
+ 0,
+ QByteArrayLiteral(""),
+ QGeoCameraCapabilities()), this);
m_cameraData.setCenter(QGeoCoordinate(51.5073,-0.1277)); //London city center
m_cameraData.setZoomLevel(8.0);
@@ -218,8 +223,18 @@ QDeclarativeGeoMap::~QDeclarativeGeoMap()
m_map->clearMapItems();
}
- if (!m_mapViews.isEmpty())
- qDeleteAll(m_mapViews);
+ // This forces the destruction of the associated items now, not when QObject destructor is called, at which point
+ // QDeclarativeGeoMap is long gone
+ if (!m_mapViews.isEmpty()) {
+ for (QDeclarativeGeoMapItemView *v : qAsConst(m_mapViews)) {
+ if (!v)
+ continue;
+ if (v->parent() == this)
+ delete v;
+ else
+ v->removeInstantiatedItems();
+ }
+ }
// remove any map items associations
for (int i = 0; i < m_mapItems.count(); ++i) {
if (m_mapItems.at(i))
@@ -752,7 +767,12 @@ void QDeclarativeGeoMap::mappingManagerInitialized()
} else {
m_activeMapType = new QDeclarativeGeoMapType(QGeoMapType(QGeoMapType::NoMap,
tr("No Map"),
- tr("No Map"), false, false, 0, QByteArrayLiteral("")), this);
+ tr("No Map"),
+ false,
+ false,
+ 0,
+ QByteArrayLiteral(""),
+ QGeoCameraCapabilities()), this);
}
}
@@ -1322,22 +1342,22 @@ QGeoShape QDeclarativeGeoMap::visibleRegion() const
return m_visibleRegion;
const QList<QDoubleVector2D> &visibleRegion = m_map->geoProjection().visibleRegion();
- QGeoPath path;
+ QGeoPolygon poly;
for (int i = 0; i < visibleRegion.size(); ++i) {
const QDoubleVector2D &c = visibleRegion.at(i);
// If a segment spans more than half of the map longitudinally, split in 2.
if (i && qAbs(visibleRegion.at(i-1).x() - c.x()) >= 0.5) { // This assumes a segment is never >= 1.0 (whole map span)
QDoubleVector2D extraPoint = (visibleRegion.at(i-1) + c) * 0.5;
- path.addCoordinate(m_map->geoProjection().wrappedMapProjectionToGeo(extraPoint));
+ poly.addCoordinate(m_map->geoProjection().wrappedMapProjectionToGeo(extraPoint));
}
- path.addCoordinate(m_map->geoProjection().wrappedMapProjectionToGeo(c));
+ poly.addCoordinate(m_map->geoProjection().wrappedMapProjectionToGeo(c));
}
if (visibleRegion.size() >= 2 && qAbs(visibleRegion.last().x() - visibleRegion.first().x()) >= 0.5) {
QDoubleVector2D extraPoint = (visibleRegion.last() + visibleRegion.first()) * 0.5;
- path.addCoordinate(m_map->geoProjection().wrappedMapProjectionToGeo(extraPoint));
+ poly.addCoordinate(m_map->geoProjection().wrappedMapProjectionToGeo(extraPoint));
}
- return path.boundingGeoRectangle();
+ return poly;
}
/*!
@@ -1454,6 +1474,61 @@ 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.
+
+ The release of this API with Qt 5.10 is a Technology Preview.
+
+ \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 void QtLocation::Map::alignCoordinateToPoint(coordinate coordinate, QPointF point)
+
+ Aligns \a coordinate to \a point.
+ This method effectively extends the functionality offered by the \l center qml property, allowing
+ to align a coordinate to point of the Map element other than its center.
+ This is useful in those applications where the center of the scene (e.g., a cursor) is not to be
+ placed exactly in the center of the map.
+
+ 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.
+
+ The release of this API with Qt 5.10 is a Technology Preview.
+
+ \sa center
+
+ \since 5.10
+*/
+void QDeclarativeGeoMap::alignCoordinateToPoint(const QGeoCoordinate &coordinate, const QPointF &point)
+{
+ if (!m_map)
+ return;
+
+ setCenter(m_map->geoProjection().anchorCoordinateToPoint(coordinate, point));
+}
+
+/*!
\qmlmethod coordinate QtLocation::Map::toCoordinate(QPointF position, bool clipToViewPort)
Returns the coordinate which corresponds to the \a position relative to the map item.
@@ -1896,6 +1971,47 @@ void QDeclarativeGeoMap::removeMapItemGroup(QDeclarativeGeoMapItemGroup *itemGro
}
/*!
+ \qmlmethod void QtLocation::Map::removeMapItemView(MapItemView itemView)
+
+ Removes \a itemView and the items instantiated by it from the Map.
+
+ \sa MapItemView, addMapItemView
+
+ \since 5.10
+*/
+void QDeclarativeGeoMap::removeMapItemView(QDeclarativeGeoMapItemView *itemView)
+{
+ if (!itemView || itemView->map_ != this) // can't remove a view that is already added to another map
+ return;
+
+ itemView->removeInstantiatedItems();
+ itemView->map_ = 0;
+ // it can be removed from the list at this point, since no operations that require a Map have to be done
+ // anymore on destruction.
+ m_mapViews.removeOne(itemView);
+}
+
+/*!
+ \qmlmethod void QtLocation::Map::addMapItemView(MapItemView itemView)
+
+ Adds \a itemView to the Map.
+
+ \sa MapItemView, removeMapItemView
+
+ \since 5.10
+*/
+void QDeclarativeGeoMap::addMapItemView(QDeclarativeGeoMapItemView *itemView)
+{
+ if (!itemView || itemView->map_) // can't add a view twice
+ return;
+
+ // Not appending it to m_mapViews because it seems unnecessary even if the
+ // itemView is a child of this (in which case it would be destroyed
+ m_mapViews.append(itemView);
+ setupMapView(itemView);
+}
+
+/*!
\qmlproperty MapType QtLocation::Map::activeMapType
\brief Access to the currently active \l{MapType}{map type}.
@@ -2155,7 +2271,7 @@ bool QDeclarativeGeoMap::sendTouchEvent(QTouchEvent *event)
auto touchPointGrabberItem = [touchDevice, windowPriv](const QTouchEvent::TouchPoint &point) -> QQuickItem* {
if (QQuickEventPoint *eventPointer = windowPriv->pointerEventInstance(touchDevice)->pointById(point.id()))
- return eventPointer->grabber();
+ return eventPointer->grabberItem();
return nullptr;
};
diff --git a/src/location/declarativemaps/qdeclarativegeomap_p.h b/src/location/declarativemaps/qdeclarativegeomap_p.h
index e8ff3265..5c568d8f 100644
--- a/src/location/declarativemaps/qdeclarativegeomap_p.h
+++ b/src/location/declarativemaps/qdeclarativegeomap_p.h
@@ -155,12 +155,18 @@ public:
QQmlListProperty<QDeclarativeGeoMapType> supportedMapTypes();
+ Q_INVOKABLE void setBearing(qreal bearing, const QGeoCoordinate &coordinate);
+ Q_INVOKABLE void alignCoordinateToPoint(const QGeoCoordinate &coordinate, const QPointF &point);
+
Q_INVOKABLE void removeMapItem(QDeclarativeGeoMapItemBase *item);
Q_INVOKABLE void addMapItem(QDeclarativeGeoMapItemBase *item);
Q_INVOKABLE void addMapItemGroup(QDeclarativeGeoMapItemGroup *itemGroup);
Q_INVOKABLE void removeMapItemGroup(QDeclarativeGeoMapItemGroup *itemGroup);
+ Q_INVOKABLE void removeMapItemView(QDeclarativeGeoMapItemView *itemView);
+ Q_INVOKABLE void addMapItemView(QDeclarativeGeoMapItemView *itemView);
+
Q_INVOKABLE void clearMapItems();
QList<QObject *> mapItems();
diff --git a/src/location/declarativemaps/qdeclarativegeomapitemview.cpp b/src/location/declarativemaps/qdeclarativegeomapitemview.cpp
index 8207caa5..24ed6700 100644
--- a/src/location/declarativemaps/qdeclarativegeomapitemview.cpp
+++ b/src/location/declarativemaps/qdeclarativegeomapitemview.cpp
@@ -431,6 +431,9 @@ void QDeclarativeGeoMapItemView::instantiateAllItems()
fitViewport();
}
+/*
+ * used internally
+*/
void QDeclarativeGeoMapItemView::removeItemData(QDeclarativeGeoMapItemViewItemData *itemData)
{
if (!itemData)
diff --git a/src/location/declarativemaps/qdeclarativegeomapitemview_p.h b/src/location/declarativemaps/qdeclarativegeomapitemview_p.h
index 8c83e37d..8f1a081f 100644
--- a/src/location/declarativemaps/qdeclarativegeomapitemview_p.h
+++ b/src/location/declarativemaps/qdeclarativegeomapitemview_p.h
@@ -141,6 +141,7 @@ private:
int m_readyIncubators;
bool m_repopulating;
+ friend class QDeclarativeGeoMap;
friend class QDeclarativeGeoMapItemViewItemData;
friend class MapItemViewDelegateIncubator;
};
diff --git a/src/location/declarativemaps/qdeclarativegeomaptype.cpp b/src/location/declarativemaps/qdeclarativegeomaptype.cpp
index 86444aa4..7e40d414 100644
--- a/src/location/declarativemaps/qdeclarativegeomaptype.cpp
+++ b/src/location/declarativemaps/qdeclarativegeomaptype.cpp
@@ -57,7 +57,8 @@ QT_BEGIN_NAMESPACE
QDeclarativeGeoMapType::QDeclarativeGeoMapType(const QGeoMapType mapType, QObject *parent)
: QObject(parent),
- mapType_(mapType) {}
+ mapType_(mapType),
+ cameraCapabilities_(new QDeclarativeGeoCameraCapabilities(mapType.cameraCapabilities(), this)) {}
QDeclarativeGeoMapType::~QDeclarativeGeoMapType() {}
@@ -131,4 +132,116 @@ bool QDeclarativeGeoMapType::night() const
return mapType_.night();
}
+/*!
+ \qmlproperty CameraCapabilities MapType::cameraCapabilities
+ \since Qt Location 5.10
+
+ This property holds the camera capabilities for this map type.
+*/
+QDeclarativeGeoCameraCapabilities *QDeclarativeGeoMapType::cameraCapabilities() const
+{
+ return cameraCapabilities_;
+}
+
+/*!
+ \qmlproperty VariantMap MapType::metadata
+ \since Qt Location 5.10
+
+ This property holds optional, extra metadata related to a specific map type.
+ The content of this property is entirely plugin-specific.
+*/
+QVariantMap QDeclarativeGeoMapType::metadata() const
+{
+ return mapType_.metadata();
+}
+
+/*
+ * QDeclarativeGeoCameraCapabilities implementation
+ */
+
+/*!
+ \qmltype CameraCapabilities
+ \instantiates QDeclarativeGeoCameraCapabilities
+ \inherits QObject
+ \inqmlmodule QtLocation
+ \ingroup qml-QtLocation5-maps
+ \since Qt Location 5.10
+
+ \brief The CameraCapabilities type holds information about the camera capabilities for a specific map type.
+
+ This includes the map minimum and maximum zoom level, minimum and maximum tilt angle and
+ minimum and maximum field of view.
+*/
+
+QDeclarativeGeoCameraCapabilities::QDeclarativeGeoCameraCapabilities(const QGeoCameraCapabilities &cameraCaps, QObject *parent)
+ : QObject(parent), cameraCaps_(cameraCaps)
+{
+
+}
+
+QDeclarativeGeoCameraCapabilities::~QDeclarativeGeoCameraCapabilities()
+{
+
+}
+
+/*!
+ \qmlproperty qreal CameraCapabilities::minimumZoomLevel
+
+ This read-only property holds the minimum available zoom level with this map type.
+*/
+qreal QDeclarativeGeoCameraCapabilities::minimumZoomLevel() const
+{
+ return cameraCaps_.minimumZoomLevelAt256();
+}
+
+/*!
+ \qmlproperty qreal CameraCapabilities::maximumZoomLevel
+
+ This read-only property holds the maximum available zoom level with this map type.
+*/
+qreal QDeclarativeGeoCameraCapabilities::maximumZoomLevel() const
+{
+ return cameraCaps_.maximumZoomLevelAt256();
+}
+
+/*!
+ \qmlproperty qreal CameraCapabilities::minimumTilt
+
+ This read-only property holds the minimum available tilt with this map type.
+*/
+qreal QDeclarativeGeoCameraCapabilities::minimumTilt() const
+{
+ return cameraCaps_.minimumTilt();
+}
+
+/*!
+ \qmlproperty qreal CameraCapabilities::maximumTilt
+
+ This read-only property holds the maximum available tilt with this map type.
+*/
+qreal QDeclarativeGeoCameraCapabilities::maximumTilt() const
+{
+ return cameraCaps_.maximumTilt();
+}
+
+/*!
+ \qmlproperty qreal CameraCapabilities::minimumFieldOfView
+
+ This read-only property holds the minimum available field of view with this map type.
+*/
+qreal QDeclarativeGeoCameraCapabilities::minimumFieldOfView() const
+{
+ return cameraCaps_.minimumFieldOfView();
+}
+
+/*!
+ \qmlproperty qreal CameraCapabilities::maximumFieldOfView
+
+ This read-only property holds the maximum available field of view with this map type.
+*/
+qreal QDeclarativeGeoCameraCapabilities::maximumFieldOfView() const
+{
+ return cameraCaps_.maximumFieldOfView();
+}
+
QT_END_NAMESPACE
diff --git a/src/location/declarativemaps/qdeclarativegeomaptype_p.h b/src/location/declarativemaps/qdeclarativegeomaptype_p.h
index 7b449aa0..5d99083d 100644
--- a/src/location/declarativemaps/qdeclarativegeomaptype_p.h
+++ b/src/location/declarativemaps/qdeclarativegeomaptype_p.h
@@ -56,6 +56,31 @@
QT_BEGIN_NAMESPACE
+class Q_LOCATION_PRIVATE_EXPORT QDeclarativeGeoCameraCapabilities: public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(qreal minimumZoomLevel READ minimumZoomLevel CONSTANT)
+ Q_PROPERTY(qreal maximumZoomLevel READ maximumZoomLevel CONSTANT)
+ Q_PROPERTY(qreal minimumTilt READ minimumTilt CONSTANT)
+ Q_PROPERTY(qreal maximumTilt READ maximumTilt CONSTANT)
+ Q_PROPERTY(qreal minimumFieldOfView READ minimumFieldOfView CONSTANT)
+ Q_PROPERTY(qreal maximumFieldOfView READ maximumFieldOfView CONSTANT)
+
+public:
+ QDeclarativeGeoCameraCapabilities(const QGeoCameraCapabilities &cameraCaps, QObject *parent = 0);
+ ~QDeclarativeGeoCameraCapabilities();
+
+ qreal minimumZoomLevel() const;
+ qreal maximumZoomLevel() const;
+ qreal minimumTilt() const;
+ qreal maximumTilt() const;
+ qreal minimumFieldOfView() const;
+ qreal maximumFieldOfView() const;
+
+private:
+ QGeoCameraCapabilities cameraCaps_;
+};
+
class Q_LOCATION_PRIVATE_EXPORT QDeclarativeGeoMapType : public QObject
{
Q_OBJECT
@@ -66,6 +91,8 @@ class Q_LOCATION_PRIVATE_EXPORT QDeclarativeGeoMapType : public QObject
Q_PROPERTY(QString description READ description CONSTANT)
Q_PROPERTY(bool mobile READ mobile CONSTANT)
Q_PROPERTY(bool night READ night CONSTANT REVISION 1)
+ Q_PROPERTY(QDeclarativeGeoCameraCapabilities *cameraCapabilities READ cameraCapabilities CONSTANT)
+ Q_PROPERTY(QVariantMap metadata READ metadata CONSTANT)
public:
enum MapStyle {
@@ -91,11 +118,14 @@ public:
QString description() const;
bool mobile() const;
bool night() const;
+ QDeclarativeGeoCameraCapabilities *cameraCapabilities() const;
+ QVariantMap metadata() const;
const QGeoMapType mapType() { return mapType_; }
private:
QGeoMapType mapType_;
+ QDeclarativeGeoCameraCapabilities *cameraCapabilities_;
};
QT_END_NAMESPACE
diff --git a/src/location/declarativemaps/qdeclarativegeoroutemodel.cpp b/src/location/declarativemaps/qdeclarativegeoroutemodel.cpp
index 94bd63c8..0383c0c4 100644
--- a/src/location/declarativemaps/qdeclarativegeoroutemodel.cpp
+++ b/src/location/declarativemaps/qdeclarativegeoroutemodel.cpp
@@ -722,6 +722,7 @@ void QDeclarativeGeoRouteQuery::componentComplete()
\li RouteQuery.DirtRoadFeature - Consider dirt roads when planning the route
\li RouteQuery.ParksFeature - Consider parks when planning the route
\li RouteQuery.MotorPoolLaneFeature - Consider motor pool lanes when planning the route
+ \li RouteQuery.TrafficFeature - Consider traffic when planning the route
\endlist
\sa setFeatureWeight, featureWeight
diff --git a/src/location/declarativemaps/qdeclarativegeoroutemodel_p.h b/src/location/declarativemaps/qdeclarativegeoroutemodel_p.h
index 3dfd2ce6..18486ac8 100644
--- a/src/location/declarativemaps/qdeclarativegeoroutemodel_p.h
+++ b/src/location/declarativemaps/qdeclarativegeoroutemodel_p.h
@@ -238,7 +238,8 @@ public:
TunnelFeature = QGeoRouteRequest::TunnelFeature,
DirtRoadFeature = QGeoRouteRequest::DirtRoadFeature,
ParksFeature = QGeoRouteRequest::ParksFeature,
- MotorPoolLaneFeature = QGeoRouteRequest::MotorPoolLaneFeature
+ MotorPoolLaneFeature = QGeoRouteRequest::MotorPoolLaneFeature,
+ TrafficFeature = QGeoRouteRequest::TrafficFeature
};
Q_DECLARE_FLAGS(FeatureTypes, FeatureType)
diff --git a/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp b/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp
index 2c6d3ba4..a97271aa 100644
--- a/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp
+++ b/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp
@@ -494,6 +494,27 @@ void QDeclarativePolylineMapItem::setPath(const QJSValue &value)
}
/*!
+ \qmlmethod int MapPolyline::setPath(geopath path)
+
+ Sets the \l path using a \l QGeoPath type.
+
+ \since 5.10
+
+ \sa path
+*/
+void QDeclarativePolylineMapItem::setPath(const QGeoPath &path)
+{
+ if (geopath_.path() == path.path())
+ return;
+
+ geopath_ = path;
+ regenerateCache();
+ geometry_.setPreserveGeometry(true, geopath_.boundingGeoRectangle().topLeft());
+ markSourceDirtyAndUpdate();
+ emit pathChanged();
+}
+
+/*!
\internal
*/
void QDeclarativePolylineMapItem::setPathFromGeoList(const QList<QGeoCoordinate> &path)
diff --git a/src/location/declarativemaps/qdeclarativepolylinemapitem_p.h b/src/location/declarativemaps/qdeclarativepolylinemapitem_p.h
index ec57c980..6b3c42e9 100644
--- a/src/location/declarativemaps/qdeclarativepolylinemapitem_p.h
+++ b/src/location/declarativemaps/qdeclarativepolylinemapitem_p.h
@@ -141,6 +141,7 @@ public:
QJSValue path() const;
virtual void setPath(const QJSValue &value);
+ Q_INVOKABLE void setPath(const QGeoPath &path);
bool contains(const QPointF &point) const Q_DECL_OVERRIDE;
const QGeoShape &geoShape() const Q_DECL_OVERRIDE;
diff --git a/src/location/declarativemaps/qquickgeomapgesturearea.cpp b/src/location/declarativemaps/qquickgeomapgesturearea.cpp
index 4f949ad0..d62ae8cf 100644
--- a/src/location/declarativemaps/qquickgeomapgesturearea.cpp
+++ b/src/location/declarativemaps/qquickgeomapgesturearea.cpp
@@ -84,18 +84,6 @@ static qreal distanceBetweenTouchPoints(const QPointF &p1, const QPointF &p2)
return QLineF(p1, p2).length();
}
-// Returns the new map center after anchoring coordinate to anchorPoint on the screen
-// Approach: find the displacement in (wrapped) mercator space, and apply that to the center
-static QGeoCoordinate anchorCoordinateToPoint(QGeoMap &map, const QGeoCoordinate &coordinate, const QPointF &anchorPoint)
-{
- QDoubleVector2D centerProj = map.geoProjection().geoToWrappedMapProjection(map.cameraData().center());
- QDoubleVector2D coordProj = map.geoProjection().geoToWrappedMapProjection(coordinate);
-
- QDoubleVector2D anchorProj = map.geoProjection().itemPositionToWrappedMapProjection(QDoubleVector2D(anchorPoint));
- // Y-clamping done in mercatorToCoord
- return map.geoProjection().wrappedMapProjectionToGeo(centerProj + coordProj - anchorProj);
-}
-
static qreal angleFromPoints(const QPointF &p1, const QPointF &p2)
{
return QLineF(p1, p2).angle();
@@ -255,6 +243,8 @@ QT_BEGIN_NAMESPACE
MapGestureArea objects are used as part of a Map, to provide for panning,
flicking and pinch-to-zoom gesture used on touch displays, as well as two finger rotation
and two finger parallel vertical sliding to tilt the map.
+ On platforms supporting \l QWheelEvent, using the scroll wheel alone, or in combination with
+ key modifiers Shift or Control will also zoom, rotate or tilt the map, respectively.
A MapGestureArea is automatically created with a new Map and available with
the \l{Map::gesture}{gesture} property. This is the only way
@@ -951,15 +941,26 @@ void QQuickGeoMapGestureArea::handleWheelEvent(QWheelEvent *event)
const QGeoCoordinate &wheelGeoPos = m_map->geoProjection().itemPositionToCoordinate(QDoubleVector2D(event->posF()), false);
const QPointF &preZoomPoint = event->posF();
- const double zoomLevelDelta = event->angleDelta().y() * qreal(0.001);
- // Gesture area should always honor maxZL, but Map might not.
- m_declarativeMap->setZoomLevel(qMin<qreal>(m_declarativeMap->zoomLevel() + zoomLevelDelta, maximumZoomLevel()),
- false);
- const QPointF &postZoomPoint = m_map->geoProjection().coordinateToItemPosition(wheelGeoPos, false).toPointF();
-
- if (preZoomPoint != postZoomPoint) // need to re-anchor the wheel geoPos to the event position
- m_declarativeMap->setCenter(anchorCoordinateToPoint(*m_map, wheelGeoPos, preZoomPoint));
-
+ // Not using AltModifier as, for some reason, it causes angleDelta to be 0
+ if (event->modifiers() & Qt::ShiftModifier && rotationEnabled()) {
+ // First set bearing
+ const double bearingDelta = event->angleDelta().y() * qreal(0.05);
+ m_declarativeMap->setBearing(m_declarativeMap->bearing() + bearingDelta);
+ // then reanchor
+ m_declarativeMap->setCenter(m_map->geoProjection().anchorCoordinateToPoint(wheelGeoPos, preZoomPoint));
+ } else if (event->modifiers() & Qt::ControlModifier && tiltEnabled()) {
+ const double tiltDelta = event->angleDelta().y() * qreal(0.05);
+ m_declarativeMap->setTilt(m_declarativeMap->tilt() + tiltDelta);
+ } else if (pinchEnabled()) {
+ const double zoomLevelDelta = event->angleDelta().y() * qreal(0.001);
+ // Gesture area should always honor maxZL, but Map might not.
+ m_declarativeMap->setZoomLevel(qMin<qreal>(m_declarativeMap->zoomLevel() + zoomLevelDelta, maximumZoomLevel()),
+ false);
+ const QPointF &postZoomPoint = m_map->geoProjection().coordinateToItemPosition(wheelGeoPos, false).toPointF();
+
+ if (preZoomPoint != postZoomPoint) // need to re-anchor the wheel geoPos to the event position
+ m_declarativeMap->setCenter(m_map->geoProjection().anchorCoordinateToPoint(wheelGeoPos, preZoomPoint));
+ }
event->accept();
}
#endif
@@ -1705,7 +1706,7 @@ bool QQuickGeoMapGestureArea::canStartPan()
*/
void QQuickGeoMapGestureArea::updatePan()
{
- QGeoCoordinate animationStartCoordinate = anchorCoordinateToPoint(*m_map, m_startCoord, m_touchPointsCentroid);
+ QGeoCoordinate animationStartCoordinate = m_map->geoProjection().anchorCoordinateToPoint(m_startCoord, m_touchPointsCentroid);
m_declarativeMap->setCenter(animationStartCoordinate);
}