Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit 8ace0d3

Browse files
committed
[core] AnnotationTileLayer vends its own name (#5163)
Fixes #5159.
1 parent 27f9a85 commit 8ace0d3

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

src/mbgl/annotation/annotation_manager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ std::unique_ptr<AnnotationTile> AnnotationManager::getTile(const CanonicalTileID
9090

9191
AnnotationTileLayer& pointLayer = *tile->layers.emplace(
9292
PointLayerID,
93-
std::make_unique<AnnotationTileLayer>()).first->second;
93+
std::make_unique<AnnotationTileLayer>(PointLayerID)).first->second;
9494

9595
LatLngBounds tileBounds(tileID);
9696

src/mbgl/annotation/annotation_tile.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ optional<Value> AnnotationTileFeature::getValue(const std::string& key) const {
2121
return optional<Value>();
2222
}
2323

24+
AnnotationTileLayer::AnnotationTileLayer(const std::string &name_)
25+
: name(name_) {}
26+
2427
util::ptr<GeometryTileLayer> AnnotationTile::getLayer(const std::string& name) const {
2528
auto it = layers.find(name);
2629
if (it != layers.end()) {

src/mbgl/annotation/annotation_tile.hpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@ class AnnotationTileFeature : public GeometryTileFeature {
2424

2525
class AnnotationTileLayer : public GeometryTileLayer {
2626
public:
27+
AnnotationTileLayer(const std::string&);
28+
2729
std::size_t featureCount() const override { return features.size(); }
2830
util::ptr<const GeometryTileFeature> getFeature(std::size_t i) const override { return features[i]; }
29-
std::string getName() const override { return ""; };
31+
std::string getName() const override { return name; };
3032

3133
std::vector<util::ptr<const AnnotationTileFeature>> features;
34+
35+
private:
36+
std::string name;
3237
};
3338

3439
class AnnotationTile : public GeometryTile {

src/mbgl/annotation/shape_annotation_impl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void ShapeAnnotationImpl::updateTile(const CanonicalTileID& tileID, AnnotationTi
119119
return;
120120

121121
AnnotationTileLayer& layer = *tile.layers.emplace(layerID,
122-
std::make_unique<AnnotationTileLayer>()).first->second;
122+
std::make_unique<AnnotationTileLayer>(layerID)).first->second;
123123

124124
for (auto& shapeFeature : shapeTile.features) {
125125
FeatureType featureType = FeatureType::Unknown;

test/api/annotations.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,23 @@ TEST(Annotations, SwitchStyle) {
259259

260260
checkRendering(map, "switch_style");
261261
}
262+
263+
TEST(Annotations, QueryRenderedFeatures) {
264+
util::RunLoop loop;
265+
266+
auto display = std::make_shared<mbgl::HeadlessDisplay>();
267+
HeadlessView view(display, 1);
268+
StubFileSource fileSource;
269+
270+
Map map(view, fileSource, MapMode::Still);
271+
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), "");
272+
map.addAnnotationIcon("default_marker", namedMarker("default_marker.png"));
273+
const LatLng latLng(0, 0);
274+
map.addPointAnnotation(PointAnnotation(latLng, "default_marker"));
275+
276+
test::render(map);
277+
278+
auto point = map.pixelForLatLng(latLng);
279+
auto features = map.queryRenderedFeatures(point);
280+
EXPECT_EQ(features.size(), 1);
281+
}

0 commit comments

Comments
 (0)