summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobrun Van Nuland <tobrun.van.nuland@gmail.com>2017-07-24 10:45:35 +0200
committerTobrun <tobrun@mapbox.com>2017-07-24 13:51:40 +0200
commit3364992be94364a6e8b302124db53aeed5d99c15 (patch)
tree688182db41ca4c92d25b79043c105bdfc539946a
parente8ad7b6a49d12a1f414e0242007a671c4514d85a (diff)
downloadqtlocation-mapboxgl-3364992be94364a6e8b302124db53aeed5d99c15.tar.gz
[android] - harden click handling of shape annotations
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java24
1 files changed, 20 insertions, 4 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java
index 73e90206f8..22e5cf4322 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java
@@ -26,6 +26,8 @@ import com.mapbox.services.commons.geojson.Feature;
import java.util.ArrayList;
import java.util.List;
+import timber.log.Timber;
+
/**
* Responsible for managing and tracking state of Annotations linked to Map. All events related to
* annotations that occur on {@link MapboxMap} are forwarded to this class.
@@ -40,6 +42,7 @@ import java.util.List;
class AnnotationManager {
private static final String LAYER_ID_SHAPE_ANNOTATIONS = "com.mapbox.annotations.shape.";
+ private static final long NO_ANNOTATION_ID = -1;
private final MapView mapView;
private final IconManager iconManager;
@@ -369,13 +372,13 @@ class AnnotationManager {
boolean onTap(PointF tapPoint) {
ShapeAnnotationHit shapeAnnotationHit = getShapeAnnotationHitFromTap(tapPoint);
long shapeAnnotationId = new ShapeAnnotationHitResolver(mapboxMap).execute(shapeAnnotationHit);
- if (shapeAnnotationId >= 0) {
+ if (shapeAnnotationId != NO_ANNOTATION_ID) {
handleClickForShapeAnnotation(shapeAnnotationId);
}
MarkerHit markerHit = getMarkerHitFromTouchArea(tapPoint);
long markerId = new MarkerHitResolver(mapboxMap).execute(markerHit);
- return markerId >= 0 && isClickHandledForMarker(markerId);
+ return markerId != NO_ANNOTATION_ID && isClickHandledForMarker(markerId);
}
private ShapeAnnotationHit getShapeAnnotationHitFromTap(PointF tapPoint) {
@@ -445,8 +448,21 @@ class AnnotationManager {
}
public long execute(ShapeAnnotationHit shapeHit) {
+ long foundAnnotationId = NO_ANNOTATION_ID;
List<Feature> features = mapboxMap.queryRenderedFeatures(shapeHit.tapPoint, shapeHit.layerIds);
- return features.isEmpty() ? -1 : Long.valueOf(features.get(0).getId());
+ if (!features.isEmpty()) {
+ foundAnnotationId = getIdFromFeature(features.get(0));
+ }
+ return foundAnnotationId;
+ }
+
+ private long getIdFromFeature(Feature feature) {
+ try {
+ return Long.valueOf(feature.getId());
+ } catch (NumberFormatException exception) {
+ Timber.e(exception, "Couldn't parse feature id to a long, with id: %s", feature.getId());
+ return NO_ANNOTATION_ID;
+ }
}
}
@@ -463,7 +479,7 @@ class AnnotationManager {
private RectF hitRectMarker = new RectF();
private RectF highestSurfaceIntersection = new RectF();
- private long closestMarkerId = -1;
+ private long closestMarkerId = NO_ANNOTATION_ID;
MarkerHitResolver(@NonNull MapboxMap mapboxMap) {
this.markerViewManager = mapboxMap.getMarkerViewManager();