diff options
Diffstat (limited to 'src/location')
-rw-r--r-- | src/location/declarativemaps/qgeomapobject_p.h | 4 | ||||
-rw-r--r-- | src/location/labs/qgeotiledmaplabs.cpp | 37 | ||||
-rw-r--r-- | src/location/labs/qgeotiledmaplabs_p.h | 1 | ||||
-rw-r--r-- | src/location/labs/qsg/qgeomapobjectqsgsupport.cpp | 6 | ||||
-rw-r--r-- | src/location/labs/qsg/qmaprouteobjectqsg.cpp | 5 | ||||
-rw-r--r-- | src/location/labs/qsg/qmaprouteobjectqsg_p_p.h | 1 | ||||
-rw-r--r-- | src/location/maps/qgeomap.cpp | 5 | ||||
-rw-r--r-- | src/location/maps/qgeomap_p.h | 1 |
8 files changed, 59 insertions, 1 deletions
diff --git a/src/location/declarativemaps/qgeomapobject_p.h b/src/location/declarativemaps/qgeomapobject_p.h index bc63e0a6..000d8320 100644 --- a/src/location/declarativemaps/qgeomapobject_p.h +++ b/src/location/declarativemaps/qgeomapobject_p.h @@ -51,6 +51,7 @@ #include <QtLocation/private/qparameterizableobject_p.h> #include <QExplicitlySharedDataPointer> #include <QtPositioning/qgeoshape.h> +#include <qqml.h> QT_BEGIN_NAMESPACE @@ -133,6 +134,9 @@ protected: friend class QGeoMapLayer; friend class QDeclarativeNavigator; }; + QT_END_NAMESPACE +QML_DECLARE_TYPE(QGeoMapObject) + #endif // QGEOMAPOBJECTBASE_H diff --git a/src/location/labs/qgeotiledmaplabs.cpp b/src/location/labs/qgeotiledmaplabs.cpp index 22d582c0..7d8d7108 100644 --- a/src/location/labs/qgeotiledmaplabs.cpp +++ b/src/location/labs/qgeotiledmaplabs.cpp @@ -44,6 +44,8 @@ #include <QtLocation/private/qmapiconobjectqsg_p_p.h> #include <QtLocation/private/qdeclarativepolylinemapitem_p.h> #include <QtLocation/private/qgeomapobjectqsgsupport_p.h> +#include <QtPositioning/private/qlocationutils_p.h> +#include <math.h> QT_BEGIN_NAMESPACE @@ -57,6 +59,7 @@ public: QGeoMapObjectPrivate *createMapObjectImplementation(QGeoMapObject *obj) override; virtual QList<QGeoMapObject *> mapObjects() const override; void removeMapObject(QGeoMapObject *obj); + QList<QObject *>mapObjectsAt(const QGeoCoordinate &coordinate) const; void updateMapObjects(QSGNode *root, QQuickWindow *window); void updateObjectsGeometry(); @@ -95,6 +98,34 @@ void QGeoTiledMapLabsPrivate::removeMapObject(QGeoMapObject *obj) m_qsgSupport.removeMapObject(obj); } +QList<QObject *> QGeoTiledMapLabsPrivate::mapObjectsAt(const QGeoCoordinate &coordinate) const +{ + // ToDo: use a space partitioning strategy + QList<QObject *> res; + for (const auto o: mapObjects()) { + // explicitly handle lines + bool contains = false; + if (o->type() == QGeoMapObject::PolylineType ) { + QMapPolylineObject *mpo = static_cast<QMapPolylineObject *>(o); + qreal mpp = QLocationUtils::metersPerPixel(m_cameraData.zoomLevel(), coordinate); + QGeoPath path = o->geoShape(); + path.setWidth(mpp * mpo->border()->width()); + contains = path.contains(coordinate); + } else if (o->type() == QGeoMapObject::RouteType) { + qreal mpp = QLocationUtils::metersPerPixel(m_cameraData.zoomLevel(), coordinate); + QGeoPath path = o->geoShape(); + path.setWidth(mpp * 4); // MapRouteObjectQSG has a hardcoded 4 pixels width; + contains = path.contains(coordinate); + } else { + contains = o->geoShape().contains(coordinate); + } + + if (contains) + res.append(o); + } + return res; +} + void QGeoTiledMapLabsPrivate::updateMapObjects(QSGNode *root, QQuickWindow *window) { m_qsgSupport.updateMapObjects(root, window); @@ -161,6 +192,12 @@ void QGeoTiledMapLabs::removeMapObject(QGeoMapObject *obj) d->removeMapObject(obj); } +QList<QObject *> QGeoTiledMapLabs::mapObjectsAt(const QGeoCoordinate &coordinate) const +{ + Q_D(const QGeoTiledMapLabs); + return d->mapObjectsAt(coordinate); +} + QGeoTiledMapLabs::QGeoTiledMapLabs(QGeoTiledMapLabsPrivate &dd, QGeoTiledMappingManagerEngine *engine, QObject *parent) : QGeoTiledMap(dd, engine, parent) { diff --git a/src/location/labs/qgeotiledmaplabs_p.h b/src/location/labs/qgeotiledmaplabs_p.h index 4f179028..d10ec633 100644 --- a/src/location/labs/qgeotiledmaplabs_p.h +++ b/src/location/labs/qgeotiledmaplabs_p.h @@ -72,6 +72,7 @@ public: bool createMapObjectImplementation(QGeoMapObject *obj) override; void removeMapObject(QGeoMapObject *obj) override; + QList<QObject *> mapObjectsAt(const QGeoCoordinate &coordinate) const override; protected: QSGNode *updateSceneGraph(QSGNode *node, QQuickWindow *window) override; diff --git a/src/location/labs/qsg/qgeomapobjectqsgsupport.cpp b/src/location/labs/qsg/qgeomapobjectqsgsupport.cpp index e0e3a6d7..1a1b102b 100644 --- a/src/location/labs/qsg/qgeomapobjectqsgsupport.cpp +++ b/src/location/labs/qsg/qgeomapobjectqsgsupport.cpp @@ -126,7 +126,11 @@ QGeoMapObjectPrivate *QGeoMapObjectQSGSupport::createMapObjectImplementationPriv QList<QGeoMapObject *> QGeoMapObjectQSGSupport::mapObjects() const { - return QList<QGeoMapObject *>(); + QList<QGeoMapObject *> res; + for (int i = 0; i < m_mapObjects.size(); ++i) { + res.append(m_mapObjects.at(i).object.data()); + } + return res; } void QGeoMapObjectQSGSupport::removeMapObject(QGeoMapObject *obj) diff --git a/src/location/labs/qsg/qmaprouteobjectqsg.cpp b/src/location/labs/qsg/qmaprouteobjectqsg.cpp index eaea64f3..8f347f88 100644 --- a/src/location/labs/qsg/qmaprouteobjectqsg.cpp +++ b/src/location/labs/qsg/qmaprouteobjectqsg.cpp @@ -100,4 +100,9 @@ void QMapRouteObjectPrivateQSG::setVisible(bool visible) m_polyline->setVisible(visible); } +QGeoShape QMapRouteObjectPrivateQSG::geoShape() const +{ + return m_polyline->geoShape(); +} + QT_END_NAMESPACE diff --git a/src/location/labs/qsg/qmaprouteobjectqsg_p_p.h b/src/location/labs/qsg/qmaprouteobjectqsg_p_p.h index 0c946259..2ade5d53 100644 --- a/src/location/labs/qsg/qmaprouteobjectqsg_p_p.h +++ b/src/location/labs/qsg/qmaprouteobjectqsg_p_p.h @@ -80,6 +80,7 @@ public: QGeoMapObjectPrivate *clone() override; void setMap(QGeoMap *map) override; void setVisible(bool visible) override; + virtual QGeoShape geoShape() const override; // Data Members QScopedPointer<QMapPolylineObjectPrivateQSG> m_polyline; diff --git a/src/location/maps/qgeomap.cpp b/src/location/maps/qgeomap.cpp index 80edac1a..dc8aa2c8 100644 --- a/src/location/maps/qgeomap.cpp +++ b/src/location/maps/qgeomap.cpp @@ -305,6 +305,11 @@ void QGeoMap::removeMapObject(QGeoMapObject * /*obj*/) { } +QList<QObject *> QGeoMap::mapObjectsAt(const QGeoCoordinate &/*coordinate*/) const +{ + return QList<QObject *>(); +} + void QGeoMap::setVisibleArea(const QRectF &visibleArea) { Q_D(QGeoMap); diff --git a/src/location/maps/qgeomap_p.h b/src/location/maps/qgeomap_p.h index c0af9e10..216c8b64 100644 --- a/src/location/maps/qgeomap_p.h +++ b/src/location/maps/qgeomap_p.h @@ -154,6 +154,7 @@ public: virtual void setCopyrightVisible(bool visible); virtual void removeMapObject(QGeoMapObject *obj); + virtual QList<QObject *> mapObjectsAt(const QGeoCoordinate &coordinate) const; void setVisibleArea(const QRectF &visibleArea); QRectF visibleArea() const; |