Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Option to consume map clicks, consuming location clicks #13205

Merged
merged 1 commit into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,11 @@ public void removeCompassListener(@NonNull CompassListener compassListener) {

/**
* 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
Expand All @@ -603,6 +608,11 @@ public void removeOnLocationClickListener(@NonNull OnLocationClickListener liste

/**
* 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
Expand Down Expand Up @@ -918,23 +928,27 @@ public void onCameraIdle() {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,9 @@ void notifyOnMapClickListeners(PointF tapPoint) {

// new API
for (MapboxMap.OnMapClickListener listener : onMapClickListenerList) {
listener.onMapClick(projection.fromScreenLocation(tapPoint));
if (listener.onMapClick(projection.fromScreenLocation(tapPoint))) {
return;
}
}
}

Expand All @@ -939,7 +941,9 @@ void notifyOnMapLongClickListeners(PointF longClickPoint) {

// new API
for (MapboxMap.OnMapLongClickListener listener : onMapLongClickListenerList) {
listener.onMapLongClick(projection.fromScreenLocation(longClickPoint));
if (listener.onMapLongClick(projection.fromScreenLocation(longClickPoint))) {
return;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2544,8 +2544,10 @@ public interface OnMapClickListener {
* 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);
}

/**
Expand All @@ -2558,8 +2560,10 @@ public interface OnMapLongClickListener {
* 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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@ protected void onCreate(@Nullable final Bundle savedInstanceState) {
mapboxMap = map;
resetMap();

mapboxMap.addOnMapLongClickListener(point -> addMarker(point));

mapboxMap.addOnMapClickListener(point -> addMarker(point));
mapboxMap.addOnMapLongClickListener(point -> {
addMarker(point);
return false;
});

mapboxMap.addOnMapClickListener(point -> {
addMarker(point);
return false;
});

if (savedInstanceState != null) {
markerList = savedInstanceState.getParcelableArrayList(STATE_MARKER_LIST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ public void onMapReady(@NonNull final MapboxMap map) {
}

@Override
public void onMapLongClick(@NonNull LatLng point) {
public boolean onMapLongClick(@NonNull LatLng point) {
toggleLogCameraChanges();
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ public void onMapReady(final MapboxMap map) {
mapboxMap = map;
mapboxMap.setMinZoomPreference(3);
mapboxMap.setMaxZoomPreference(5);
mapboxMap.setOnMapClickListener(point -> map.setStyle(Style.OUTDOORS, style -> Timber.d("Style Loaded %s", style)));
mapboxMap.setOnMapClickListener(point -> {
map.setStyle(Style.OUTDOORS, style -> Timber.d("Style Loaded %s", style));
return false;
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ protected void onCreate(Bundle savedInstanceState) {
// Add a marker on the clicked point
marker = mapboxMap.addMarker(new CustomMarkerOptions().position(point).features(features));
mapboxMap.selectMarker(marker);

return false;
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ protected void onCreate(Bundle savedInstanceState) {
List<Feature> features = source.querySourceFeatures(eq(get("key1"), literal("value1")));
Toast.makeText(QuerySourceFeaturesActivity.this, String.format("Found %s features",
features.size()), Toast.LENGTH_SHORT).show();

return false;
});

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public void onMapReady(MapboxMap map) {
infoWindow.update();
});
}

return false;
});

// Focus on Paris
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void onInfoWindowLongClick(Marker marker) {
}

@Override
public void onMapLongClick(@NonNull LatLng point) {
public boolean onMapLongClick(@NonNull LatLng point) {
if (customMarker != null) {
// Remove previous added marker
mapboxMap.removeAnnotation(customMarker);
Expand All @@ -122,6 +122,8 @@ public void onMapLongClick(@NonNull LatLng point) {
.snippet(new DecimalFormat("#.#####").format(point.getLatitude()) + ", "
+ new DecimalFormat("#.#####").format(point.getLongitude()))
.position(point));

return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

import com.mapbox.android.core.permissions.PermissionsListener;
import com.mapbox.android.core.permissions.PermissionsManager;
import com.mapbox.mapboxsdk.location.LocationComponent;
import com.mapbox.mapboxsdk.location.modes.RenderMode;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.location.LocationComponent;
import com.mapbox.mapboxsdk.location.modes.RenderMode;
import com.mapbox.mapboxsdk.testapp.R;

import java.util.List;
Expand All @@ -33,12 +32,9 @@ protected void onCreate(Bundle savedInstanceState) {
mapView = findViewById(R.id.mapView);
FloatingActionButton stylesFab = findViewById(R.id.fabStyles);

stylesFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mapboxMap != null) {
mapboxMap.setStyleUrl(Utils.getNextStyle());
}
stylesFab.setOnClickListener(v -> {
if (mapboxMap != null) {
mapboxMap.setStyleUrl(Utils.getNextStyle());
}
});

Expand Down Expand Up @@ -86,6 +82,12 @@ private void activateLocationComponent() {
locationComponent.activateLocationComponent(this);
locationComponent.setLocationComponentEnabled(true);
locationComponent.setRenderMode(RenderMode.COMPASS);

locationComponent.addOnLocationClickListener(
() -> Toast.makeText(this, "Location clicked", Toast.LENGTH_SHORT).show());

locationComponent.addOnLocationLongClickListener(
() -> Toast.makeText(this, "Location long clicked", Toast.LENGTH_SHORT).show());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
// test if we can open 2 activities after each other
Toast.makeText(mapViewMini.getContext(), "Creating a new Activity instance",Toast.LENGTH_SHORT).show();
startActivity(new Intent(mapViewMini.getContext(), DoubleMapActivity.class));

return false;
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class DraggableMarkerActivity : AppCompatActivity() {
Snackbar.LENGTH_LONG)
.show()
}

false
}

draggableSymbolsManager = DraggableSymbolsManager(
Expand Down Expand Up @@ -185,6 +187,7 @@ class DraggableMarkerActivity : AppCompatActivity() {
onSymbolDragStarted(id)
}
}
false
}

androidGesturesManager.setMoveGestureListener(MyMoveGestureListener())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ private void addSymbolClickListener() {
"hello from: " + feature.getStringProperty(FEATURE_NAME),
Toast.LENGTH_LONG).show();
}

return false;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.ViewGroup;

import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.mapbox.geojson.Feature;
Expand Down Expand Up @@ -133,7 +134,7 @@ public void onMapReady(MapboxMap mapboxMap) {
}

@Override
public void onMapClick(@NonNull LatLng point) {
public boolean onMapClick(@NonNull LatLng point) {
// Query which features are clicked
PointF screenLoc = mapboxMap.getProjection().toScreenLocation(point);
List<Feature> features = mapboxMap.queryRenderedFeatures(screenLoc, MARKER_LAYER);
Expand All @@ -147,6 +148,8 @@ public void onMapClick(@NonNull LatLng point) {
}
geoJsonSource.setGeoJson(markerCollection);
}

return false;
}

private void toggleTextSize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ private void addMapClickListener() {
} else {
Timber.e("No features found");
}

return false;
});
}

Expand Down