diff options
author | Tobrun <tobrun@mapbox.com> | 2016-01-19 10:25:05 +0100 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2016-01-19 12:59:57 +0100 |
commit | 6b3745c68dcfe98d746d478539b035ea8699f736 (patch) | |
tree | acef802252bb1f00a4feac19c9421afb59e2d48c /platform | |
parent | 5ff95d45240cc340d22c37bb13e4289b4eab40b7 (diff) | |
download | qtlocation-mapboxgl-6b3745c68dcfe98d746d478539b035ea8699f736.tar.gz |
[android] #3156 - improving marker selection touch handling
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java | 60 |
1 files changed, 17 insertions, 43 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java index fdfc3faafb..8db7fbf77c 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/views/MapView.java @@ -3186,9 +3186,9 @@ public final class MapView extends FrameLayout { // Open / Close InfoWindow PointF tapPoint = new PointF(e.getX(), e.getY()); - final float toleranceSides = 30 * mScreenDensity; - final float toleranceTop = 40 * mScreenDensity; - final float toleranceBottom = 10 * mScreenDensity; + final float toleranceSides = 15 * mScreenDensity; + final float toleranceTop = 20 * mScreenDensity; + final float toleranceBottom = 5 * mScreenDensity; RectF tapRect = new RectF(tapPoint.x - toleranceSides, tapPoint.y + toleranceTop, tapPoint.x + toleranceSides, tapPoint.y - toleranceBottom); @@ -3201,52 +3201,27 @@ public final class MapView extends FrameLayout { ); BoundingBox tapBounds = BoundingBox.fromLatLngs(corners); - List<Marker> nearbyMarkers = getMarkersInBounds(tapBounds); + long newSelectedMarkerId = -1; - long newSelectedMarkerId; - - if (nearbyMarkers.size() > 0) { - - // there is at least one nearby marker; select one - // - // first, sort for comparison and iteration + if (nearbyMarkers!=null && nearbyMarkers.size() > 0) { Collections.sort(nearbyMarkers); - - if (nearbyMarkers == mMarkersNearLastTap) { - - // TODO: We still need to adapt this logic to the new mSelectedMarkers list, - // though the basic functionality is there. - - // the selection candidates haven't changed; cycle through them -// if (mSelectedMarker != null -// && (mSelectedMarker.getId() == mMarkersNearLastTap.get(mMarkersNearLastTap.size() - 1).getId())) { -// // the selected marker is the last in the set; cycle back to the first -// // note: this could be the selected marker if only one in set -// newSelectedMarkerId = mMarkersNearLastTap.get(0).getId(); -// } else if (mSelectedMarker != null) { -// // otherwise increment the selection through the candidates -// long result = mMarkersNearLastTap.indexOf(mSelectedMarker); -// newSelectedMarkerId = mMarkersNearLastTap.get((int) result + 1).getId(); -// } else { - // no current selection; select the first one - newSelectedMarkerId = mMarkersNearLastTap.get(0).getId(); -// } - } else { - // start tracking a new set of nearby markers - mMarkersNearLastTap = nearbyMarkers; - - // select the first one - newSelectedMarkerId = mMarkersNearLastTap.get(0).getId(); + for (Marker nearbyMarker : nearbyMarkers) { + boolean found = false; + for (Marker selectedMarker : mSelectedMarkers) { + if(selectedMarker.equals(nearbyMarker)){ + found = true; + } + } + if(!found){ + newSelectedMarkerId = nearbyMarker.getId(); + break; + } } - - } else { - // there are no nearby markers; deselect if necessary - newSelectedMarkerId = -1; + mMarkersNearLastTap = nearbyMarkers; } if (newSelectedMarkerId >= 0) { - int count = mAnnotations.size(); for (int i = 0; i < count; i++) { Annotation annotation = mAnnotations.get(i); @@ -3259,7 +3234,6 @@ public final class MapView extends FrameLayout { } } } - } else { // deselect any selected marker deselectMarkers(); |