diff --git a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/AnnotationManager.java b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/AnnotationManager.java index 94b31b8da..903a7100a 100644 --- a/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/AnnotationManager.java +++ b/plugin-annotation/src/main/java/com/mapbox/mapboxsdk/plugins/annotation/AnnotationManager.java @@ -17,6 +17,7 @@ import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -375,8 +376,7 @@ public boolean onMapClick(@NonNull LatLng point) { return false; } - T annotation = queryMapForFeatures(point); - if (annotation != null) { + for (T annotation : queryMapForAllFeatures(point)) { for (U clickListener : clickListeners) { if (clickListener.onAnnotationClick(annotation)) { return true; @@ -392,8 +392,7 @@ public boolean onMapLongClick(@NonNull LatLng point) { return false; } - T annotation = queryMapForFeatures(point); - if (annotation != null) { + for (T annotation : queryMapForAllFeatures(point)) { for (V clickListener : longClickListeners) { if (clickListener.onAnnotationLongClick(annotation)) { return true; @@ -404,11 +403,6 @@ public boolean onMapLongClick(@NonNull LatLng point) { } } - @Nullable - private T queryMapForFeatures(@NonNull LatLng point) { - return queryMapForFeatures(mapboxMap.getProjection().toScreenLocation(point)); - } - @Nullable T queryMapForFeatures(@NonNull PointF point) { List features = mapboxMap.queryRenderedFeatures(point, coreElementProvider.getLayerId()); @@ -418,4 +412,23 @@ T queryMapForFeatures(@NonNull PointF point) { } return null; } + + @NonNull + private List queryMapForAllFeatures(@NonNull LatLng point) { + return queryMapForAllFeatures(mapboxMap.getProjection().toScreenLocation(point)); + } + + @NonNull + List queryMapForAllFeatures(@NonNull PointF point) { + List annotations = new LinkedList(); + List features = mapboxMap.queryRenderedFeatures(point, coreElementProvider.getLayerId()); + for (Feature feature : features) { + long id = feature.getProperty(getAnnotationIdKey()).getAsLong(); + T annotation = this.annotations.get(id); + if (annotation != null) { + annotations.add(annotation); + } + } + return annotations; + } }