|
24 | 24 | import com.google.gson.GsonBuilder;
|
25 | 25 | import com.google.gson.reflect.TypeToken;
|
26 | 26 | import com.mapbox.mapboxsdk.Mapbox;
|
| 27 | +import com.mapbox.mapboxsdk.annotations.Marker; |
27 | 28 | import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
28 | 29 | import com.mapbox.mapboxsdk.annotations.PolygonOptions;
|
29 | 30 | import com.mapbox.mapboxsdk.camera.CameraPosition;
|
@@ -76,6 +77,7 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment {
|
76 | 77 | private Animation rotate_forward;
|
77 | 78 |
|
78 | 79 | private Place place;
|
| 80 | + private Marker selected; |
79 | 81 |
|
80 | 82 | public NearbyMapFragment() {
|
81 | 83 | }
|
@@ -135,6 +137,8 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
135 | 137 | else if (bottomSheetDetailsBehavior.getState() == BottomSheetBehavior
|
136 | 138 | .STATE_COLLAPSED) {
|
137 | 139 | bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
| 140 | + mapView.getMapAsync(MapboxMap::deselectMarkers); |
| 141 | + selected=null; |
138 | 142 | return true;
|
139 | 143 | }
|
140 | 144 | }
|
@@ -250,8 +254,15 @@ private void setupMapView(Bundle savedInstanceState) {
|
250 | 254 | mapView.getMapAsync(mapboxMap -> {
|
251 | 255 | mapboxMap.addMarkers(baseMarkerOptions);
|
252 | 256 |
|
| 257 | + mapboxMap.setOnInfoWindowCloseListener(marker -> { |
| 258 | + if (marker == selected){ |
| 259 | + bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); |
| 260 | + } |
| 261 | + }); |
| 262 | + |
253 | 263 | mapboxMap.setOnMarkerClickListener(marker -> {
|
254 | 264 | if (marker instanceof NearbyMarker) {
|
| 265 | + this.selected = marker; |
255 | 266 | NearbyMarker nearbyMarker = (NearbyMarker) marker;
|
256 | 267 | Place place = nearbyMarker.getNearbyBaseMarker().getPlace();
|
257 | 268 | passInfoToSheet(place);
|
@@ -325,6 +336,7 @@ public void prepareViewsForSheetPosition(int bottomSheetState) {
|
325 | 336 | this.getView().requestFocus();
|
326 | 337 | break;
|
327 | 338 | case (BottomSheetBehavior.STATE_HIDDEN):
|
| 339 | + mapView.getMapAsync(MapboxMap::deselectMarkers); |
328 | 340 | transparentView.setClickable(false);
|
329 | 341 | transparentView.setAlpha(0);
|
330 | 342 | closeFabs(isFabOpen);
|
|
0 commit comments