From 6f9a8a3b9902224f0dc0188858a07d6d5c8a5b07 Mon Sep 17 00:00:00 2001 From: haluk-pointr Date: Mon, 25 Jul 2022 17:17:59 +0300 Subject: [PATCH] Add queryRenderedFeatures method for qt --- platform/qt/include/QMapLibreGL/map.hpp | 2 ++ platform/qt/src/map.cpp | 18 ++++++++++++++++++ platform/qt/src/map_p.hpp | 2 ++ platform/qt/src/utils/map_renderer.cpp | 5 +++++ platform/qt/src/utils/map_renderer.hpp | 2 ++ 5 files changed, 29 insertions(+) diff --git a/platform/qt/include/QMapLibreGL/map.hpp b/platform/qt/include/QMapLibreGL/map.hpp index 4b6450ca60d..18a2d9002d5 100644 --- a/platform/qt/include/QMapLibreGL/map.hpp +++ b/platform/qt/include/QMapLibreGL/map.hpp @@ -174,6 +174,8 @@ class Q_MAPLIBREGL_EXPORT Map : public QObject const QVector> &defaultStyles() const; + std::vector queryRenderedFeatures(const Coordinate &point, QVector layerIds); + public slots: void render(); void connectionEstablished(); diff --git a/platform/qt/src/map.cpp b/platform/qt/src/map.cpp index 6be15823ba1..a247d8a087c 100644 --- a/platform/qt/src/map.cpp +++ b/platform/qt/src/map.cpp @@ -1316,6 +1316,19 @@ const QVector> &Map::defaultStyles() const return d_ptr->defaultStyles; } +std::vector Map::queryRenderedFeatures(const Coordinate &point, QVector layerIds){ + std::vector stdLayerIds; + for(const auto &layerId: layerIds){ + stdLayerIds.push_back(layerId.toStdString()); + } + auto features = d_ptr->queryRenderedFeatures({point.first, point.second}, mbgl::RenderedQueryOptions(stdLayerIds,{})); + std::vector qtFeatures; + for(const auto &feature: features){ + qtFeatures.push_back(GeoJSON::toFeature(feature)); + } + return qtFeatures; +} + /*! \fn void QMapLibreGL::Map::needsRendering() @@ -1540,4 +1553,9 @@ bool MapPrivate::setProperty(const PropertySetter& setter, const QString& layer, return true; } +std::vector MapPrivate::queryRenderedFeatures(const mbgl::ScreenCoordinate& point, const mbgl::RenderedQueryOptions& options) const{ + return m_mapRenderer->queryRenderedFeatures(point, options); +} + + } // namespace QMapLibreGL diff --git a/platform/qt/src/map_p.hpp b/platform/qt/src/map_p.hpp index af5e0d4852e..d7b66863f2c 100644 --- a/platform/qt/src/map_p.hpp +++ b/platform/qt/src/map_p.hpp @@ -41,6 +41,8 @@ class MapPrivate : public QObject, public mbgl::RendererFrontend using PropertySetter = mbgl::optional (mbgl::style::Layer::*)(const std::string&, const mbgl::style::conversion::Convertible&); bool setProperty(const PropertySetter& setter, const QString& layer, const QString& name, const QVariant& value); + std::vector queryRenderedFeatures(const mbgl::ScreenCoordinate& point, const mbgl::RenderedQueryOptions& options = {}) const; + mbgl::EdgeInsets margins; std::unique_ptr mapObj{}; QVector> defaultStyles; diff --git a/platform/qt/src/utils/map_renderer.cpp b/platform/qt/src/utils/map_renderer.cpp index b2798d44361..2bad0839c31 100644 --- a/platform/qt/src/utils/map_renderer.cpp +++ b/platform/qt/src/utils/map_renderer.cpp @@ -64,6 +64,11 @@ void MapRenderer::updateParameters(std::shared_ptr newPa m_updateParameters = std::move(newParameters); } +std::vector MapRenderer::queryRenderedFeatures(const mbgl::ScreenCoordinate& point, const mbgl::RenderedQueryOptions& options) const +{ + return m_renderer->queryRenderedFeatures(point,options); +} + void MapRenderer::updateFramebuffer(quint32 fbo, const mbgl::Size &size) { MBGL_VERIFY_THREAD(tid); diff --git a/platform/qt/src/utils/map_renderer.hpp b/platform/qt/src/utils/map_renderer.hpp index e37d384eee2..41fc0aa98e2 100644 --- a/platform/qt/src/utils/map_renderer.hpp +++ b/platform/qt/src/utils/map_renderer.hpp @@ -38,6 +38,8 @@ class MapRenderer : public QObject // Thread-safe, called by the Frontend void updateParameters(std::shared_ptr); + std::vector queryRenderedFeatures(const mbgl::ScreenCoordinate& point, const mbgl::RenderedQueryOptions& options = {}) const; + signals: void needsRendering();