Prevent annotation changes from invalidating unrelated drag actions #1159
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Relates to, but does not resolve, #1029
Motivation for change
I have a use case where markers on the map are 'linked' together via lines. As the user drags a marker, it is necessary that the line is programmatically updated as well. Due to the current logic which ensures data integrity, updates to the associated lines invalidate/stop the drag action.
This simple change adds a new method to the
DraggableAnnotationController
which allows theAnnotationManager
to notify the controller of more fine-grain changes to the map source. If the change wasn't to the dragged annotation, the drag will continue.Future work
As stated above, this does not solve 1029, which asks that changes to certain attributes of a dragged annotation don't stop the drag action. For example, a circle should be able to change size while being dragged, as this does not logically interfere with the annotation moving.
Although not included in this PR, a solution to that could be to add a field/method to the
Annotation
class which computes a 'drag integrity hash' which hashes all fields that must remain static during a drag. When a drag starts, theDraggableAnnotationManager
can take note of this hash. When notified of an update, the controller can check the current integrity hash of the annotation, and if it doesn't match the original stop the drag.If that solution is agreeable, I can update this PR to include that.