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

Method _addToHistory

src/mapml-viewer.js:1076–1107  ·  view source on GitHub ↗

* Adds to the maps history on moveends * @private

()

Source from the content-addressed store, hash-verified

1074 * @private
1075 */
1076 _addToHistory() {
1077 if (this._traversalCall > 0) {
1078 // this._traversalCall tracks how many consecutive moveends to ignore from history
1079 this._traversalCall--; // this is useful for ignoring moveends corresponding to back, forward and reload
1080 return;
1081 }
1082
1083 let mapLocation = this._map.getPixelBounds().getCenter();
1084 let location = {
1085 zoom: this._map.getZoom(),
1086 x: mapLocation.x,
1087 y: mapLocation.y
1088 };
1089 this._historyIndex++;
1090 this._history.splice(this._historyIndex, 0, location);
1091 // Remove future history and overwrite it when map pan/zoom while inside history
1092 if (this._historyIndex + 1 !== this._history.length) {
1093 this._history.length = this._historyIndex + 1;
1094 }
1095 if (this._historyIndex === 0) {
1096 // when at initial state of map, disable back, forward, and reload items
1097 this._map.contextMenu.toggleContextMenuItem('Back', 'disabled'); // back contextmenu item
1098 this._map.contextMenu.toggleContextMenuItem('Forward', 'disabled'); // forward contextmenu item
1099 this._map.contextMenu.toggleContextMenuItem('Reload', 'disabled'); // reload contextmenu item
1100 this._reloadButton?.disable();
1101 } else {
1102 this._map.contextMenu.toggleContextMenuItem('Back', 'enabled'); // back contextmenu item
1103 this._map.contextMenu.toggleContextMenuItem('Forward', 'disabled'); // forward contextmenu item
1104 this._map.contextMenu.toggleContextMenuItem('Reload', 'enabled'); // reload contextmenu item
1105 this._reloadButton?.enable();
1106 }
1107 }
1108 /**
1109 * Allow user to move back in history
1110 */

Callers 3

_createMapMethod · 0.95
_setUpEventsMethod · 0.95
_resetHistoryMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected