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

Commit

Permalink
[android] #4159 - expose an api to enable selection/deselection of ma…
Browse files Browse the repository at this point in the history
…rkers on map tap (#5312)
  • Loading branch information
zugaldia authored Jun 13, 2016
1 parent 8c86252 commit 7c213e3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1688,8 +1688,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

0 comments on commit 7c213e3

Please sign in to comment.