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

Fix crash reselecting annotation #3881

Merged
merged 1 commit into from
Feb 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Known issues:

- Corrected the dynamic framework’s minimum deployment target to iOS 8.0. ([#3872](https://github.com/mapbox/mapbox-gl-native/pull/3872))
- Fixed Fabric compatibility. ([#3847](https://github.com/mapbox/mapbox-gl-native/pull/3847))
- Fixed a crash that can occur when reselecting an annotation. ([#3881](https://github.com/mapbox/mapbox-gl-native/pull/3881))
- Fixed an issue preventing `-[MGLMapViewDelegate mapView:tapOnCalloutForAnnotation:]` from being called when a non-custom callout view is tapped. ([#3875](https://github.com/mapbox/mapbox-gl-native/pull/3875))

## iOS 3.1.0
Expand Down
21 changes: 15 additions & 6 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2698,19 +2698,28 @@ - (MGLAnnotationTag)annotationTagAtPoint:(CGPoint)point persistingResults:(BOOL)
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
Expand Down
18 changes: 12 additions & 6 deletions platform/osx/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1757,17 +1757,23 @@ - (MGLAnnotationTag)annotationTagAtPoint:(NSPoint)point persistingResults:(BOOL)
// set of annotations as we do now. Cycle through them.
if (_lastSelectedAnnotationTag == MGLAnnotationTagNotFound
|| _lastSelectedAnnotationTag == _annotationsNearbyLastClick.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 = _annotationsNearbyLastClick.front();
} else {
// Step to the next annotation in the set.
auto result = std::find(_annotationsNearbyLastClick.begin(),
_annotationsNearbyLastClick.end(),
_lastSelectedAnnotationTag);
auto distance = std::distance(_annotationsNearbyLastClick.begin(), result);
hitAnnotationTag = _annotationsNearbyLastClick[distance + 1];
if (result == _annotationsNearbyLastClick.end()) {
// An annotation from this set hasn’t been selected before.
// Select the first (nearest) one.
hitAnnotationTag = _annotationsNearbyLastClick.front();
} else {
// Step to the next annotation in the set.
auto distance = std::distance(_annotationsNearbyLastClick.begin(), result);
hitAnnotationTag = _annotationsNearbyLastClick[distance + 1];
}
}
} else {
// Remember the nearby annotations for the next time this method is
Expand Down