summaryrefslogtreecommitdiff
path: root/platform/osx
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-04-20 08:43:05 -0700
committerMinh Nguyễn <mxn@1ec5.org>2016-04-20 14:23:57 -0700
commit72086edb6e95905bd85ab1e0b485fec16379735b (patch)
tree8a4901a9e6a29ad6a2b43571abdf1cd57c9dc361 /platform/osx
parent268884368a15cae285c1ffd2654b1e25a25ded7f (diff)
downloadqtlocation-mapboxgl-72086edb6e95905bd85ab1e0b485fec16379735b.tar.gz
[ios, osx] Avoid observing coordinate on MGLMultiPoint
There’s no point observing the coordinate key path on MGLMultiPoint, since that property is immutable. Use the observation context instead of performing an annotation tag lookup when a coordinate has changed.
Diffstat (limited to 'platform/osx')
-rw-r--r--platform/osx/src/MGLMapView.mm27
1 files changed, 12 insertions, 15 deletions
diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm
index 8be4772c3a..69bc5c87b1 100644
--- a/platform/osx/src/MGLMapView.mm
+++ b/platform/osx/src/MGLMapView.mm
@@ -460,21 +460,20 @@ public:
}
}
-- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(__unused id)object change:(__unused NSDictionary *)change context:(__unused void *)context {
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(__unused NSDictionary *)change context:(void *)context {
if ([keyPath isEqualToString:@"contentLayoutRect"] ||
[keyPath isEqualToString:@"titlebarAppearsTransparent"]) {
[self adjustContentInsets];
} else if ([keyPath isEqualToString:@"coordinate"] &&
- [object conformsToProtocol:@protocol(MGLAnnotation)]) {
+ [object conformsToProtocol:@protocol(MGLAnnotation)] &&
+ ![object isKindOfClass:[MGLMultiPoint class]]) {
id <MGLAnnotation> annotation = object;
- MGLAnnotationTag annotationTag = [self annotationTagForAnnotation:annotation];
- if (annotationTag != MGLAnnotationTagNotFound) {
- const mbgl::LatLng latLng = MGLLatLngFromLocationCoordinate2D(annotation.coordinate);
- MGLAnnotationImage *annotationImage = [self imageOfAnnotationWithTag:annotationTag];
- _mbglMap->updatePointAnnotation(annotationTag, { latLng, annotationImage.styleIconIdentifier.UTF8String ?: "" });
- if (annotationTag == _selectedAnnotationTag) {
- [self deselectAnnotation:annotation];
- }
+ MGLAnnotationTag annotationTag = (MGLAnnotationTag)(NSUInteger)context;
+ const mbgl::LatLng latLng = MGLLatLngFromLocationCoordinate2D(annotation.coordinate);
+ MGLAnnotationImage *annotationImage = [self imageOfAnnotationWithTag:annotationTag];
+ _mbglMap->updatePointAnnotation(annotationTag, { latLng, annotationImage.styleIconIdentifier.UTF8String ?: "" });
+ if (annotationTag == _selectedAnnotationTag) {
+ [self deselectAnnotation:annotation];
}
}
}
@@ -1608,6 +1607,7 @@ public:
_annotationContextsByAnnotationTag[annotationTag] = context;
if ([annotation isKindOfClass:[NSObject class]]) {
+ NSAssert(![annotation isKindOfClass:[MGLMultiPoint class]], @"Point annotation should not be MGLMultiPoint.");
[(NSObject *)annotation addObserver:self forKeyPath:@"coordinate" options:0 context:(void *)(NSUInteger)annotationTag];
}
}
@@ -1624,10 +1624,6 @@ public:
MGLAnnotationContext context;
context.annotation = annotation;
_annotationContextsByAnnotationTag[annotationTag] = context;
-
- if ([annotation isKindOfClass:[NSObject class]]) {
- [(NSObject *)annotation addObserver:self forKeyPath:@"coordinate" options:0 context:(void *)(NSUInteger)annotationTag];
- }
}
}
@@ -1720,7 +1716,8 @@ public:
_annotationContextsByAnnotationTag.erase(annotationTag);
- if ([annotation isKindOfClass:[NSObject class]]) {
+ if ([annotation isKindOfClass:[NSObject class]] &&
+ ![annotation isKindOfClass:[MGLMultiPoint class]]) {
[(NSObject *)annotation removeObserver:self forKeyPath:@"coordinate" context:(void *)(NSUInteger)annotationTag];
}
}