diff options
author | Łukasz Paczos <lukas.paczos@gmail.com> | 2018-10-26 14:41:39 +0200 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2018-10-31 14:53:56 +0100 |
commit | 48bbaa6c6ed2306c59fcab58d455bdeb5ddc91c3 (patch) | |
tree | 6f54d037682c9a5a054f8480873007020494ddf7 /platform/android/MapboxGLAndroidSDK/src/main/java/com | |
parent | 11f00c439374238901b1992a940c98ecd59880bf (diff) | |
download | qtlocation-mapboxgl-48bbaa6c6ed2306c59fcab58d455bdeb5ddc91c3.tar.gz |
[android] option to consume map clicks, consuming location clicks
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com')
3 files changed, 28 insertions, 6 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java index 9118f926f3..4e17268abb 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java @@ -583,6 +583,11 @@ public final class LocationComponent { /** * Adds a listener that gets invoked when the user clicks the displayed location. + * <p> + * If there are registered location click listeners and the location is clicked, + * only {@link OnLocationClickListener#onLocationComponentClick()} is going to be delivered, + * {@link com.mapbox.mapboxsdk.maps.MapboxMap.OnMapClickListener#onMapClick(LatLng)} is going to be consumed + * and not pushed to the listeners registered after the component's activation. * * @param listener The location click listener that is invoked when the * location is clicked @@ -602,6 +607,11 @@ public final class LocationComponent { /** * Adds a listener that gets invoked when the user long clicks the displayed location. + * <p> + * If there are registered location long click listeners and the location is long clicked, + * only {@link OnLocationLongClickListener#onLocationComponentLongClick()} is going to be delivered, + * {@link com.mapbox.mapboxsdk.maps.MapboxMap.OnMapLongClickListener#onMapLongClick(LatLng)} is going to be consumed + * and not pushed to the listeners registered after the component's activation. * * @param listener The location click listener that is invoked when the * location is clicked @@ -915,23 +925,27 @@ public final class LocationComponent { private OnMapClickListener onMapClickListener = new OnMapClickListener() { @Override - public void onMapClick(@NonNull LatLng point) { + public boolean onMapClick(@NonNull LatLng point) { if (!onLocationClickListeners.isEmpty() && locationLayerController.onMapClick(point)) { for (OnLocationClickListener listener : onLocationClickListeners) { listener.onLocationComponentClick(); } + return true; } + return false; } }; private MapboxMap.OnMapLongClickListener onMapLongClickListener = new MapboxMap.OnMapLongClickListener() { @Override - public void onMapLongClick(@NonNull LatLng point) { + public boolean onMapLongClick(@NonNull LatLng point) { if (!onLocationLongClickListeners.isEmpty() && locationLayerController.onMapClick(point)) { for (OnLocationLongClickListener listener : onLocationLongClickListeners) { listener.onLocationComponentLongClick(); } + return true; } + return false; } }; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java index 711896e45e..d589b2e0e3 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java @@ -927,7 +927,9 @@ final class MapGestureDetector { // new API for (MapboxMap.OnMapClickListener listener : onMapClickListenerList) { - listener.onMapClick(projection.fromScreenLocation(tapPoint)); + if (listener.onMapClick(projection.fromScreenLocation(tapPoint))) { + return; + } } } @@ -939,7 +941,9 @@ final class MapGestureDetector { // new API for (MapboxMap.OnMapLongClickListener listener : onMapLongClickListenerList) { - listener.onMapLongClick(projection.fromScreenLocation(longClickPoint)); + if (listener.onMapLongClick(projection.fromScreenLocation(longClickPoint))) { + return; + } } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java index 5296535dd0..f34a30f140 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java @@ -2544,8 +2544,10 @@ public final class MapboxMap { * Called when the user clicks on the map view. * * @param point The projected map coordinate the user clicked on. + * @return True if this click should be consumed and not passed further to other listeners registered afterwards, + * false otherwise. */ - void onMapClick(@NonNull LatLng point); + boolean onMapClick(@NonNull LatLng point); } /** @@ -2558,8 +2560,10 @@ public final class MapboxMap { * Called when the user long clicks on the map view. * * @param point The projected map coordinate the user long clicked on. + * @return True if this click should be consumed and not passed further to other listeners registered afterwards, + * false otherwise. */ - void onMapLongClick(@NonNull LatLng point); + boolean onMapLongClick(@NonNull LatLng point); } /** |