[android] option to consume map clicks, consuming location clicks

This commit is contained in:
Łukasz Paczos
2018-10-26 14:41:39 +02:00
committed by Tobrun
parent 11f00c4393
commit 48bbaa6c6e
16 changed files with 74 additions and 21 deletions

View File

@@ -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;
}
};

View File

@@ -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;
}
}
}

View File

@@ -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);
}
/**