diff --git a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/AnnotationManager.java b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/AnnotationManager.java index 94b31b8da..456919b32 100644 --- a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/AnnotationManager.java +++ b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/AnnotationManager.java @@ -131,7 +131,7 @@ public T create(S options) { T t = options.build(currentId, this); annotations.put(t.getId(), t); currentId++; - updateSource(); + internalUpdateSource(); return t; } @@ -150,7 +150,7 @@ public List create(List optionsList) { annotations.put(annotation.getId(), annotation); currentId++; } - updateSource(); + internalUpdateSource(); return annotationList; } @@ -162,7 +162,8 @@ public List create(List optionsList) { @UiThread public void delete(T annotation) { annotations.remove(annotation.getId()); - updateSource(); + draggableAnnotationController.onAnnotationUpdated(annotation); + internalUpdateSource(); } /** @@ -174,8 +175,9 @@ public void delete(T annotation) { public void delete(List annotationList) { for (T annotation : annotationList) { annotations.remove(annotation.getId()); + draggableAnnotationController.onAnnotationUpdated(annotation); } - updateSource(); + internalUpdateSource(); } /** @@ -196,7 +198,8 @@ public void deleteAll() { public void update(T annotation) { if (annotations.containsValue(annotation)) { annotations.put(annotation.getId(), annotation); - updateSource(); + draggableAnnotationController.onAnnotationUpdated(annotation); + internalUpdateSource(); } else { Logger.e(TAG, "Can't update annotation: " + annotation.toString() @@ -213,12 +216,13 @@ public void update(T annotation) { public void update(List annotationList) { for (T annotation : annotationList) { annotations.put(annotation.getId(), annotation); + draggableAnnotationController.onAnnotationUpdated(annotation); } - updateSource(); + internalUpdateSource(); } /** - * Trigger an update to the underlying source + * Trigger an update to the underlying source. Invalidates active drags. */ public void updateSource() { draggableAnnotationController.onSourceUpdated(); diff --git a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/DraggableAnnotationController.java b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/DraggableAnnotationController.java index b9be243d5..516c54277 100644 --- a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/DraggableAnnotationController.java +++ b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/DraggableAnnotationController.java @@ -97,6 +97,12 @@ void removeAnnotationManager(AnnotationManager annotationManager) { } } + void onAnnotationUpdated(Annotation annotation) { + if (annotation == draggedAnnotation) { + stopDragging(draggedAnnotation, draggedAnnotationManager); + } + } + void onSourceUpdated() { stopDragging(draggedAnnotation, draggedAnnotationManager); }