summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/location/mapviewer/map/MapComponent.qml38
-rw-r--r--src/imports/location/qdeclarativegeomap.cpp18
-rw-r--r--src/imports/location/qdeclarativegeomap_p.h4
-rw-r--r--src/imports/location/qdeclarativegeomapgesturearea.cpp16
4 files changed, 59 insertions, 17 deletions
diff --git a/examples/location/mapviewer/map/MapComponent.qml b/examples/location/mapviewer/map/MapComponent.qml
index 0cb84fdf..0857804b 100644
--- a/examples/location/mapviewer/map/MapComponent.qml
+++ b/examples/location/mapviewer/map/MapComponent.qml
@@ -302,9 +302,25 @@ Map {
Keys.onPressed: {
if (event.key === Qt.Key_Plus) {
- map.zoomLevel++
+ map.zoomLevel++;
} else if (event.key === Qt.Key_Minus) {
- map.zoomLevel--
+ map.zoomLevel--;
+ } else if (event.key === Qt.Key_Left || event.key === Qt.Key_Right ||
+ event.key === Qt.Key_Up || event.key === Qt.Key_Down) {
+ var dx = 0;
+ var dy = 0;
+
+ switch (event.key) {
+
+ case Qt.Key_Left: dx = map.width / 4; break;
+ case Qt.Key_Right: dx = -map.width / 4; break;
+ case Qt.Key_Up: dy = map.height / 4; break;
+ case Qt.Key_Down: dy = -map.height / 4; break;
+
+ }
+
+ var mapCenterPoint = Qt.point(map.width / 2.0 - dx, map.height / 2.0 - dy);
+ map.center = map.toCoordinate(mapCenterPoint);
}
}
@@ -594,14 +610,22 @@ Map {
}
onDoubleClicked: {
- map.center = map.toCoordinate(Qt.point(mouse.x, mouse.y))
+ var mouseGeoPos = map.toCoordinate(Qt.point(mouse.x, mouse.y));
+ var preZoomPoint = map.fromCoordinate(mouseGeoPos, false);
if (mouse.button === Qt.LeftButton) {
- map.zoomLevel++
+ map.zoomLevel++;
} else if (mouse.button === Qt.RightButton) {
- map.zoomLevel--
+ map.zoomLevel--;
}
- lastX = -1
- lastY = -1
+ var postZoomPoint = map.fromCoordinate(mouseGeoPos, false);
+ var dx = postZoomPoint.x - preZoomPoint.x;
+ var dy = postZoomPoint.y - preZoomPoint.y;
+
+ var mapCenterPoint = Qt.point(map.width / 2.0 + dx, map.height / 2.0 + dy);
+ map.center = map.toCoordinate(mapCenterPoint);
+
+ lastX = -1;
+ lastY = -1;
}
onPressAndHold:{
diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp
index f948b0c3..1de22a50 100644
--- a/src/imports/location/qdeclarativegeomap.cpp
+++ b/src/imports/location/qdeclarativegeomap.cpp
@@ -821,31 +821,33 @@ QQmlListProperty<QDeclarativeGeoMapType> QDeclarativeGeoMap::supportedMapTypes()
}
/*!
- \qmlmethod coordinate QtLocation::Map::toCoordinate(QPointF position)
+ \qmlmethod coordinate QtLocation::Map::toCoordinate(QPointF position, bool clipToViewPort)
Returns the coordinate which corresponds to the \a position relative to the map item.
- Returns an invalid coordinate if \a position is not within the current viewport.
+ If \a cliptoViewPort is \c true, or not supplied then returns an invalid coordinate if
+ \a position is not within the current viewport.
*/
-QGeoCoordinate QDeclarativeGeoMap::toCoordinate(const QPointF &position) const
+QGeoCoordinate QDeclarativeGeoMap::toCoordinate(const QPointF &position, bool clipToViewPort) const
{
if (m_map)
- return m_map->itemPositionToCoordinate(QDoubleVector2D(position));
+ return m_map->itemPositionToCoordinate(QDoubleVector2D(position), clipToViewPort);
else
return QGeoCoordinate();
}
/*!
- \qmlmethod point QtLocation::Map::fromCoordinate(coordinate coordinate)
+ \qmlmethod point QtLocation::Map::fromCoordinate(coordinate coordinate, bool clipToViewPort)
Returns the position relative to the map item which corresponds to the \a coordinate.
- Returns an invalid QPointF if \a coordinate is not within the current viewport.
+ If \a cliptoViewPort is \c true, or not supplied then returns an invalid QPointF if
+ \a coordinate is not within the current viewport.
*/
-QPointF QDeclarativeGeoMap::fromCoordinate(const QGeoCoordinate &coordinate) const
+QPointF QDeclarativeGeoMap::fromCoordinate(const QGeoCoordinate &coordinate, bool clipToViewPort) const
{
if (m_map)
- return m_map->coordinateToItemPosition(coordinate).toPointF();
+ return m_map->coordinateToItemPosition(coordinate, clipToViewPort).toPointF();
else
return QPointF(qQNaN(), qQNaN());
}
diff --git a/src/imports/location/qdeclarativegeomap_p.h b/src/imports/location/qdeclarativegeomap_p.h
index 58c07b1b..ddbb8018 100644
--- a/src/imports/location/qdeclarativegeomap_p.h
+++ b/src/imports/location/qdeclarativegeomap_p.h
@@ -103,8 +103,8 @@ public:
Q_INVOKABLE void clearMapItems();
QList<QObject *> mapItems();
- Q_INVOKABLE QGeoCoordinate toCoordinate(const QPointF &position) const;
- Q_INVOKABLE QPointF fromCoordinate(const QGeoCoordinate &coordinate) const;
+ Q_INVOKABLE QGeoCoordinate toCoordinate(const QPointF &position, bool clipToViewPort = true) const;
+ Q_INVOKABLE QPointF fromCoordinate(const QGeoCoordinate &coordinate, bool clipToViewPort = true) const;
#if QT_DEPRECATED_SINCE(5,5)
QT_DEPRECATED Q_INVOKABLE QPointF toScreenPosition(const QGeoCoordinate &coordinate) const;
diff --git a/src/imports/location/qdeclarativegeomapgesturearea.cpp b/src/imports/location/qdeclarativegeomapgesturearea.cpp
index 5a74d231..7d34b729 100644
--- a/src/imports/location/qdeclarativegeomapgesturearea.cpp
+++ b/src/imports/location/qdeclarativegeomapgesturearea.cpp
@@ -658,7 +658,23 @@ void QDeclarativeGeoMapGestureArea::handleTouchEvent(QTouchEvent *event)
void QDeclarativeGeoMapGestureArea::handleWheelEvent(QWheelEvent *event)
{
+ QGeoCoordinate wheelGeoPos = map_->itemPositionToCoordinate(QDoubleVector2D(event->posF()), false);
+ QPointF preZoomPoint = map_->coordinateToItemPosition(wheelGeoPos, false).toPointF();
+
declarativeMap_->setZoomLevel(qBound(minimumZoomLevel(), declarativeMap_->zoomLevel() + event->angleDelta().y() * qreal(0.001), maximumZoomLevel()));
+
+ QPointF postZoomPoint = map_->coordinateToItemPosition(wheelGeoPos, false).toPointF();
+
+ if (preZoomPoint != postZoomPoint)
+ {
+ qreal dx = postZoomPoint.x() - preZoomPoint.x();
+ qreal dy = postZoomPoint.y() - preZoomPoint.y();
+ QPointF mapCenterPoint(map_->width() / 2.0 + dx, map_->height() / 2.0 + dy);
+
+ QGeoCoordinate mapCenterCoordinate = map_->itemPositionToCoordinate(QDoubleVector2D(mapCenterPoint), false);
+ map_->mapController()->setCenter(mapCenterCoordinate);
+ }
+
event->accept();
}