-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Update annotations and annotation images dynamically #3835
Conversation
@@ -169,6 +169,7 @@ - (void)showSettings | |||
@"Add Test Shapes", | |||
@"Start World Tour", | |||
@"Add Custom Callout Point", | |||
@"Reset Annotation Images", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not seeing a new handler for this action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I didn’t end up needing that action. I’ll remove it.
Implementing the annotation replacement in mbgl, as in #3885, would probably be more efficient. |
Moving to 3.3.0 milestone in light of #4556. |
e0199a7
to
b69e525
Compare
I added support for atomically relocating an annotation without having to replace the annotation outright. The PR description has been updated. |
MGLAnnotationContext context; | ||
context.annotation = annotations[i]; | ||
context.symbolIdentifier = @(points[i].icon.c_str()); | ||
context.imageReuseIdentifier = annotationImage.reuseIdentifier; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! I made a similar refactor on my annotation branch. This is better and includes the new and better property name on MGLAnnotationContext
👍 this looks great! I will base the change I'm about to make for a custom view off of this branch until it lands in master. |
Added an API for deleting unused annotation images’ images. When you nil out the image of an MGLAnnotationImage, MGLMapView deletes the sprite from the style and recreates any annotation associated with the MGLAnnotationImage instance; the MGLAnnotationImage’s falls back to SDK’s default annotation image. In iosapp, deselecting an annotation resets its image to the default; deselecting it again restores the image. ref #3185
When refreshing an annotation’s image, update the annotation instead of replacing it outright.
MGLMapView observes changes to the coordinate property of each MGLAnnotation added to it. Changing the coordinate property in a KVO-compliant way causes the annotation to be relocated and its callout view, if present, to be dismissed. To avoid observing the same annotation twice yet also avoid expensive lookups when adding or removing annotations, MGLMapView indexes added point annotations in an NSMutableSet. In iosapp, tapping a callout view moves the selected annotation to the center of the screen and deselects it. Fixes #1980.
MGLMapView observes changes to the coordinate property of each MGLAnnotation added to it. Changing the coordinate property in a KVO-compliant way causes the annotation to be relocated and its callout view, if present, to be dismissed. To avoid observing the same annotation twice yet also avoid expensive lookups when adding or removing annotations, MGLMapView indexes added point annotations in an NSMutableSet.
7401aab
to
f8c52d5
Compare
Hi, Removing MGLPolyline object from MGLMapView causes app crash.
Exception detail: 2016-04-20 18:11:23.932 MapboxTest[364:56042] *** Terminating app due to uncaught exception 'NSRangeException', reason: 'Cannot remove an observer <MGLMapView 0x15ee754d0> for the key path "coordinate" from <MGLPolyline 0x15ee602a0> because it is not registered as an observer.' |
Here’s what this PR implemented originally:
We should have something to exercise both pieces of functionality, but feel free to find a better way to exercise them. |
MGLMapView observes changes to the
coordinate
property of each MGLAnnotation added to it. Changing thecoordinate
property in a KVO-compliant way causes the annotation to be relocated and its callout view, if present, to be dismissed. To avoid observing the same annotation twice yet also avoid expensive lookups when adding or removing annotations, MGLMapView indexes added point annotations in an NSMutableSet.Added the ability to delete an unused annotation image’s images on iOS. (The OS X SDK doesn’t yet support changing an annotation image’s image.) When you nil out the image of an MGLAnnotationImage, MGLMapView deletes the sprite from the style and resets any annotation associated with the MGLAnnotationImage instance to use the default red pin icon under the hood. The annotation remains associated with the MGLAnnotationImage, which comes in handy in the event that the annotation image’s image becomes non-nil.
In iosapp, tapping a callout view moves the selected annotation to the center of the screen and deselects it. Deselecting an annotation resets its image to the default; deselecting it again restores the image.
Fixes #1980.
/ref #3185
/cc @boundsj @friedbunny