Skip to content

Commit 62c8306

Browse files
committed
Add a button to clear the browsers (tile) cache and reload them
1 parent 2a14718 commit 62c8306

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

BlueMapCore/src/main/webroot/js/libs/BlueMap.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@ import SKY_VERTEX_SHADER from './shaders/SkyVertexShader.js';
5757
import SKY_FRAGMENT_SHADER from './shaders/SkyFragmentShader.js';
5858

5959
import { stringToImage, pathFromCoords } from './utils.js';
60-
import {getCookie, setCookie} from "./utils";
60+
import {cachePreventionNr, getCookie, setCookie} from "./utils";
6161

6262
export default class BlueMap {
6363
constructor(element, dataRoot) {
6464
this.element = $('<div class="bluemap-container"></div>').appendTo(element)[0];
6565
this.dataRoot = dataRoot;
6666
this.locationHash = '';
67+
this.cacheSuffix = '';
6768

6869
this.hiresViewDistance = 160;
6970
this.lowresViewDistance = 3200;
@@ -112,6 +113,17 @@ export default class BlueMap {
112113
});
113114
}
114115

116+
reloadMap() {
117+
if (this.hiresTileManager !== undefined){
118+
this.hiresTileManager.removeAllTiles();
119+
this.hiresTileManager.update();
120+
}
121+
if (this.lowresTileManager !== undefined){
122+
this.lowresTileManager.removeAllTiles();
123+
this.lowresTileManager.update();
124+
}
125+
}
126+
115127
changeMap(map, loadTiles = true) {
116128
if (this.debugInfo) console.debug("changing map: ", map);
117129

@@ -310,7 +322,7 @@ export default class BlueMap {
310322

311323
async loadSettings() {
312324
return new Promise(resolve => {
313-
this.fileLoader.load(this.dataRoot + 'settings.json', settings => {
325+
this.fileLoader.load(this.dataRoot + 'settings.json?' + cachePreventionNr(), settings => {
314326
try {
315327
this.settings = JSON.parse(settings);
316328
this.maps = [];
@@ -379,6 +391,7 @@ export default class BlueMap {
379391
this.hiresViewDistance = this.loadUserSetting("hiresViewDistance", this.hiresViewDistance);
380392
this.lowresViewDistance = this.loadUserSetting("lowresViewDistance", this.lowresViewDistance);
381393
this.controls.settings.zoom.max = this.loadUserSetting("maxZoomDistance", this.controls.settings.zoom.max);
394+
this.cacheSuffix = this.loadUserSetting("cacheSuffix", this.cacheSuffix);
382395
this.debugInfo = this.loadUserSetting("debugInfo", this.debugInfo);
383396
}
384397

@@ -393,6 +406,7 @@ export default class BlueMap {
393406
this.saveUserSetting("hiresViewDistance", this.hiresViewDistance);
394407
this.saveUserSetting("lowresViewDistance", this.lowresViewDistance);
395408
this.saveUserSetting("maxZoomDistance", this.controls.settings.zoom.max);
409+
this.saveUserSetting("cacheSuffix", this.cacheSuffix);
396410
this.saveUserSetting("debugInfo", this.debugInfo);
397411
}
398412

@@ -427,7 +441,7 @@ export default class BlueMap {
427441

428442
async loadHiresMaterial() {
429443
return new Promise(resolve => {
430-
this.fileLoader.load(this.dataRoot + 'textures.json', textures => {
444+
this.fileLoader.load(this.dataRoot + 'textures.json?' + cachePreventionNr(), textures => {
431445
textures = JSON.parse(textures);
432446
let materials = [];
433447
for (let i = 0; i < textures['textures'].length; i++) {
@@ -501,7 +515,7 @@ export default class BlueMap {
501515
async loadHiresTile(tileX, tileZ) {
502516
let path = this.dataRoot + this.map + '/hires/';
503517
path += pathFromCoords(tileX, tileZ);
504-
path += '.json';
518+
path += '.json?' + this.cacheSuffix;
505519

506520
return new Promise((resolve, reject) => {
507521
this.bufferGeometryLoader.load(path, geometry => {
@@ -522,7 +536,7 @@ export default class BlueMap {
522536
async loadLowresTile(tileX, tileZ) {
523537
let path = this.dataRoot + this.map + '/lowres/';
524538
path += pathFromCoords(tileX, tileZ);
525-
path += '.json';
539+
path += '.json?' + this.cacheSuffix;
526540

527541
return new Promise((reslove, reject) => {
528542
this.bufferGeometryLoader.load(path, geometry => {

BlueMapCore/src/main/webroot/js/libs/ui/UI.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ import NIGHT from '../../../assets/night.svg';
4141
import HudInfo from "../hud/HudInfo";
4242
import MarkerManager from "../hud/MarkerManager";
4343

44+
import {cachePreventionNr} from "../utils";
45+
4446
export default class UI {
4547

4648
constructor(blueMap) {
@@ -101,6 +103,11 @@ export default class UI {
101103
this.blueMap.debugInfo = button.isSelected();
102104
});
103105

106+
let clearCache = new Button("clear tile cache", button => {
107+
this.blueMap.cacheSuffix = cachePreventionNr();
108+
this.blueMap.reloadMap();
109+
});
110+
104111
//toolbar
105112
this.toolbar.addElement(menuButton);
106113
this.toolbar.addElement(mapSelect);
@@ -128,6 +135,7 @@ export default class UI {
128135
this.menu.addElement(lowresSlider);
129136
this.menu.addElement(extendedZoom);
130137
this.menu.addElement(new Separator());
138+
this.menu.addElement(clearCache);
131139
this.menu.addElement(debugInfo);
132140
this.menu.update();
133141
}

0 commit comments

Comments
 (0)