summaryrefslogtreecommitdiff
path: root/src/mbgl/annotation/annotation_manager.cpp
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-06-16 17:31:52 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-06-17 11:38:04 -0700
commit2921127bdbe6cb7583c097675fe67416c8dff38e (patch)
treefc1243f56ab93eabaddfb3a979ddee31ebffc4a7 /src/mbgl/annotation/annotation_manager.cpp
parente2f52a1dd8020e8665c55650c75d4e5a5e1423a6 (diff)
downloadqtlocation-mapboxgl-2921127bdbe6cb7583c097675fe67416c8dff38e.tar.gz
[core] Avoid unnecessary work when a symbol annotation is updated
In particular, if only the geometry changes, don't cascade and recalculate the style.
Diffstat (limited to 'src/mbgl/annotation/annotation_manager.cpp')
-rw-r--r--src/mbgl/annotation/annotation_manager.cpp56
1 files changed, 52 insertions, 4 deletions
diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp
index e3c6cc56d4..dd2467e34f 100644
--- a/src/mbgl/annotation/annotation_manager.cpp
+++ b/src/mbgl/annotation/annotation_manager.cpp
@@ -31,10 +31,9 @@ AnnotationID AnnotationManager::addAnnotation(const Annotation& annotation, cons
return id;
}
-void AnnotationManager::updateAnnotation(const AnnotationID& id, const Annotation& annotation, const uint8_t maxZoom) {
- removeAnnotation(id);
- Annotation::visit(annotation, [&] (const auto& annotation_) {
- this->add(id, annotation_, maxZoom);
+Update AnnotationManager::updateAnnotation(const AnnotationID& id, const Annotation& annotation, const uint8_t maxZoom) {
+ return Annotation::visit(annotation, [&] (const auto& annotation_) {
+ return this->update(id, annotation_, maxZoom);
});
}
@@ -69,6 +68,53 @@ void AnnotationManager::add(const AnnotationID& id, const StyleSourcedAnnotation
std::make_unique<StyleSourcedAnnotationImpl>(id, annotation, maxZoom));
}
+Update AnnotationManager::update(const AnnotationID& id, const SymbolAnnotation& annotation, const uint8_t maxZoom) {
+ auto it = symbolAnnotations.find(id);
+ if (it == symbolAnnotations.end()) {
+ removeAndAdd(id, annotation, maxZoom);
+ return Update::AnnotationData | Update::AnnotationStyle;
+ }
+
+ Update result = Update::Nothing;
+ const SymbolAnnotation& existing = it->second->annotation;
+
+ if (existing.geometry != annotation.geometry) {
+ result |= Update::AnnotationData;
+ }
+
+ if (existing.icon != annotation.icon) {
+ result |= Update::AnnotationData | Update::AnnotationStyle;
+ }
+
+ if (result != Update::Nothing) {
+ removeAndAdd(id, annotation, maxZoom);
+ }
+
+ return result;
+}
+
+Update AnnotationManager::update(const AnnotationID& id, const LineAnnotation& annotation, const uint8_t maxZoom) {
+ removeAndAdd(id, annotation, maxZoom);
+ return Update::AnnotationData | Update::AnnotationStyle;
+}
+
+Update AnnotationManager::update(const AnnotationID& id, const FillAnnotation& annotation, const uint8_t maxZoom) {
+ removeAndAdd(id, annotation, maxZoom);
+ return Update::AnnotationData | Update::AnnotationStyle;
+}
+
+Update AnnotationManager::update(const AnnotationID& id, const StyleSourcedAnnotation& annotation, const uint8_t maxZoom) {
+ removeAndAdd(id, annotation, maxZoom);
+ return Update::AnnotationData | Update::AnnotationStyle;
+}
+
+void AnnotationManager::removeAndAdd(const AnnotationID& id, const Annotation& annotation, const uint8_t maxZoom) {
+ removeAnnotation(id);
+ Annotation::visit(annotation, [&] (const auto& annotation_) {
+ this->add(id, annotation_, maxZoom);
+ });
+}
+
AnnotationIDs AnnotationManager::getPointAnnotationsInBounds(const LatLngBounds& bounds) const {
AnnotationIDs result;
@@ -133,7 +179,9 @@ void AnnotationManager::updateStyle(Style& style) {
}
obsoleteShapeAnnotationLayers.clear();
+}
+void AnnotationManager::updateData() {
for (auto& tile : tiles) {
tile->setData(getTileData(tile->id.canonical));
}