From ec6ed280573434693649294f8c37c6cbd8c7005a Mon Sep 17 00:00:00 2001 From: Peter Date: Sat, 22 Jun 2024 14:24:09 +0200 Subject: [PATCH] fix 'center map' and keep zoom if zoomed in --- src/actions/Actions.ts | 4 +--- src/map/ContextMenuContent.tsx | 2 +- src/stores/MapActionReceiver.ts | 4 +++- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/actions/Actions.ts b/src/actions/Actions.ts index 5713eeb3..1f9164fa 100644 --- a/src/actions/Actions.ts +++ b/src/actions/Actions.ts @@ -179,11 +179,9 @@ export class MapIsLoaded implements Action {} export class ZoomMapToPoint implements Action { readonly coordinate: Coordinate - readonly zoom: number - constructor(coordinate: Coordinate, zoom: number) { + constructor(coordinate: Coordinate) { this.coordinate = coordinate - this.zoom = zoom } } diff --git a/src/map/ContextMenuContent.tsx b/src/map/ContextMenuContent.tsx index 6ebcd407..931d395d 100644 --- a/src/map/ContextMenuContent.tsx +++ b/src/map/ContextMenuContent.tsx @@ -112,7 +112,7 @@ export function ContextMenuContent({ className={styles.entry} onClick={() => { onSelect() - Dispatcher.dispatch(new ZoomMapToPoint(coordinate, 8)) + Dispatcher.dispatch(new ZoomMapToPoint(coordinate)) }} > {tr('center_map')} diff --git a/src/stores/MapActionReceiver.ts b/src/stores/MapActionReceiver.ts index d6e127e0..76a171ab 100644 --- a/src/stores/MapActionReceiver.ts +++ b/src/stores/MapActionReceiver.ts @@ -31,8 +31,10 @@ export default class MapActionReceiver implements ActionReceiver { // the map has not been rendered for the first time yet fitBounds(this.map, action.bbox, isSmallScreen, [window.innerWidth, window.innerHeight]) } else if (action instanceof ZoomMapToPoint) { + let zoom = this.map.getView().getZoom() + if(zoom == undefined || zoom < 8) zoom = 8 this.map.getView().animate({ - zoom: action.zoom, + zoom: zoom, center: fromLonLat([action.coordinate.lng, action.coordinate.lat]), duration: 400, })