[core, android, ios, macos] Replaced getPointAnnotationsInBounds() w/ queryPointAnnotations() (#5165)

queryPointAnnotations() accepts a screen rectangle instead of a geographic bounding box, so marker hit testing works at the edges of a rotated, tilted map view.

Fixes #5151.
This commit is contained in:
Minh Nguyễn
2016-08-12 15:45:18 -07:00
committed by Jesse Bounds
parent 272ec0c30b
commit e147887e35
16 changed files with 75 additions and 63 deletions

View File

@@ -115,17 +115,6 @@ void AnnotationManager::removeAndAdd(const AnnotationID& id, const Annotation& a
});
}
AnnotationIDs AnnotationManager::getPointAnnotationsInBounds(const LatLngBounds& bounds) const {
AnnotationIDs result;
symbolTree.query(boost::geometry::index::intersects(bounds),
boost::make_function_output_iterator([&](const auto& val){
result.push_back(val->id);
}));
return result;
}
std::unique_ptr<AnnotationTileData> AnnotationManager::getTileData(const CanonicalTileID& tileID) {
if (symbolAnnotations.empty() && shapeAnnotations.empty())
return nullptr;

View File

@@ -33,8 +33,6 @@ public:
Update updateAnnotation(const AnnotationID&, const Annotation&, const uint8_t maxZoom);
void removeAnnotation(const AnnotationID&);
AnnotationIDs getPointAnnotationsInBounds(const LatLngBounds&) const;
void addIcon(const std::string& name, std::shared_ptr<const SpriteImage>);
void removeIcon(const std::string& name);
double getTopOffsetPixelsForIcon(const std::string& name);

View File

@@ -21,9 +21,11 @@ AnnotationTile::~AnnotationTile() {
void AnnotationTile::setNecessity(Necessity) {}
AnnotationTileFeature::AnnotationTileFeature(FeatureType type_, GeometryCollection geometries_,
std::unordered_map<std::string, std::string> properties_)
: type(type_),
AnnotationTileFeature::AnnotationTileFeature(const AnnotationID id_,
FeatureType type_, GeometryCollection geometries_,
std::unordered_map<std::string, std::string> properties_)
: id(id_),
type(type_),
properties(std::move(properties_)),
geometries(std::move(geometries_)) {}

View File

@@ -1,5 +1,6 @@
#pragma once
#include <mbgl/annotation/annotation.hpp>
#include <mbgl/tile/geometry_tile.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
@@ -25,13 +26,15 @@ private:
class AnnotationTileFeature : public GeometryTileFeature {
public:
AnnotationTileFeature(FeatureType, GeometryCollection,
AnnotationTileFeature(AnnotationID, FeatureType, GeometryCollection,
std::unordered_map<std::string, std::string> properties = {{}});
FeatureType getType() const override { return type; }
optional<Value> getValue(const std::string&) const override;
optional<FeatureIdentifier> getID() const override { return { id }; }
GeometryCollection getGeometries() const override { return geometries; }
const AnnotationID id;
const FeatureType type;
const std::unordered_map<std::string, std::string> properties;
const GeometryCollection geometries;

View File

@@ -55,7 +55,7 @@ void ShapeAnnotationImpl::updateTileData(const CanonicalTileID& tileID, Annotati
}
layer.features.emplace_back(
std::make_shared<AnnotationTileFeature>(featureType, renderGeometry));
std::make_shared<AnnotationTileFeature>(id, featureType, renderGeometry));
}
}

View File

@@ -31,7 +31,8 @@ void SymbolAnnotationImpl::updateLayer(const CanonicalTileID& tileID, Annotation
projected *= double(util::EXTENT);
layer.features.emplace_back(
std::make_shared<const AnnotationTileFeature>(FeatureType::Point,
std::make_shared<const AnnotationTileFeature>(id,
FeatureType::Point,
GeometryCollection {{ {{ convertPoint<int16_t>(projected) }} }},
featureProperties));
}

View File

@@ -703,10 +703,6 @@ void Map::removeAnnotation(AnnotationID annotation) {
update(Update::AnnotationStyle | Update::AnnotationData);
}
AnnotationIDs Map::getPointAnnotationsInBounds(const LatLngBounds& bounds) {
return impl->annotationManager->getPointAnnotationsInBounds(bounds);
}
#pragma mark - Feature query api
std::vector<Feature> Map::queryRenderedFeatures(const ScreenCoordinate& point, const optional<std::vector<std::string>>& layerIDs) {
@@ -735,6 +731,18 @@ std::vector<Feature> Map::queryRenderedFeatures(const ScreenBox& box, const opti
});
}
AnnotationIDs Map::queryPointAnnotations(const ScreenBox& box) {
auto features = queryRenderedFeatures(box, {{ AnnotationManager::PointLayerID }});
AnnotationIDs ids;
ids.reserve(features.size());
for (auto &feature : features) {
assert(feature.id);
assert(*feature.id <= std::numeric_limits<AnnotationID>::max());
ids.push_back(static_cast<AnnotationID>(feature.id->get<uint64_t>()));
}
return ids;
}
#pragma mark - Style API
style::Source* Map::getSource(const std::string& sourceID) {