diff --git a/overviewer_core/data/js_src/util.js b/overviewer_core/data/js_src/util.js index f4f487b..59294cb 100644 --- a/overviewer_core/data/js_src/util.js +++ b/overviewer_core/data/js_src/util.js @@ -221,6 +221,27 @@ overviewer.util = { 'Overviewer/Leaflet'); overviewer.map.on('baselayerchange', function(ev) { + + // when changing the layer, ensure coordinates remain correct + if (overviewer.current_layer[overviewer.current_world]) { + const center = overviewer.map.getCenter(); + const currentWorldCoords = overviewer.util.fromLatLngToWorld( + center.lat, + center.lng, + overviewer.current_layer[overviewer.current_world].tileSetConfig); + + const newMapCoords = overviewer.util.fromWorldToLatLng( + currentWorldCoords.x, + currentWorldCoords.y, + currentWorldCoords.z, + ev.layer.tileSetConfig); + + overviewer.map.setView( + newMapCoords, + overviewer.map.getZoom(), + { animate: false }); + } + // before updating the current_layer, remove the marker control, if it exists if (overviewer.current_world && overviewer.current_layer[overviewer.current_world]) { let tsc = overviewer.current_layer[overviewer.current_world].tileSetConfig;