From 8f98024f37911c2c8b0e04fe37b9c3271bf0b7fd Mon Sep 17 00:00:00 2001 From: Brad Leege Date: Fri, 4 Sep 2015 18:52:08 -0500 Subject: [PATCH] #894 - Flipping the Y value to make screen touch event locations line up with marker. Updating marker selection and deselection logic to allow for proper selection and reselection. --- .../com/mapbox/mapboxgl/views/MapView.java | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java index 0e7c8a929..1a69fdde3 100644 --- a/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java +++ b/android/java/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxgl/views/MapView.java @@ -8,7 +8,10 @@ import android.content.IntentFilter; import android.content.pm.PackageManager; import android.content.res.TypedArray; import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.Color; import android.graphics.Matrix; +import android.graphics.Paint; import android.graphics.PointF; import android.hardware.GeomagneticField; import android.hardware.Sensor; @@ -1033,10 +1036,18 @@ public class MapView extends FrameLayout implements LocationListener { mNativeMapView.cancelTransitions(); // Open / Close InfoWindow - PointF tapPoint = new PointF(e.getX(), e.getY()); + + float x = e.getX(); + float y = e.getY(); + + // flip y direction vertically to match core GL + y = getHeight() - y; + + PointF tapPoint = new PointF(x, y); + LatLng tapLatLng = fromScreenLocation(tapPoint); float toleranceWidth = 60 * mScreenDensity; - float toleranceHeight = 80 * mScreenDensity; + float toleranceHeight = 200 * mScreenDensity; PointF tr = new PointF(tapPoint.x + toleranceWidth / 2, tapPoint.y + 2 * toleranceHeight / 3); PointF bl = new PointF(tapPoint.x - toleranceWidth / 2, tapPoint.y - 1 * toleranceHeight / 3); @@ -1046,6 +1057,8 @@ public class MapView extends FrameLayout implements LocationListener { BoundingBox bbox = new BoundingBox(ne, sw); + addPolyline(new PolylineOptions().add(sw, ne).color(Color.RED).width(5)); + List nearbyAnnotations = getAnnotationsInBounds(bbox); long newSelectedAnnotationID = -1; @@ -1096,11 +1109,13 @@ public class MapView extends FrameLayout implements LocationListener { if (newSelectedAnnotationID >= 0) { for (Annotation annotation : mAnnotations) { - if (annotation.getId() == newSelectedAnnotationID) { - if (annotation.getId() == mSelectedAnnotation.getId()) { - selectAnnotation(annotation); + if (annotation instanceof Marker) { + if (annotation.getId() == newSelectedAnnotationID) { + if (mSelectedAnnotation == null || annotation.getId() != mSelectedAnnotation.getId()) { + selectAnnotation(annotation); + } + break; } - break; } } @@ -1989,6 +2004,7 @@ public class MapView extends FrameLayout implements LocationListener { Marker marker = (Marker) mSelectedAnnotation; if (marker.isInfoWindowShown()) { marker.hideInfoWindow(); + mSelectedAnnotation = null; } } }