MCPcopy Index your code
hub / github.com/Maps4HTML/MapML.js / reload

Method reload

src/mapml-viewer.js:1184–1223  ·  view source on GitHub ↗

* Allows the user to reload/reset the map's location to it's initial location

()

Source from the content-addressed store, hash-verified

1182 * Allows the user to reload/reset the map's location to it's initial location
1183 */
1184 reload() {
1185 let initialLocation = this._history.shift();
1186 let mapLocation = this._map.getPixelBounds().getCenter();
1187 let curr = {
1188 zoom: this._map.getZoom(),
1189 x: mapLocation.x,
1190 y: mapLocation.y
1191 };
1192
1193 this._map.contextMenu.toggleContextMenuItem('Back', 'disabled'); // back contextmenu item
1194 this._map.contextMenu.toggleContextMenuItem('Forward', 'disabled'); // forward contextmenu item
1195 this._map.contextMenu.toggleContextMenuItem('Reload', 'disabled'); // reload contextmenu item
1196 this._reloadButton?.disable();
1197
1198 this._history = [initialLocation];
1199 this._historyIndex = 0;
1200
1201 if (initialLocation.zoom !== curr.zoom) {
1202 this._traversalCall = 2; // ignores the next 2 moveend events
1203
1204 let currScale = this._map.options.crs.scale(curr.zoom); // gets the scale of the current zoom level
1205 let initScale = this._map.options.crs.scale(initialLocation.zoom); // gets the scale of the initial location's zoom
1206
1207 let scale = currScale / initScale;
1208
1209 this._map.panBy(
1210 [
1211 initialLocation.x * scale - curr.x,
1212 initialLocation.y * scale - curr.y
1213 ],
1214 { animate: false }
1215 );
1216 this._map.setZoom(initialLocation.zoom);
1217 } else {
1218 // if it's on the same zoom level as the initial location, no need to calculate scales
1219 this._traversalCall = 1;
1220 this._map.panBy([initialLocation.x - curr.x, initialLocation.y - curr.y]);
1221 }
1222 this._map.getContainer().focus();
1223 }
1224
1225 _toggleFullScreen() {
1226 this._map.toggleFullscreen();

Callers 1

_setUpEventsMethod · 0.95

Calls 1

focusMethod · 0.80

Tested by

no test coverage detected