[core] annotation manager - manage dirty state internally
This commit is contained in:
committed by
Ivo van Dongen
parent
0694d224c7
commit
377faaf4f8
@@ -39,19 +39,22 @@ AnnotationID AnnotationManager::addAnnotation(const Annotation& annotation, cons
|
||||
Annotation::visit(annotation, [&] (const auto& annotation_) {
|
||||
this->add(id, annotation_, maxZoom);
|
||||
});
|
||||
dirty = true;
|
||||
return id;
|
||||
}
|
||||
|
||||
Update AnnotationManager::updateAnnotation(const AnnotationID& id, const Annotation& annotation, const uint8_t maxZoom) {
|
||||
bool AnnotationManager::updateAnnotation(const AnnotationID& id, const Annotation& annotation, const uint8_t maxZoom) {
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
return Annotation::visit(annotation, [&] (const auto& annotation_) {
|
||||
return this->update(id, annotation_, maxZoom);
|
||||
Annotation::visit(annotation, [&] (const auto& annotation_) {
|
||||
this->update(id, annotation_, maxZoom);
|
||||
});
|
||||
return dirty;
|
||||
}
|
||||
|
||||
void AnnotationManager::removeAnnotation(const AnnotationID& id) {
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
remove(id);
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
void AnnotationManager::add(const AnnotationID& id, const SymbolAnnotation& annotation, const uint8_t) {
|
||||
@@ -72,49 +75,45 @@ void AnnotationManager::add(const AnnotationID& id, const FillAnnotation& annota
|
||||
impl.updateStyle(*style.get().impl);
|
||||
}
|
||||
|
||||
Update AnnotationManager::update(const AnnotationID& id, const SymbolAnnotation& annotation, const uint8_t maxZoom) {
|
||||
Update result = Update::Nothing;
|
||||
|
||||
void AnnotationManager::update(const AnnotationID& id, const SymbolAnnotation& annotation, const uint8_t maxZoom) {
|
||||
auto it = symbolAnnotations.find(id);
|
||||
if (it == symbolAnnotations.end()) {
|
||||
assert(false); // Attempt to update a non-existent symbol annotation
|
||||
return result;
|
||||
return;
|
||||
}
|
||||
|
||||
const SymbolAnnotation& existing = it->second->annotation;
|
||||
|
||||
if (existing.geometry != annotation.geometry || existing.icon != annotation.icon) {
|
||||
result |= Update::AnnotationData;
|
||||
dirty = true;
|
||||
|
||||
remove(id);
|
||||
add(id, annotation, maxZoom);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Update AnnotationManager::update(const AnnotationID& id, const LineAnnotation& annotation, const uint8_t maxZoom) {
|
||||
void AnnotationManager::update(const AnnotationID& id, const LineAnnotation& annotation, const uint8_t maxZoom) {
|
||||
auto it = shapeAnnotations.find(id);
|
||||
if (it == shapeAnnotations.end()) {
|
||||
assert(false); // Attempt to update a non-existent shape annotation
|
||||
return Update::Nothing;
|
||||
return;
|
||||
}
|
||||
|
||||
shapeAnnotations.erase(it);
|
||||
add(id, annotation, maxZoom);
|
||||
return Update::AnnotationData;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
Update AnnotationManager::update(const AnnotationID& id, const FillAnnotation& annotation, const uint8_t maxZoom) {
|
||||
void AnnotationManager::update(const AnnotationID& id, const FillAnnotation& annotation, const uint8_t maxZoom) {
|
||||
auto it = shapeAnnotations.find(id);
|
||||
if (it == shapeAnnotations.end()) {
|
||||
assert(false); // Attempt to update a non-existent shape annotation
|
||||
return Update::Nothing;
|
||||
return;
|
||||
}
|
||||
|
||||
shapeAnnotations.erase(it);
|
||||
add(id, annotation, maxZoom);
|
||||
return Update::AnnotationData;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
void AnnotationManager::remove(const AnnotationID& id) {
|
||||
@@ -187,8 +186,11 @@ void AnnotationManager::updateStyle() {
|
||||
|
||||
void AnnotationManager::updateData() {
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
for (auto& tile : tiles) {
|
||||
tile->setData(getTileData(tile->id.canonical));
|
||||
if (dirty) {
|
||||
for (auto& tile : tiles) {
|
||||
tile->setData(getTileData(tile->id.canonical));
|
||||
}
|
||||
dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include <mbgl/annotation/annotation.hpp>
|
||||
#include <mbgl/annotation/symbol_annotation_impl.hpp>
|
||||
#include <mbgl/style/image.hpp>
|
||||
#include <mbgl/map/update.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
|
||||
#include <mutex>
|
||||
@@ -30,7 +29,7 @@ public:
|
||||
~AnnotationManager();
|
||||
|
||||
AnnotationID addAnnotation(const Annotation&, const uint8_t maxZoom);
|
||||
Update updateAnnotation(const AnnotationID&, const Annotation&, const uint8_t maxZoom);
|
||||
bool updateAnnotation(const AnnotationID&, const Annotation&, const uint8_t maxZoom);
|
||||
void removeAnnotation(const AnnotationID&);
|
||||
|
||||
void addImage(std::unique_ptr<style::Image>);
|
||||
@@ -53,9 +52,9 @@ private:
|
||||
void add(const AnnotationID&, const LineAnnotation&, const uint8_t);
|
||||
void add(const AnnotationID&, const FillAnnotation&, const uint8_t);
|
||||
|
||||
Update update(const AnnotationID&, const SymbolAnnotation&, const uint8_t);
|
||||
Update update(const AnnotationID&, const LineAnnotation&, const uint8_t);
|
||||
Update update(const AnnotationID&, const FillAnnotation&, const uint8_t);
|
||||
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 remove(const AnnotationID&);
|
||||
|
||||
@@ -67,6 +66,8 @@ private:
|
||||
|
||||
std::mutex mutex;
|
||||
|
||||
bool dirty = false;
|
||||
|
||||
AnnotationID nextID = 0;
|
||||
|
||||
using SymbolAnnotationTree = boost::geometry::index::rtree<std::shared_ptr<const SymbolAnnotationImpl>, boost::geometry::index::rstar<16, 4>>;
|
||||
|
||||
@@ -630,7 +630,9 @@ AnnotationID Map::addAnnotation(const Annotation& annotation) {
|
||||
}
|
||||
|
||||
void Map::updateAnnotation(AnnotationID id, const Annotation& annotation) {
|
||||
impl->onUpdate(impl->annotationManager.updateAnnotation(id, annotation, getMaxZoom()));
|
||||
if (impl->annotationManager.updateAnnotation(id, annotation, getMaxZoom())) {
|
||||
impl->onUpdate(Update::AnnotationData);
|
||||
}
|
||||
}
|
||||
|
||||
void Map::removeAnnotation(AnnotationID annotation) {
|
||||
|
||||
Reference in New Issue
Block a user