summaryrefslogtreecommitdiff
path: root/platform/ios/src/MGLMapView.mm
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-02-10 09:34:19 -0800
committerMinh Nguyễn <mxn@1ec5.org>2016-02-10 09:38:04 -0800
commit71611ec61247593aa6e9b568595114647363532d (patch)
treef63a29eb41d06a5d4aec8a86a4d3350a05f78afb /platform/ios/src/MGLMapView.mm
parent2080d1976456bb4e70d657558eab0e4aa7a03605 (diff)
downloadqtlocation-mapboxgl-71611ec61247593aa6e9b568595114647363532d.tar.gz
[ios, osx] Fixed crash reselecting annotation
Handle the case where the currently selected annotation isn’t one of the nearby annotations. This hasn’t come up before on OS X because clicking an annotation while another annotation is selected only dismisses the callout popover. Fixes #3284.
Diffstat (limited to 'platform/ios/src/MGLMapView.mm')
-rw-r--r--platform/ios/src/MGLMapView.mm21
1 files changed, 15 insertions, 6 deletions
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 2040c40da5..bb71a4c63a 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -2698,19 +2698,28 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
if (_selectedAnnotationTag == MGLAnnotationTagNotFound
|| _selectedAnnotationTag == _annotationsNearbyLastTap.back())
{
- // Either an annotation from this set hasn’t been selected
- // before or the last annotation in the set was selected. Wrap
- // around to the first annotation in the set.
+ // Either no annotation is selected or the last annotation in
+ // the set was selected. Wrap around to the first annotation in
+ // the set.
hitAnnotationTag = _annotationsNearbyLastTap.front();
}
else
{
- // Step to the next annotation in the set.
auto result = std::find(_annotationsNearbyLastTap.begin(),
_annotationsNearbyLastTap.end(),
_selectedAnnotationTag);
- auto distance = std::distance(_annotationsNearbyLastTap.begin(), result);
- hitAnnotationTag = _annotationsNearbyLastTap[distance + 1];
+ if (result == _annotationsNearbyLastTap.end())
+ {
+ // An annotation from this set hasn’t been selected before.
+ // Select the first (nearest) one.
+ hitAnnotationTag = _annotationsNearbyLastTap.front();
+ }
+ else
+ {
+ // Step to the next annotation in the set.
+ auto distance = std::distance(_annotationsNearbyLastTap.begin(), result);
+ hitAnnotationTag = _annotationsNearbyLastTap[distance + 1];
+ }
}
}
else