[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.
This commit is contained in:
@@ -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<std::mutex> 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<std::mutex> 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<SymbolAnnotationImpl>(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<LineAnnotationImpl>(id, annotation, maxZoom)).first->second;
|
||||
std::make_unique<LineAnnotationImpl>(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<FillAnnotationImpl>(id, annotation, maxZoom)).first->second;
|
||||
std::make_unique<FillAnnotationImpl>(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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<style::Image>);
|
||||
@@ -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&);
|
||||
|
||||
|
||||
@@ -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) {
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<mapbox::geojsonvt::GeoJSONVT> shapeTiler;
|
||||
};
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -459,3 +459,19 @@ TEST(Annotations, DebugSparse) {
|
||||
|
||||
test.checkRendering("debug_sparse");
|
||||
}
|
||||
|
||||
TEST(Annotations, ChangeMaxZoom) {
|
||||
AnnotationTest test;
|
||||
|
||||
LineString<double> 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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user