summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-04-20 10:26:28 -0700
committerMinh Nguyễn <mxn@1ec5.org>2016-04-20 14:23:57 -0700
commit2aaa8b94746d50c89a4430a6787f9c28fb0e8a70 (patch)
treeda23d59bf54989e44591e8172f48b84dd52e7b84 /platform
parent72086edb6e95905bd85ab1e0b485fec16379735b (diff)
downloadqtlocation-mapboxgl-2aaa8b94746d50c89a4430a6787f9c28fb0e8a70.tar.gz
[ios, osx] Ignore invalid observation context
If a subclass of MGLMapView registers itself as an observer of a non-multipoint annotation’s coordinate key path but fails to handle the change in its -observeValueForKeyPath:ofObject:change:context: implementation, the context would likely be a value other than the annotation’s tag. In that case, avoid doing anything in response to the coordinate changing. Even if the context in that case happens to match the annotation’s tag – say, because the developer passed in NULL (which is equal to 0) for the first added annotation (which would have a tag of 0) – the result would be an unnecessary but harmless update.
Diffstat (limited to 'platform')
-rw-r--r--platform/ios/src/MGLMapView.mm19
-rw-r--r--platform/osx/src/MGLMapView.mm18
2 files changed, 27 insertions, 10 deletions
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 1b07c68cf3..9831c379a1 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -1612,12 +1612,21 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
{
id <MGLAnnotation> annotation = object;
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)
+ // We can get here because a subclass registered itself as an observer
+ // of the coordinate key path of a non-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])
{
- [self deselectAnnotation:annotation animated:YES];
+ 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 animated:YES];
+ }
}
}
}
diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm
index 69bc5c87b1..6ef93b70cf 100644
--- a/platform/osx/src/MGLMapView.mm
+++ b/platform/osx/src/MGLMapView.mm
@@ -469,11 +469,19 @@ public:
![object isKindOfClass:[MGLMultiPoint class]]) {
id <MGLAnnotation> annotation = object;
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];
+ // We can get here because a subclass registered itself as an observer
+ // of the coordinate key path of a non-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]) {
+ 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];
+ }
}
}
}