[core] implement queryRenderedFeatures

This commit is contained in:
Ansis Brammanis
2016-04-05 16:27:37 -07:00
committed by John Firebaugh
parent 25442a77be
commit 61d14089e0
51 changed files with 1295 additions and 179 deletions

View File

@@ -22,6 +22,7 @@
#include <mbgl/util/exception.hpp>
#include <mbgl/util/async_task.hpp>
#include <mbgl/util/mapbox.hpp>
#include <mbgl/util/tile_coordinate.hpp>
namespace mbgl {
@@ -711,6 +712,39 @@ AnnotationIDs Map::getPointAnnotationsInBounds(const LatLngBounds& bounds) {
return impl->annotationManager->getPointAnnotationsInBounds(bounds);
}
#pragma mark - Feature query api
std::vector<TileCoordinate> pointsToCoordinates(const std::vector<ScreenCoordinate>& queryPoints, const TransformState& transformState) {
std::vector<TileCoordinate> queryGeometry;
for (auto& p : queryPoints) {
queryGeometry.push_back(TileCoordinate::fromScreenCoordinate(transformState, 0, { p.x, transformState.getHeight() - p.y }));
}
return queryGeometry;
}
std::vector<std::string> Map::queryRenderedFeatures(const ScreenCoordinate& point, const optional<std::vector<std::string>>& layerIDs) {
if (!impl->style) return {};
auto queryGeometry = pointsToCoordinates({ point }, impl->transform.getState());
return impl->style->queryRenderedFeatures(queryGeometry, impl->transform.getZoom(), impl->transform.getAngle(), layerIDs);
}
std::vector<std::string> Map::queryRenderedFeatures(const std::array<ScreenCoordinate, 2>& box, const optional<std::vector<std::string>>& layerIDs) {
if (!impl->style) return {};
std::vector<ScreenCoordinate> queryPoints {
{ box[0].x, box[0].y },
{ box[1].x, box[0].y },
{ box[1].x, box[1].y },
{ box[0].x, box[1].y },
{ box[0].x, box[0].y }
};
auto queryGeometry = pointsToCoordinates(queryPoints, impl->transform.getState());
return impl->style->queryRenderedFeatures(queryGeometry, impl->transform.getZoom(), impl->transform.getAngle(), layerIDs);
}
#pragma mark - Style API
void Map::addCustomLayer(const std::string& id,