Skip to content

Commit

Permalink
Add queryRenderedFeatures method for qt
Browse files Browse the repository at this point in the history
  • Loading branch information
haluk-pointr committed Jul 25, 2022
1 parent 8a1039e commit 6f9a8a3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions platform/qt/include/QMapLibreGL/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ class Q_MAPLIBREGL_EXPORT Map : public QObject

const QVector<QPair<QString, QString>> &defaultStyles() const;

std::vector<Feature> queryRenderedFeatures(const Coordinate &point, QVector<QString> layerIds);

public slots:
void render();
void connectionEstablished();
Expand Down
18 changes: 18 additions & 0 deletions platform/qt/src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,19 @@ const QVector<QPair<QString, QString>> &Map::defaultStyles() const
return d_ptr->defaultStyles;
}

std::vector<Feature> Map::queryRenderedFeatures(const Coordinate &point, QVector<QString> layerIds){
std::vector<std::string> 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<Feature> qtFeatures;
for(const auto &feature: features){
qtFeatures.push_back(GeoJSON::toFeature(feature));
}
return qtFeatures;
}

/*!
\fn void QMapLibreGL::Map::needsRendering()
Expand Down Expand Up @@ -1540,4 +1553,9 @@ bool MapPrivate::setProperty(const PropertySetter& setter, const QString& layer,
return true;
}

std::vector<mbgl::Feature> MapPrivate::queryRenderedFeatures(const mbgl::ScreenCoordinate& point, const mbgl::RenderedQueryOptions& options) const{
return m_mapRenderer->queryRenderedFeatures(point, options);
}


} // namespace QMapLibreGL
2 changes: 2 additions & 0 deletions platform/qt/src/map_p.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class MapPrivate : public QObject, public mbgl::RendererFrontend
using PropertySetter = mbgl::optional<mbgl::style::conversion::Error> (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<mbgl::Feature> queryRenderedFeatures(const mbgl::ScreenCoordinate& point, const mbgl::RenderedQueryOptions& options = {}) const;

mbgl::EdgeInsets margins;
std::unique_ptr<mbgl::Map> mapObj{};
QVector<QPair<QString, QString>> defaultStyles;
Expand Down
5 changes: 5 additions & 0 deletions platform/qt/src/utils/map_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ void MapRenderer::updateParameters(std::shared_ptr<mbgl::UpdateParameters> newPa
m_updateParameters = std::move(newParameters);
}

std::vector<mbgl::Feature> 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);
Expand Down
2 changes: 2 additions & 0 deletions platform/qt/src/utils/map_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class MapRenderer : public QObject
// Thread-safe, called by the Frontend
void updateParameters(std::shared_ptr<mbgl::UpdateParameters>);

std::vector<mbgl::Feature> queryRenderedFeatures(const mbgl::ScreenCoordinate& point, const mbgl::RenderedQueryOptions& options = {}) const;

signals:
void needsRendering();

Expand Down

0 comments on commit 6f9a8a3

Please sign in to comment.