From d9a2f984819f10768a54f295143c38eea55a17db Mon Sep 17 00:00:00 2001 From: "Blue (Lukas Rieger)" Date: Fri, 18 Sep 2020 11:50:36 +0200 Subject: [PATCH] Only update hash when the camera is no longer moving to reduce the history-spam as much as possible while still retaining the url-feature --- BlueMapCore/src/main/webroot/js/libs/BlueMap.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/BlueMapCore/src/main/webroot/js/libs/BlueMap.js b/BlueMapCore/src/main/webroot/js/libs/BlueMap.js index d5d13c20..62c178d5 100644 --- a/BlueMapCore/src/main/webroot/js/libs/BlueMap.js +++ b/BlueMapCore/src/main/webroot/js/libs/BlueMap.js @@ -248,7 +248,7 @@ export default class BlueMap { this.hiresTileManager.setPosition(this.controls.targetPosition); } - this.locationHash = + let newHash = '#' + this.map + ':' + Math.floor(this.controls.targetPosition.x) + ':' + Math.floor(this.controls.targetPosition.z) @@ -256,10 +256,18 @@ export default class BlueMap { + ':' + Math.round(this.controls.targetDistance * 100) / 100 + ':' + Math.ceil(this.controls.targetAngle * 100) / 100 + ':' + Math.floor(this.controls.terrainHeight); + // only update hash when changed - if (window.location.hash !== this.locationHash) { - history.replaceState(undefined, undefined, this.locationHash); + if (window.location.hash !== newHash) { + + // but wait until it has finished changing (update when camera is no longer moving, to reduce the number of updates and history spam) + if (this.locationHash === newHash) { + history.replaceState(undefined, undefined, this.locationHash); + } + + this.locationHash = newHash; } + }; render = () => {