Improve marker updating and fix an error when loading empty tiles

This commit is contained in:
Blue (Lukas Rieger) 2021-03-28 13:22:45 +02:00
parent 89694564e0
commit 4e81bb4abd
No known key found for this signature in database
GPG Key ID: 904C4995F9E1F800
4 changed files with 31 additions and 15 deletions

View File

@ -61,7 +61,10 @@ export class TileLoader {
return new Promise((resolve, reject) => {
this.fileLoader.load(tileUrl + '?' + this.tileCacheHash,
geometryJson => {
if (!geometryJson.type || geometryJson.type !== 'BufferGeometry') reject({status: "empty"});
if (!geometryJson.type || geometryJson.type !== 'BufferGeometry'){
reject({status: "empty"});
return;
}
let geometry = this.bufferGeometryLoader.parse(geometryJson);

View File

@ -52,7 +52,7 @@ export class MarkerFileManager extends MarkerManager {
}
updateFromData(markerData) {
if (!Array.isArray(markerData.markerSets)) return;
if (!Array.isArray(markerData.markerSets)) return false;
let updatedMarkerSets = new Set();
// add & update
@ -71,6 +71,8 @@ export class MarkerFileManager extends MarkerManager {
this.removeMarkerSet(setId);
}
});
return true;
}
/**

View File

@ -63,8 +63,12 @@ export class MarkerManager {
if (ms > 0) {
let autoUpdate = () => {
this.update()
.then(() => {
this._updateInterval = setTimeout(autoUpdate, ms);
.then(success => {
if (success) {
this._updateInterval = setTimeout(autoUpdate, ms);
} else {
this._updateInterval = setTimeout(autoUpdate, Math.max(ms, 1000 * 15));
}
})
.catch(e => {
alert(this.events, e, "warning");
@ -158,8 +162,11 @@ export class MarkerManager {
/**
* Updates all managed markers using the provided data.
* @param markerData {object} - The data object, usually parsed json from a markers.json
* @returns {boolean} - If the update was successful
*/
updateFromData(markerData) {}
updateFromData(markerData) {
return false;
}
/**
* @private

View File

@ -50,20 +50,23 @@ export class PlayerMarkerManager extends MarkerManager {
*/
updateFromData(markerData) {
if (!Array.isArray(markerData.players)) {
this.clear();
return false;
}
/** @type Set<Marker> */
let updatedPlayerMarkers = new Set();
// update
if (Array.isArray(markerData.players)) {
markerData.players.forEach(playerData => {
try {
let playerMarker = this.updatePlayerMarkerFromData(playerData);
updatedPlayerMarkers.add(playerMarker);
} catch (err) {
alert(this.events, err, "fine");
}
});
}
markerData.players.forEach(playerData => {
try {
let playerMarker = this.updatePlayerMarkerFromData(playerData);
updatedPlayerMarkers.add(playerMarker);
} catch (err) {
alert(this.events, err, "fine");
}
});
// remove
this.markers.forEach((playerMarker, markerId) => {
@ -72,6 +75,7 @@ export class PlayerMarkerManager extends MarkerManager {
}
});
return true;
}
/**