Skip to content

Commit

Permalink
fix 'center map' and keep zoom if zoomed in
Browse files Browse the repository at this point in the history
  • Loading branch information
karussell committed Jun 22, 2024
1 parent df80454 commit ec6ed28
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/actions/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/map/ContextMenuContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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')}
Expand Down
4 changes: 3 additions & 1 deletion src/stores/MapActionReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down

0 comments on commit ec6ed28

Please sign in to comment.