diff options
author | Tobrun Van Nuland <tobrun.van.nuland@gmail.com> | 2017-07-24 10:45:35 +0200 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2017-07-28 12:06:53 +0200 |
commit | 0eee31e212a9936bcfe0c61a3bf3635a8778a434 (patch) | |
tree | eec4d8350fae604948f5e61b2e5de31d41b8e252 | |
parent | 5e6ca3ada217c84fa2f198e5de6bc89bc2c5874d (diff) | |
download | qtlocation-mapboxgl-0eee31e212a9936bcfe0c61a3bf3635a8778a434.tar.gz |
[android] - harden click handling of shape annotations
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java | 22 |
1 files changed, 18 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 f35eb9b4f0..ef794c8482 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 @@ -43,6 +43,7 @@ import timber.log.Timber; class AnnotationManager { private static final String LAYER_ID_SHAPE_ANNOTATIONS = "com.mapbox.annotations.shape."; + private static final long NO_ANNOTATION_ID = -1; private final NativeMapView nativeMapView; private final MapView mapView; @@ -649,13 +650,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) { @@ -725,8 +726,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; + } } } @@ -743,7 +757,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(); |