summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2017-08-31 15:24:09 +0300
committerIvo van Dongen <ivovandongen@users.noreply.github.com>2017-08-31 18:45:28 +0300
commit377faaf4f8a5db1f7b31eedaf92d0865cda37db9 (patch)
tree75a2aca3372f8967aaa8d5e1d80072203e77017a /src
parent0694d224c745ea5ee5eb1fc46cbb0b9487e6333a (diff)
downloadqtlocation-mapboxgl-377faaf4f8a5db1f7b31eedaf92d0865cda37db9.tar.gz
[core] annotation manager - manage dirty state internally
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/annotation/annotation_manager.cpp38
-rw-r--r--src/mbgl/annotation/annotation_manager.hpp11
-rw-r--r--src/mbgl/map/map.cpp4
3 files changed, 29 insertions, 24 deletions
diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp
index dbf8387ae0..1f2d01e9eb 100644
--- a/src/mbgl/annotation/annotation_manager.cpp
+++ b/src/mbgl/annotation/annotation_manager.cpp
@@ -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;
}
}
diff --git a/src/mbgl/annotation/annotation_manager.hpp b/src/mbgl/annotation/annotation_manager.hpp
index dee823bc0f..a028a8f1ba 100644
--- a/src/mbgl/annotation/annotation_manager.hpp
+++ b/src/mbgl/annotation/annotation_manager.hpp
@@ -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>>;
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index e255c5d0ae..8aacce6287 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -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) {