[android] - harden click handling of shape annotations
This commit is contained in:
committed by
Tobrun
parent
5e6ca3ada2
commit
0eee31e212
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user