* Allow user to move back in history
()
| 1109 | * Allow user to move back in history |
| 1110 | */ |
| 1111 | back() { |
| 1112 | let history = this._history; |
| 1113 | let curr = history[this._historyIndex]; |
| 1114 | |
| 1115 | if (this._historyIndex > 0) { |
| 1116 | this._map.contextMenu.toggleContextMenuItem('Forward', 'enabled'); // forward contextmenu item |
| 1117 | this._historyIndex--; |
| 1118 | let prev = history[this._historyIndex]; |
| 1119 | // Disable back, reload contextmenu item when at the end of history |
| 1120 | if (this._historyIndex === 0) { |
| 1121 | this._map.contextMenu.toggleContextMenuItem('Back', 'disabled'); // back contextmenu item |
| 1122 | this._map.contextMenu.toggleContextMenuItem('Reload', 'disabled'); // reload contextmenu item |
| 1123 | this._reloadButton?.disable(); |
| 1124 | } |
| 1125 | |
| 1126 | if (prev.zoom !== curr.zoom) { |
| 1127 | this._traversalCall = 2; // allows the next 2 moveends to be ignored from history |
| 1128 | |
| 1129 | let currScale = this._map.options.crs.scale(curr.zoom); // gets the scale of the current zoom level |
| 1130 | let prevScale = this._map.options.crs.scale(prev.zoom); // gets the scale of the previous zoom level |
| 1131 | |
| 1132 | let scale = currScale / prevScale; // used to convert the previous pixel location to be in terms of the current zoom level |
| 1133 | |
| 1134 | this._map.panBy([prev.x * scale - curr.x, prev.y * scale - curr.y], { |
| 1135 | animate: false |
| 1136 | }); |
| 1137 | this._map.setZoom(prev.zoom); |
| 1138 | } else { |
| 1139 | this._traversalCall = 1; |
| 1140 | this._map.panBy([prev.x - curr.x, prev.y - curr.y]); |
| 1141 | } |
| 1142 | } |
| 1143 | } |
| 1144 | |
| 1145 | /** |
| 1146 | * Allows user to move forward in history |