Basic support for Pl3xmap tile update interval

This commit is contained in:
James Lyne 2021-08-13 23:51:03 +01:00
parent 13260bbfeb
commit 280e036276
3 changed files with 22 additions and 1 deletions

View File

@ -43,7 +43,16 @@ export default defineComponent({
const store = useStore(), const store = useStore(),
active = computed(() => props.map === store.state.currentMap); active = computed(() => props.map === store.state.currentMap);
let layer: LiveAtlasTileLayer; let redrawTimeout = 0,
layer: LiveAtlasTileLayer;
const redraw = () => {
if(active.value) {
layer._update();
}
redrawTimeout = setTimeout(redraw, props.map.tileUpdateInterval);
};
if(store.state.currentServer?.type === 'dynmap') { if(store.state.currentServer?.type === 'dynmap') {
layer = new DynmapTileLayer({ layer = new DynmapTileLayer({
@ -71,8 +80,16 @@ export default defineComponent({
enableLayer(); enableLayer();
} }
if(props.map.tileUpdateInterval) {
redrawTimeout = setTimeout(redraw, props.map.tileUpdateInterval);
}
onUnmounted(() => { onUnmounted(() => {
disableLayer(); disableLayer();
if(redrawTimeout) {
clearTimeout(redrawTimeout);
}
}); });
}, },

View File

@ -34,6 +34,7 @@ export interface LiveAtlasMapDefinitionOptions {
worldToMap?: [number, number, number, number, number, number, number, number, number]; worldToMap?: [number, number, number, number, number, number, number, number, number];
nativeZoomLevels: number; nativeZoomLevels: number;
extraZoomLevels: number; extraZoomLevels: number;
tileUpdateInterval?: number;
} }
export default class LiveAtlasMapDefinition { export default class LiveAtlasMapDefinition {
@ -52,6 +53,7 @@ export default class LiveAtlasMapDefinition {
readonly nativeZoomLevels: number; readonly nativeZoomLevels: number;
readonly extraZoomLevels: number; readonly extraZoomLevels: number;
readonly scale: number; readonly scale: number;
readonly tileUpdateInterval?: number;
constructor(options: LiveAtlasMapDefinitionOptions) { constructor(options: LiveAtlasMapDefinitionOptions) {
this.world = options.world; //Ignore append_to_world here otherwise things break this.world = options.world; //Ignore append_to_world here otherwise things break
@ -71,6 +73,7 @@ export default class LiveAtlasMapDefinition {
this.nativeZoomLevels = options.nativeZoomLevels || 1; this.nativeZoomLevels = options.nativeZoomLevels || 1;
this.extraZoomLevels = options.extraZoomLevels || 0; this.extraZoomLevels = options.extraZoomLevels || 0;
this.scale = (1 / Math.pow(2, this.nativeZoomLevels)); this.scale = (1 / Math.pow(2, this.nativeZoomLevels));
this.tileUpdateInterval = options.tileUpdateInterval || undefined;
if(options.mapToWorld || options.worldToMap) { if(options.mapToWorld || options.worldToMap) {
this.projection = new LiveAtlasProjection({ this.projection = new LiveAtlasProjection({

View File

@ -127,6 +127,7 @@ export default class Pl3xmapMapProvider extends MapProvider {
nativeZoomLevels: worldResponse.zoom.max || 1, nativeZoomLevels: worldResponse.zoom.max || 1,
extraZoomLevels: worldResponse.zoom.extra || 0, extraZoomLevels: worldResponse.zoom.extra || 0,
tileUpdateInterval: worldResponse.tiles_update_interval ? worldResponse.tiles_update_interval * 1000 : undefined,
}))); })));
worlds.push({ worlds.push({