From 280e0362768364b9c94e77d7ec40a0afd65dbd72 Mon Sep 17 00:00:00 2001 From: James Lyne Date: Fri, 13 Aug 2021 23:51:03 +0100 Subject: [PATCH] Basic support for Pl3xmap tile update interval --- src/components/map/layer/MapLayer.vue | 19 ++++++++++++++++++- src/model/LiveAtlasMapDefinition.ts | 3 +++ src/providers/Pl3xmapMapProvider.ts | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/components/map/layer/MapLayer.vue b/src/components/map/layer/MapLayer.vue index d1e227d..2a70ae3 100644 --- a/src/components/map/layer/MapLayer.vue +++ b/src/components/map/layer/MapLayer.vue @@ -43,7 +43,16 @@ export default defineComponent({ const store = useStore(), 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') { layer = new DynmapTileLayer({ @@ -71,8 +80,16 @@ export default defineComponent({ enableLayer(); } + if(props.map.tileUpdateInterval) { + redrawTimeout = setTimeout(redraw, props.map.tileUpdateInterval); + } + onUnmounted(() => { disableLayer(); + + if(redrawTimeout) { + clearTimeout(redrawTimeout); + } }); }, diff --git a/src/model/LiveAtlasMapDefinition.ts b/src/model/LiveAtlasMapDefinition.ts index bfbc948..8d32a81 100644 --- a/src/model/LiveAtlasMapDefinition.ts +++ b/src/model/LiveAtlasMapDefinition.ts @@ -34,6 +34,7 @@ export interface LiveAtlasMapDefinitionOptions { worldToMap?: [number, number, number, number, number, number, number, number, number]; nativeZoomLevels: number; extraZoomLevels: number; + tileUpdateInterval?: number; } export default class LiveAtlasMapDefinition { @@ -52,6 +53,7 @@ export default class LiveAtlasMapDefinition { readonly nativeZoomLevels: number; readonly extraZoomLevels: number; readonly scale: number; + readonly tileUpdateInterval?: number; constructor(options: LiveAtlasMapDefinitionOptions) { 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.extraZoomLevels = options.extraZoomLevels || 0; this.scale = (1 / Math.pow(2, this.nativeZoomLevels)); + this.tileUpdateInterval = options.tileUpdateInterval || undefined; if(options.mapToWorld || options.worldToMap) { this.projection = new LiveAtlasProjection({ diff --git a/src/providers/Pl3xmapMapProvider.ts b/src/providers/Pl3xmapMapProvider.ts index ceba348..b8c1609 100644 --- a/src/providers/Pl3xmapMapProvider.ts +++ b/src/providers/Pl3xmapMapProvider.ts @@ -127,6 +127,7 @@ export default class Pl3xmapMapProvider extends MapProvider { nativeZoomLevels: worldResponse.zoom.max || 1, extraZoomLevels: worldResponse.zoom.extra || 0, + tileUpdateInterval: worldResponse.tiles_update_interval ? worldResponse.tiles_update_interval * 1000 : undefined, }))); worlds.push({