Skip to content

Commit ba73dbb

Browse files
committed
Fix zoom and target according to bottom sheet position
1 parent ae0bfae commit ba73dbb

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,19 @@ private void updateMapToTrackPosition() {
262262
new LatLng(curMapBoxLatLng.getLatitude()- CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT,
263263
curMapBoxLatLng.getLongitude())
264264
: curMapBoxLatLng ) // Sets the new camera position
265-
.zoom(mapboxMap.getCameraPosition().zoom) // Same zoom level
265+
.zoom(isBottomListSheetExpanded ?
266+
11 // zoom level is fixed to 11 when bottom sheet is expanded
267+
:mapboxMap.getCameraPosition().zoom) // Same zoom level
266268
.build();
267269
}else {
268270
position = new CameraPosition.Builder()
269271
.target(isBottomListSheetExpanded ?
270272
new LatLng(curMapBoxLatLng.getLatitude()- CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE,
271273
curMapBoxLatLng.getLongitude())
272274
: curMapBoxLatLng ) // Sets the new camera position
273-
.zoom(mapboxMap.getCameraPosition().zoom) // Same zoom level
275+
.zoom(isBottomListSheetExpanded ?
276+
11 // zoom level is fixed to 11 when bottom sheet is expanded
277+
:mapboxMap.getCameraPosition().zoom) // Same zoom level
274278
.build();
275279
}
276280

@@ -291,14 +295,14 @@ private void updateMapCameraAccordingToBottomSheet(boolean isBottomListSheetExpa
291295
.target(new LatLng(curLatLng.getLatitude() - CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT,
292296
curLatLng.getLongitude())) // Sets the new camera target above
293297
// current to make it visible when sheet is expanded
294-
.zoom(11) // Same zoom level
298+
.zoom(11) // Fixed zoom level
295299
.build();
296300
} else {
297301
position = new CameraPosition.Builder()
298302
.target(new LatLng(curLatLng.getLatitude() - CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE,
299303
curLatLng.getLongitude())) // Sets the new camera target above
300304
// current to make it visible when sheet is expanded
301-
.zoom(11) // Same zoom level
305+
.zoom(11) // Fixed zoom level
302306
.build();
303307
}
304308

@@ -366,10 +370,29 @@ private void setListeners() {
366370
fabRecenter.setOnClickListener(view -> {
367371
if (curLatLng != null) {
368372
mapView.getMapAsync(mapboxMap -> {
369-
CameraPosition position = new CameraPosition.Builder()
370-
.target(new LatLng(curLatLng.getLatitude(), curLatLng.getLongitude())) // Sets the new camera position
371-
.zoom(11) // Sets the zoom
372-
.build(); // Creates a CameraPosition from the builder
373+
CameraPosition position;
374+
375+
if(ViewUtil.isPortrait(getActivity())){
376+
position = new CameraPosition.Builder()
377+
.target(isBottomListSheetExpanded ?
378+
new LatLng(curLatLng.getLatitude()- CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT,
379+
curLatLng.getLongitude())
380+
: new LatLng(curLatLng.getLatitude(), curLatLng.getLongitude(), 0)) // Sets the new camera position
381+
.zoom(isBottomListSheetExpanded ?
382+
11 // zoom level is fixed to 11 when bottom sheet is expanded
383+
:mapboxMap.getCameraPosition().zoom) // Same zoom level
384+
.build();
385+
}else {
386+
position = new CameraPosition.Builder()
387+
.target(isBottomListSheetExpanded ?
388+
new LatLng(curLatLng.getLatitude()- CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE,
389+
curLatLng.getLongitude())
390+
: new LatLng(curLatLng.getLatitude(), curLatLng.getLongitude(), 0)) // Sets the new camera position
391+
.zoom(isBottomListSheetExpanded ?
392+
11 // zoom level is fixed to 11 when bottom sheet is expanded
393+
:mapboxMap.getCameraPosition().zoom) // Same zoom level
394+
.build();
395+
}
373396

374397
mapboxMap.animateCamera(CameraUpdateFactory
375398
.newCameraPosition(position), 1000);

0 commit comments

Comments
 (0)