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