|
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; |
@@ -77,6 +78,7 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment { |
77 | 78 | private Animation rotate_forward; |
78 | 79 |
|
79 | 80 | private Place place; |
| 81 | + private Marker selected; |
80 | 82 |
|
81 | 83 | public NearbyMapFragment() { |
82 | 84 | } |
@@ -136,6 +138,8 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
136 | 138 | else if (bottomSheetDetailsBehavior.getState() == BottomSheetBehavior |
137 | 139 | .STATE_COLLAPSED) { |
138 | 140 | bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); |
| 141 | + mapView.getMapAsync(MapboxMap::deselectMarkers); |
| 142 | + selected=null; |
139 | 143 | return true; |
140 | 144 | } |
141 | 145 | } |
@@ -253,8 +257,15 @@ private void setupMapView(Bundle savedInstanceState) { |
253 | 257 | mapView.getMapAsync(mapboxMap -> { |
254 | 258 | mapboxMap.addMarkers(baseMarkerOptions); |
255 | 259 |
|
| 260 | + mapboxMap.setOnInfoWindowCloseListener(marker -> { |
| 261 | + if (marker == selected){ |
| 262 | + bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); |
| 263 | + } |
| 264 | + }); |
| 265 | + |
256 | 266 | mapboxMap.setOnMarkerClickListener(marker -> { |
257 | 267 | if (marker instanceof NearbyMarker) { |
| 268 | + this.selected = marker; |
258 | 269 | NearbyMarker nearbyMarker = (NearbyMarker) marker; |
259 | 270 | Place place = nearbyMarker.getNearbyBaseMarker().getPlace(); |
260 | 271 | passInfoToSheet(place); |
@@ -328,6 +339,7 @@ public void prepareViewsForSheetPosition(int bottomSheetState) { |
328 | 339 | this.getView().requestFocus(); |
329 | 340 | break; |
330 | 341 | case (BottomSheetBehavior.STATE_HIDDEN): |
| 342 | + mapView.getMapAsync(MapboxMap::deselectMarkers); |
331 | 343 | transparentView.setClickable(false); |
332 | 344 | transparentView.setAlpha(0); |
333 | 345 | closeFabs(isFabOpen); |
|
0 commit comments