diff options
author | Justin R. Miller <incanus@users.noreply.github.com> | 2016-10-04 18:42:12 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-04 18:42:12 -0700 |
commit | 105673efc1c59e19f5352fb770405aa591cdebeb (patch) | |
tree | 7b57c89ad346a4e62c60c404338d0b34853ad02b /platform/ios | |
parent | 07315711d6b191a5812065bb76ab5beb33d995d9 (diff) | |
download | qtlocation-mapboxgl-105673efc1c59e19f5352fb770405aa591cdebeb.tar.gz |
[ios, macos] fixes #6160: allow updating multipoint coordinates (#6565)
Diffstat (limited to 'platform/ios')
-rw-r--r-- | platform/ios/CHANGELOG.md | 1 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 29 |
2 files changed, 30 insertions, 0 deletions
diff --git a/platform/ios/CHANGELOG.md b/platform/ios/CHANGELOG.md index 4a445a075a..07f0a3c89d 100644 --- a/platform/ios/CHANGELOG.md +++ b/platform/ios/CHANGELOG.md @@ -40,6 +40,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT ### Annotations +* MGLPolyline annotations and the exterior coordinates of MGLPolygon annotations are now able to be mutated, part or all, and changes are displayed immediately. ([#6565](https://github.com/mapbox/mapbox-gl-native/pull/6565)) * Fixed an issue preventing MGLAnnotationView from animating when its coordinate changes. ([#6215](https://github.com/mapbox/mapbox-gl-native/pull/6215)) * Fixed an issue causing the wrong annotation view to be selected when tapping an annotation view with a center offset applied. ([#5931](https://github.com/mapbox/mapbox-gl-native/pull/5931)) * Fixed an issue that assigned annotation views to polyline and polygon annotations. ([#5770](https://github.com/mapbox/mapbox-gl-native/pull/5770)) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index bc11303ee8..9067efc033 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -1795,6 +1795,29 @@ public: } } } + 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]) + { + // Update the annotation’s backing geometry to match the annotation model object. + _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 animated:YES]; + } + } + } } + (NS_SET_OF(NSString *) *)keyPathsForValuesAffectingZoomEnabled @@ -2840,6 +2863,8 @@ public: 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]] @@ -3132,6 +3157,10 @@ public: { [(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); } |