From d742c2d3eb3b8f669f0df9c6e5f6596eaf8fb616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Mikl=C3=B3s?= Date: Tue, 9 Feb 2016 16:09:01 +0100 Subject: [PATCH] [core] Add support for updating point annotations --- include/mbgl/map/map.hpp | 2 ++ src/mbgl/annotation/annotation_manager.cpp | 10 ++++++++++ src/mbgl/annotation/annotation_manager.hpp | 1 + src/mbgl/map/map.cpp | 5 +++++ 4 files changed, 18 insertions(+) diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 3a8503016..8c27b1756 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -161,6 +161,8 @@ public: AnnotationID addShapeAnnotation(const ShapeAnnotation&); AnnotationIDs addShapeAnnotations(const std::vector&); + void updatePointAnnotation(AnnotationID, const PointAnnotation&); + void removeAnnotation(AnnotationID); void removeAnnotations(const AnnotationIDs&); diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp index 52f8b08ad..5f5feb456 100644 --- a/src/mbgl/annotation/annotation_manager.cpp +++ b/src/mbgl/annotation/annotation_manager.cpp @@ -48,6 +48,16 @@ AnnotationManager::addShapeAnnotations(const std::vector& shape return annotationIDs; } +void AnnotationManager::updatePointAnnotation(const AnnotationID& id, const PointAnnotation& point, const uint8_t) { + auto foundAnnotation = pointAnnotations.find(id); + if (foundAnnotation != pointAnnotations.end()) { + auto updatedAnnotation = std::make_shared(id, point); + pointTree.remove(foundAnnotation->second); + pointTree.insert(updatedAnnotation); + foundAnnotation->second = updatedAnnotation; + } +} + void AnnotationManager::removeAnnotations(const AnnotationIDs& ids) { for (const auto& id : ids) { if (pointAnnotations.find(id) != pointAnnotations.end()) { diff --git a/src/mbgl/annotation/annotation_manager.hpp b/src/mbgl/annotation/annotation_manager.hpp index 163c7129c..11860047c 100644 --- a/src/mbgl/annotation/annotation_manager.hpp +++ b/src/mbgl/annotation/annotation_manager.hpp @@ -28,6 +28,7 @@ public: AnnotationIDs addPointAnnotations(const std::vector&, const uint8_t maxZoom); AnnotationIDs addShapeAnnotations(const std::vector&, const uint8_t maxZoom); + void updatePointAnnotation(const AnnotationID&, const PointAnnotation&, const uint8_t maxZoom); void removeAnnotations(const AnnotationIDs&); AnnotationIDs getPointAnnotationsInBounds(const LatLngBounds&) const; diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 2df86a8f1..cfbdbafb6 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -452,6 +452,11 @@ AnnotationIDs Map::addShapeAnnotations(const std::vector& annot return result; } +void Map::updatePointAnnotation(AnnotationID annotationId, const PointAnnotation& annotation) { + data->getAnnotationManager()->updatePointAnnotation(annotationId, annotation, getMaxZoom()); + update(Update::Annotations); +} + void Map::removeAnnotation(AnnotationID annotation) { removeAnnotations({ annotation }); }