* Allows the user to reload/reset the map's location to it's initial location
()
| 1225 | * Allows the user to reload/reset the map's location to it's initial location |
| 1226 | */ |
| 1227 | reload() { |
| 1228 | let initialLocation = this._history.shift(); |
| 1229 | let mapLocation = this._map.getPixelBounds().getCenter(); |
| 1230 | let curr = { |
| 1231 | zoom: this._map.getZoom(), |
| 1232 | x: mapLocation.x, |
| 1233 | y: mapLocation.y |
| 1234 | }; |
| 1235 | |
| 1236 | this._map.contextMenu.toggleContextMenuItem('Back', 'disabled'); // back contextmenu item |
| 1237 | this._map.contextMenu.toggleContextMenuItem('Forward', 'disabled'); // forward contextmenu item |
| 1238 | this._map.contextMenu.toggleContextMenuItem('Reload', 'disabled'); // reload contextmenu item |
| 1239 | this._reloadButton?.disable(); |
| 1240 | |
| 1241 | this._history = [initialLocation]; |
| 1242 | this._historyIndex = 0; |
| 1243 | |
| 1244 | if (initialLocation.zoom !== curr.zoom) { |
| 1245 | this._traversalCall = 2; // ignores the next 2 moveend events |
| 1246 | |
| 1247 | let currScale = this._map.options.crs.scale(curr.zoom); // gets the scale of the current zoom level |
| 1248 | let initScale = this._map.options.crs.scale(initialLocation.zoom); // gets the scale of the initial location's zoom |
| 1249 | |
| 1250 | let scale = currScale / initScale; |
| 1251 | |
| 1252 | this._map.panBy( |
| 1253 | [ |
| 1254 | initialLocation.x * scale - curr.x, |
| 1255 | initialLocation.y * scale - curr.y |
| 1256 | ], |
| 1257 | { animate: false } |
| 1258 | ); |
| 1259 | this._map.setZoom(initialLocation.zoom); |
| 1260 | } else { |
| 1261 | // if it's on the same zoom level as the initial location, no need to calculate scales |
| 1262 | this._traversalCall = 1; |
| 1263 | this._map.panBy([initialLocation.x - curr.x, initialLocation.y - curr.y]); |
| 1264 | } |
| 1265 | this._map.getContainer().focus(); |
| 1266 | } |
| 1267 | |
| 1268 | _toggleFullScreen() { |
| 1269 | this._map.toggleFullscreen(); |
no test coverage detected