Skip to content

Commit

Permalink
Fixed annotation dragging behavior (#25)
Browse files Browse the repository at this point in the history
AnnotationManager: fix drag interruption due to unlelated annotation state update
- the drag event of an annotation was stopped when there was a state update
of any annotion. This made it impossible to drag an annotation while updating
anything else on the map.

Signed-off-by: Roman Bapst <bapstroman@gmail.com>
  • Loading branch information
RomanBapst committed May 5, 2023
1 parent f2019fe commit f2eb0f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public T create(S options) {
T t = options.build(currentId, this);
annotations.put(t.getId(), t);
currentId++;
updateSource();
internalUpdateSource();
return t;
}

Expand All @@ -155,7 +155,7 @@ public List<T> create(List<S> optionsList) {
annotations.put(annotation.getId(), annotation);
currentId++;
}
updateSource();
internalUpdateSource();
return annotationList;
}

Expand All @@ -167,7 +167,8 @@ public List<T> create(List<S> optionsList) {
@UiThread
public void delete(T annotation) {
annotations.remove(annotation.getId());
updateSource();
draggableAnnotationController.onAnnotationUpdated(annotation);
internalUpdateSource();
}

/**
Expand All @@ -179,8 +180,9 @@ public void delete(T annotation) {
public void delete(List<T> annotationList) {
for (T annotation : annotationList) {
annotations.remove(annotation.getId());
draggableAnnotationController.onAnnotationUpdated(annotation);
}
updateSource();
internalUpdateSource();
}

/**
Expand All @@ -201,7 +203,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()
Expand All @@ -218,8 +221,9 @@ public void update(T annotation) {
public void update(List<T> annotationList) {
for (T annotation : annotationList) {
annotations.put(annotation.getId(), annotation);
draggableAnnotationController.onAnnotationUpdated(annotation);
}
updateSource();
internalUpdateSource();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ void removeAnnotationManager(AnnotationManager annotationManager) {
}
}

void onAnnotationUpdated(Annotation annotation) {
if (annotation == draggedAnnotation) {
stopDragging(draggedAnnotation, draggedAnnotationManager);
}
}

void onSourceUpdated() {
stopDragging(draggedAnnotation, draggedAnnotationManager);
}
Expand Down

0 comments on commit f2eb0f0

Please sign in to comment.