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

Expose an API to enable selection/deselection of markers on a map tap #5312

Merged
merged 1 commit into from
Jun 13, 2016
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 @@ -1677,8 +1677,10 @@ public boolean onSingleTapConfirmed(MotionEvent e) {
}
}
} else {
// deselect any selected marker
mMapboxMap.deselectMarkers();
if (mMapboxMap.getUiSettings().isDeselectMarkersOnTap()) {
// deselect any selected marker
mMapboxMap.deselectMarkers();
}

// notify app of map click
MapboxMap.OnMapClickListener listener = mMapboxMap.getOnMapClickListener();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class UiSettings {

private boolean zoomControlsEnabled;

private boolean deselectMarkersOnTap = true;

UiSettings(@NonNull MapView mapView) {
this.mapView = mapView;
this.compassSettings = new ViewSettings();
Expand Down Expand Up @@ -483,6 +485,26 @@ public boolean isZoomControlsEnabled() {
return zoomControlsEnabled;
}

/**
* Gets whether the markers are automatically deselected (and therefore, their infowindows
* closed) when a map tap is detected.

* @return If true, markers are deselected on a map tap.
*/
public boolean isDeselectMarkersOnTap() {
return deselectMarkersOnTap;
}

/**
* Sets whether the markers are automatically deselected (and therefore, their infowindows
* closed) when a map tap is detected.
*
* @param deselectMarkersOnTap
*/
public void setDeselectMarkersOnTap(boolean deselectMarkersOnTap) {
this.deselectMarkersOnTap = deselectMarkersOnTap;
}

/**
* <p>
* Changes whether the user may scroll around the map.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ private void toggleConcurrentInfoWindow(boolean allowConcurrentInfoWindow) {
mapboxMap.setAllowConcurrentMultipleOpenInfoWindows(allowConcurrentInfoWindow);
}

private void toggleDeselectMarkersOnTap(boolean deselectMarkersOnTap) {
mapboxMap.getUiSettings().setDeselectMarkersOnTap(deselectMarkersOnTap);
}

@Override
public boolean onInfoWindowClick(@NonNull Marker marker) {
Toast.makeText(getApplicationContext(), "OnClick: " + marker.getTitle(), Toast.LENGTH_LONG).show();
Expand Down Expand Up @@ -157,6 +161,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
toggleConcurrentInfoWindow(!item.isChecked());
item.setChecked(!item.isChecked());
return true;
case R.id.action_toggle_deselect_markers_on_tap:
toggleDeselectMarkersOnTap(!item.isChecked());
item.setChecked(!item.isChecked());
return true;
case android.R.id.home:
onBackPressed();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
android:id="@+id/action_toggle_concurrent_infowindow"
app:showAsAction="never"
android:checkable="true"/>
<item
android:title="@string/menuitem_title_deselect_markers_on_tap"
android:id="@+id/action_toggle_deselect_markers_on_tap"
app:showAsAction="never"
android:checkable="true"
android:checked="true"/>
</group>

</menu>
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
<string name="description_back_to_map">Restart map view after temporarily leaving to another activity</string>
<string name="description_view_marker">Use an Android SDK View as marker</string>

<string name="menuitem_title_concurrent_infowindow">Concurrent Open InfoWindows</string>r
<string name="menuitem_title_concurrent_infowindow">Concurrent Open InfoWindows</string>
<string name="menuitem_title_deselect_markers_on_tap">Deselect Markers On Tap</string>
<string name="menuitem_title_tracking_mode_dismiss_on_gesture">Dismiss location tracking on gesture</string>
<string name="menuitem_title_bearing_mode_dismiss_on_gesture">Dismiss bearing tracking on gesture</string>
<string name="menuitem_title_reset">Reset</string>
Expand Down