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

Method _addToHistory

src/web-map.js:1119–1150  ·  view source on GitHub ↗

* Adds to the maps history on moveends * @private

()

Source from the content-addressed store, hash-verified

1117 * @private
1118 */
1119 _addToHistory() {
1120 if (this._traversalCall > 0) {
1121 // this._traversalCall tracks how many consecutive moveends to ignore from history
1122 this._traversalCall--; // this is useful for ignoring moveends corresponding to back, forward and reload
1123 return;
1124 }
1125
1126 let mapLocation = this._map.getPixelBounds().getCenter();
1127 let location = {
1128 zoom: this._map.getZoom(),
1129 x: mapLocation.x,
1130 y: mapLocation.y
1131 };
1132 this._historyIndex++;
1133 this._history.splice(this._historyIndex, 0, location);
1134 // Remove future history and overwrite it when map pan/zoom while inside history
1135 if (this._historyIndex + 1 !== this._history.length) {
1136 this._history.length = this._historyIndex + 1;
1137 }
1138 if (this._historyIndex === 0) {
1139 // when at initial state of map, disable back, forward, and reload items
1140 this._map.contextMenu.toggleContextMenuItem('Back', 'disabled'); // back contextmenu item
1141 this._map.contextMenu.toggleContextMenuItem('Forward', 'disabled'); // forward contextmenu item
1142 this._map.contextMenu.toggleContextMenuItem('Reload', 'disabled'); // reload contextmenu item
1143 this._reloadButton?.disable();
1144 } else {
1145 this._map.contextMenu.toggleContextMenuItem('Back', 'enabled'); // back contextmenu item
1146 this._map.contextMenu.toggleContextMenuItem('Forward', 'disabled'); // forward contextmenu item
1147 this._map.contextMenu.toggleContextMenuItem('Reload', 'enabled'); // reload contextmenu item
1148 this._reloadButton?.enable();
1149 }
1150 }
1151 /**
1152 * Allow user to move back in history
1153 */

Callers 3

_createMapMethod · 0.95
_setUpEventsMethod · 0.95
_resetHistoryMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected