Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
macos support for polyline/polygon coordinates mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
incanus committed Oct 4, 2016
1 parent e7888e1 commit 0349363
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions platform/macos/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,25 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(_
[self deselectAnnotation:annotation];
}
}
} else if ([keyPath isEqualToString:@"coordinates"] &&
[object isKindOfClass:[MGLMultiPoint class]]) {
MGLMultiPoint *annotation = object;
MGLAnnotationTag annotationTag = (MGLAnnotationTag)(NSUInteger)context;
// We can get here because a subclass registered itself as an observer
// of the coordinates key path of a multipoint annotation but failed
// to handle the change. This check deters us from treating the
// subclass’s context as an annotation tag. If the context happens to
// match a valid annotation tag, the annotation will be unnecessarily
// but safely updated.
if (annotation == [self annotationWithTag:annotationTag]) {
_mbglMap->updateAnnotation(annotationTag, [annotation annotationObjectWithDelegate:self]);
// We don't current support shape multipoint annotation selection, but let's make sure
// deselection is handled just to avoid problems in the future.
if (annotationTag == _selectedAnnotationTag)
{
[self deselectAnnotation:annotation];
}
}
}
}

Expand Down Expand Up @@ -1625,6 +1644,8 @@ - (void)addAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations {
MGLAnnotationContext context;
context.annotation = annotation;
_annotationContextsByAnnotationTag[annotationTag] = context;

[(NSObject *)annotation addObserver:self forKeyPath:@"coordinates" options:0 context:(void *)(NSUInteger)annotationTag];
} else if (![annotation isKindOfClass:[MGLMultiPolyline class]]
|| ![annotation isKindOfClass:[MGLMultiPolygon class]]
|| ![annotation isKindOfClass:[MGLShapeCollection class]]) {
Expand Down Expand Up @@ -1762,6 +1783,8 @@ - (void)removeAnnotations:(NS_ARRAY_OF(id <MGLAnnotation>) *)annotations {
if ([annotation isKindOfClass:[NSObject class]] &&
![annotation isKindOfClass:[MGLMultiPoint class]]) {
[(NSObject *)annotation removeObserver:self forKeyPath:@"coordinate" context:(void *)(NSUInteger)annotationTag];
} else if ([annotation isKindOfClass:[MGLMultiPoint class]]) {
[(NSObject *)annotation removeObserver:self forKeyPath:@"coordinates" context:(void *)(NSUInteger)annotationTag];
}

_mbglMap->removeAnnotation(annotationTag);
Expand Down

0 comments on commit 0349363

Please sign in to comment.