From 303e27f10514edfce1f9dfcd063fe3b1363afb61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Fri, 22 Dec 2017 16:27:31 +0100 Subject: [core] don't tie Annotation geometries to Map maxzoom Instead, geometry generation via GeoJSONVT is now bound to the hardcoded limit of the annotation tile source. --- src/mbgl/annotation/annotation_manager.cpp | 30 +++++++++++++-------------- src/mbgl/annotation/annotation_manager.hpp | 16 +++++++------- src/mbgl/annotation/fill_annotation_impl.cpp | 4 ++-- src/mbgl/annotation/fill_annotation_impl.hpp | 2 +- src/mbgl/annotation/line_annotation_impl.cpp | 4 ++-- src/mbgl/annotation/line_annotation_impl.hpp | 2 +- src/mbgl/annotation/shape_annotation_impl.cpp | 7 ++++--- src/mbgl/annotation/shape_annotation_impl.hpp | 3 +-- src/mbgl/map/map.cpp | 4 ++-- test/api/annotations.test.cpp | 16 ++++++++++++++ 10 files changed, 52 insertions(+), 36 deletions(-) diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp index a4d53bbd3f..b94b0a1bce 100644 --- a/src/mbgl/annotation/annotation_manager.cpp +++ b/src/mbgl/annotation/annotation_manager.cpp @@ -34,20 +34,20 @@ void AnnotationManager::onStyleLoaded() { updateStyle(); } -AnnotationID AnnotationManager::addAnnotation(const Annotation& annotation, const uint8_t maxZoom) { +AnnotationID AnnotationManager::addAnnotation(const Annotation& annotation) { std::lock_guard lock(mutex); AnnotationID id = nextID++; Annotation::visit(annotation, [&] (const auto& annotation_) { - this->add(id, annotation_, maxZoom); + this->add(id, annotation_); }); dirty = true; return id; } -bool AnnotationManager::updateAnnotation(const AnnotationID& id, const Annotation& annotation, const uint8_t maxZoom) { +bool AnnotationManager::updateAnnotation(const AnnotationID& id, const Annotation& annotation) { std::lock_guard lock(mutex); Annotation::visit(annotation, [&] (const auto& annotation_) { - this->update(id, annotation_, maxZoom); + this->update(id, annotation_); }); return dirty; } @@ -58,25 +58,25 @@ void AnnotationManager::removeAnnotation(const AnnotationID& id) { dirty = true; } -void AnnotationManager::add(const AnnotationID& id, const SymbolAnnotation& annotation, const uint8_t) { +void AnnotationManager::add(const AnnotationID& id, const SymbolAnnotation& annotation) { auto impl = std::make_shared(id, annotation); symbolTree.insert(impl); symbolAnnotations.emplace(id, impl); } -void AnnotationManager::add(const AnnotationID& id, const LineAnnotation& annotation, const uint8_t maxZoom) { +void AnnotationManager::add(const AnnotationID& id, const LineAnnotation& annotation) { ShapeAnnotationImpl& impl = *shapeAnnotations.emplace(id, - std::make_unique(id, annotation, maxZoom)).first->second; + std::make_unique(id, annotation)).first->second; impl.updateStyle(*style.get().impl); } -void AnnotationManager::add(const AnnotationID& id, const FillAnnotation& annotation, const uint8_t maxZoom) { +void AnnotationManager::add(const AnnotationID& id, const FillAnnotation& annotation) { ShapeAnnotationImpl& impl = *shapeAnnotations.emplace(id, - std::make_unique(id, annotation, maxZoom)).first->second; + std::make_unique(id, annotation)).first->second; impl.updateStyle(*style.get().impl); } -void AnnotationManager::update(const AnnotationID& id, const SymbolAnnotation& annotation, const uint8_t maxZoom) { +void AnnotationManager::update(const AnnotationID& id, const SymbolAnnotation& annotation) { auto it = symbolAnnotations.find(id); if (it == symbolAnnotations.end()) { assert(false); // Attempt to update a non-existent symbol annotation @@ -89,11 +89,11 @@ void AnnotationManager::update(const AnnotationID& id, const SymbolAnnotation& a dirty = true; remove(id); - add(id, annotation, maxZoom); + add(id, annotation); } } -void AnnotationManager::update(const AnnotationID& id, const LineAnnotation& annotation, const uint8_t maxZoom) { +void AnnotationManager::update(const AnnotationID& id, const LineAnnotation& annotation) { auto it = shapeAnnotations.find(id); if (it == shapeAnnotations.end()) { assert(false); // Attempt to update a non-existent shape annotation @@ -101,11 +101,11 @@ void AnnotationManager::update(const AnnotationID& id, const LineAnnotation& ann } shapeAnnotations.erase(it); - add(id, annotation, maxZoom); + add(id, annotation); dirty = true; } -void AnnotationManager::update(const AnnotationID& id, const FillAnnotation& annotation, const uint8_t maxZoom) { +void AnnotationManager::update(const AnnotationID& id, const FillAnnotation& annotation) { auto it = shapeAnnotations.find(id); if (it == shapeAnnotations.end()) { assert(false); // Attempt to update a non-existent shape annotation @@ -113,7 +113,7 @@ void AnnotationManager::update(const AnnotationID& id, const FillAnnotation& ann } shapeAnnotations.erase(it); - add(id, annotation, maxZoom); + add(id, annotation); dirty = true; } diff --git a/src/mbgl/annotation/annotation_manager.hpp b/src/mbgl/annotation/annotation_manager.hpp index 22b25cd2ac..326565f8bc 100644 --- a/src/mbgl/annotation/annotation_manager.hpp +++ b/src/mbgl/annotation/annotation_manager.hpp @@ -28,8 +28,8 @@ public: AnnotationManager(style::Style&); ~AnnotationManager(); - AnnotationID addAnnotation(const Annotation&, const uint8_t maxZoom); - bool updateAnnotation(const AnnotationID&, const Annotation&, const uint8_t maxZoom); + AnnotationID addAnnotation(const Annotation&); + bool updateAnnotation(const AnnotationID&, const Annotation&); void removeAnnotation(const AnnotationID&); void addImage(std::unique_ptr); @@ -49,13 +49,13 @@ public: static const std::string ShapeLayerID; private: - void add(const AnnotationID&, const SymbolAnnotation&, const uint8_t); - void add(const AnnotationID&, const LineAnnotation&, const uint8_t); - void add(const AnnotationID&, const FillAnnotation&, const uint8_t); + void add(const AnnotationID&, const SymbolAnnotation&); + void add(const AnnotationID&, const LineAnnotation&); + void add(const AnnotationID&, const FillAnnotation&); - void update(const AnnotationID&, const SymbolAnnotation&, const uint8_t); - void update(const AnnotationID&, const LineAnnotation&, const uint8_t); - void update(const AnnotationID&, const FillAnnotation&, const uint8_t); + void update(const AnnotationID&, const SymbolAnnotation&); + void update(const AnnotationID&, const LineAnnotation&); + void update(const AnnotationID&, const FillAnnotation&); void remove(const AnnotationID&); diff --git a/src/mbgl/annotation/fill_annotation_impl.cpp b/src/mbgl/annotation/fill_annotation_impl.cpp index 9c73aeb796..9d3e12e004 100644 --- a/src/mbgl/annotation/fill_annotation_impl.cpp +++ b/src/mbgl/annotation/fill_annotation_impl.cpp @@ -7,8 +7,8 @@ namespace mbgl { using namespace style; -FillAnnotationImpl::FillAnnotationImpl(AnnotationID id_, FillAnnotation annotation_, uint8_t maxZoom_) - : ShapeAnnotationImpl(id_, maxZoom_), +FillAnnotationImpl::FillAnnotationImpl(AnnotationID id_, FillAnnotation annotation_) + : ShapeAnnotationImpl(id_), annotation(ShapeAnnotationGeometry::visit(annotation_.geometry, CloseShapeAnnotation{}), annotation_.opacity, annotation_.color, annotation_.outlineColor) { } diff --git a/src/mbgl/annotation/fill_annotation_impl.hpp b/src/mbgl/annotation/fill_annotation_impl.hpp index 5c49e447b8..98f9921514 100644 --- a/src/mbgl/annotation/fill_annotation_impl.hpp +++ b/src/mbgl/annotation/fill_annotation_impl.hpp @@ -7,7 +7,7 @@ namespace mbgl { class FillAnnotationImpl : public ShapeAnnotationImpl { public: - FillAnnotationImpl(AnnotationID, FillAnnotation, uint8_t maxZoom); + FillAnnotationImpl(AnnotationID, FillAnnotation); void updateStyle(style::Style::Impl&) const final; const ShapeAnnotationGeometry& geometry() const final; diff --git a/src/mbgl/annotation/line_annotation_impl.cpp b/src/mbgl/annotation/line_annotation_impl.cpp index d35b956888..74fec49af8 100644 --- a/src/mbgl/annotation/line_annotation_impl.cpp +++ b/src/mbgl/annotation/line_annotation_impl.cpp @@ -7,8 +7,8 @@ namespace mbgl { using namespace style; -LineAnnotationImpl::LineAnnotationImpl(AnnotationID id_, LineAnnotation annotation_, uint8_t maxZoom_) - : ShapeAnnotationImpl(id_, maxZoom_), +LineAnnotationImpl::LineAnnotationImpl(AnnotationID id_, LineAnnotation annotation_) + : ShapeAnnotationImpl(id_), annotation(ShapeAnnotationGeometry::visit(annotation_.geometry, CloseShapeAnnotation{}), annotation_.opacity, annotation_.width, annotation_.color) { } diff --git a/src/mbgl/annotation/line_annotation_impl.hpp b/src/mbgl/annotation/line_annotation_impl.hpp index 548a094d53..108787c422 100644 --- a/src/mbgl/annotation/line_annotation_impl.hpp +++ b/src/mbgl/annotation/line_annotation_impl.hpp @@ -7,7 +7,7 @@ namespace mbgl { class LineAnnotationImpl : public ShapeAnnotationImpl { public: - LineAnnotationImpl(AnnotationID, LineAnnotation, uint8_t maxZoom); + LineAnnotationImpl(AnnotationID, LineAnnotation); void updateStyle(style::Style::Impl&) const final; const ShapeAnnotationGeometry& geometry() const final; diff --git a/src/mbgl/annotation/shape_annotation_impl.cpp b/src/mbgl/annotation/shape_annotation_impl.cpp index 9288159b6a..715dce484e 100644 --- a/src/mbgl/annotation/shape_annotation_impl.cpp +++ b/src/mbgl/annotation/shape_annotation_impl.cpp @@ -13,9 +13,8 @@ namespace mbgl { using namespace style; namespace geojsonvt = mapbox::geojsonvt; -ShapeAnnotationImpl::ShapeAnnotationImpl(const AnnotationID id_, const uint8_t maxZoom_) +ShapeAnnotationImpl::ShapeAnnotationImpl(const AnnotationID id_) : id(id_), - maxZoom(maxZoom_), layerID(AnnotationManager::ShapeLayerID + util::toString(id)) { } @@ -28,7 +27,9 @@ void ShapeAnnotationImpl::updateTileData(const CanonicalTileID& tileID, Annotati return Feature { std::move(geom) }; })); mapbox::geojsonvt::Options options; - options.maxZoom = maxZoom; + // The annotation source is currently hard coded to maxzoom 16, so we're topping out at z16 + // here as well. + options.maxZoom = 16; options.buffer = 255u; options.extent = util::EXTENT; options.tolerance = baseTolerance; diff --git a/src/mbgl/annotation/shape_annotation_impl.hpp b/src/mbgl/annotation/shape_annotation_impl.hpp index caf2cff1a5..3e28221f7b 100644 --- a/src/mbgl/annotation/shape_annotation_impl.hpp +++ b/src/mbgl/annotation/shape_annotation_impl.hpp @@ -17,7 +17,7 @@ class CanonicalTileID; class ShapeAnnotationImpl { public: - ShapeAnnotationImpl(const AnnotationID, const uint8_t maxZoom); + ShapeAnnotationImpl(const AnnotationID); virtual ~ShapeAnnotationImpl() = default; virtual void updateStyle(style::Style::Impl&) const = 0; @@ -26,7 +26,6 @@ public: void updateTileData(const CanonicalTileID&, AnnotationTileData&); const AnnotationID id; - const uint8_t maxZoom; const std::string layerID; std::unique_ptr shapeTiler; }; diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 5aa534724f..947973415a 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -676,13 +676,13 @@ double Map::getTopOffsetPixelsForAnnotationImage(const std::string& id) { } AnnotationID Map::addAnnotation(const Annotation& annotation) { - auto result = impl->annotationManager.addAnnotation(annotation, getMaxZoom()); + auto result = impl->annotationManager.addAnnotation(annotation); impl->onUpdate(); return result; } void Map::updateAnnotation(AnnotationID id, const Annotation& annotation) { - if (impl->annotationManager.updateAnnotation(id, annotation, getMaxZoom())) { + if (impl->annotationManager.updateAnnotation(id, annotation)) { impl->onUpdate(); } } diff --git a/test/api/annotations.test.cpp b/test/api/annotations.test.cpp index d5e76fc21e..07257851ac 100644 --- a/test/api/annotations.test.cpp +++ b/test/api/annotations.test.cpp @@ -459,3 +459,19 @@ TEST(Annotations, DebugSparse) { test.checkRendering("debug_sparse"); } + +TEST(Annotations, ChangeMaxZoom) { + AnnotationTest test; + + LineString line = {{ { 0, 0 }, { 45, 45 }, { 30, 0 } }}; + LineAnnotation annotation { line }; + annotation.color = Color::red(); + annotation.width = { 5 }; + + test.map.setMaxZoom(6); + test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json")); + test.map.addAnnotation(annotation); + test.map.setMaxZoom(14); + test.map.setZoom(test.map.getMaxZoom()); + test.checkRendering("line_annotation_max_zoom"); +} -- cgit v1.2.1