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

Backport: Don't tie Annotation geometries to Map maxzoom #10818

Merged
merged 1 commit into from
Jan 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/mbgl/annotation/annotation_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
Expand All @@ -89,31 +89,31 @@ 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
return;
}

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
return;
}

shapeAnnotations.erase(it);
add(id, annotation, maxZoom);
add(id, annotation);
dirty = true;
}

Expand Down
16 changes: 8 additions & 8 deletions src/mbgl/annotation/annotation_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class AnnotationManager : private util::noncopyable {
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>);
Expand All @@ -49,13 +49,13 @@ class AnnotationManager : private util::noncopyable {
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&);

Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/annotation/fill_annotation_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/annotation/fill_annotation_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/annotation/line_annotation_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/annotation/line_annotation_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/mbgl/annotation/shape_annotation_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
}

Expand All @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/mbgl/annotation/shape_annotation_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,7 +26,6 @@ class ShapeAnnotationImpl {
void updateTileData(const CanonicalTileID&, AnnotationTileData&);

const AnnotationID id;
const uint8_t maxZoom;
const std::string layerID;
std::unique_ptr<mapbox::geojsonvt::GeoJSONVT> shapeTiler;
};
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,13 +647,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();
}
}
Expand Down
16 changes: 16 additions & 0 deletions test/api/annotations.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}