summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2015-12-11 08:18:57 -0800
committerMinh Nguyễn <mxn@1ec5.org>2015-12-13 16:37:30 -0800
commitb59f087ea8bd451d7e822bb27d3612974fa5ac77 (patch)
tree601ac07c9dbdf50c4679b15b3e5ee2405d7a832b
parentd3275aa43c5317300d3f3aba8e83e37a93df55a0 (diff)
downloadqtlocation-mapboxgl-b59f087ea8bd451d7e822bb27d3612974fa5ac77.tar.gz
[ios] Sort candidate annotations by proximity to tap
If you tap near a tight cluster of annotations, the annotation directly beneath your finger should be selected first. Previously, the annotations within the query bounds would be selected in order from oldest to newest, which was counterintuitive. The new behavior does sometimes make it more difficult to cycle through the entire cluster, but the previous behavior often got in the way anyways, as your finger would wind up atop a callout view for an annotation farther south. Also updated the changelog.
-rw-r--r--CHANGELOG.md2
-rw-r--r--platform/ios/MGLMapView.mm17
2 files changed, 15 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f912bd0091..64794924a6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -24,6 +24,8 @@ Known issues:
## iOS master
- `MGLMapView` methods that alter the viewport now accept optional completion handlers. ([#3090](https://github.com/mapbox/mapbox-gl-native/pull/3090))
+- Tapping now selects annotations more reliably. Tapping near the top of a large annotation image now selects that annotation. An annotation image’s alignment insets influence how far away the user can tap and still select the annotation. For example, if your annotation image has a large shadow, you can keep that shadow from being tappable by excluding it from the image’s alignment rect. ([#3261](https://github.com/mapbox/mapbox-gl-native/pull/3261))
+- The user dot’s callout view is now centered above the user dot. It was previously offset slightly to the left. ([#3261](https://github.com/mapbox/mapbox-gl-native/pull/3261))
## iOS 3.0.1
diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm
index 560e5249d5..092750cc16 100644
--- a/platform/ios/MGLMapView.mm
+++ b/platform/ios/MGLMapView.mm
@@ -2370,10 +2370,6 @@ std::chrono::steady_clock::duration durationInSeconds(float duration)
return self.annotationImagesByIdentifier[identifier];
}
-CLLocationDistance MGLDistanceBetweenCoordinate2Ds(CLLocationCoordinate2D a, CLLocationCoordinate2D b) {
- return hypot(b.latitude - a.latitude, b.longitude - a.longitude);
-}
-
/**
Returns the tag of the annotation at the given point in the view.
@@ -2435,6 +2431,19 @@ CLLocationDistance MGLDistanceBetweenCoordinate2Ds(CLLocationCoordinate2D a, CLL
if (nearbyAnnotations == _annotationsNearbyLastTap)
{
+ // The first selection in the cycle should be the one nearest to the
+ // tap.
+ CLLocationCoordinate2D currentCoordinate = [self convertPoint:point toCoordinateFromView:self];
+ std::sort(nearbyAnnotations.begin(), nearbyAnnotations.end(), [&](const MGLAnnotationTag tagA, const MGLAnnotationTag tagB) {
+ CLLocationCoordinate2D coordinateA = [[self annotationWithTag:tagA] coordinate];
+ CLLocationCoordinate2D coordinateB = [[self annotationWithTag:tagB] coordinate];
+ CLLocationDegrees deltaA = hypot(coordinateA.latitude - currentCoordinate.latitude,
+ coordinateA.longitude - currentCoordinate.longitude);
+ CLLocationDegrees deltaB = hypot(coordinateB.latitude - currentCoordinate.latitude,
+ coordinateB.longitude - currentCoordinate.longitude);
+ return deltaA < deltaB;
+ });
+
// The last time we persisted a set of annotations, we had the same
// set of annotations as we do now. Cycle through them.
if (_selectedAnnotationTag == MGLAnnotationTagNotFound