From a15e9d4b7789b9c6f8950411927915d5c2c0399f Mon Sep 17 00:00:00 2001 From: James Lyne Date: Sat, 26 Feb 2022 01:02:56 +0000 Subject: [PATCH] Overviewer overlay layers --- src/providers/OverviewerMapProvider.ts | 72 ++++++++++++++++++++------ 1 file changed, 56 insertions(+), 16 deletions(-) diff --git a/src/providers/OverviewerMapProvider.ts b/src/providers/OverviewerMapProvider.ts index e00da44..9053b55 100644 --- a/src/providers/OverviewerMapProvider.ts +++ b/src/providers/OverviewerMapProvider.ts @@ -24,7 +24,7 @@ import { LiveAtlasMarker, LiveAtlasMarkerSet, LiveAtlasPointMarker, LiveAtlasServerConfig, - LiveAtlasServerMessageConfig, + LiveAtlasServerMessageConfig, LiveAtlasTileLayerOverlay, LiveAtlasWorldDefinition } from "@/index"; import {MutationTypes} from "@/store/mutation-types"; @@ -87,7 +87,8 @@ export default class OverviewerMapProvider extends MapProvider { } private buildWorlds(serverResponse: any): Array { - const worlds: Map = new Map(); + const tileSize = serverResponse.CONST.tileSize, + worlds: Map = new Map(); (serverResponse.worlds || []).forEach((world: string) => { worlds.set(world, { @@ -106,21 +107,26 @@ export default class OverviewerMapProvider extends MapProvider { return; } - if(tileset?.isOverlay) { + const world = worlds.get(tileset.world) as LiveAtlasWorldDefinition, + baseUrl = `${this.config}${tileset.base}/${tileset.path}`, + prefix = tileset.base, + imageFormat = tileset.imgextension, + nativeZoomLevels = tileset.zoomLevels, + minZoom = tileset.minZoom, + maxZoom = tileset.maxZoom; + + //Ignore overlays until all map definitions have been created + if(tileset.isOverlay) { return; } - const world = worlds.get(tileset.world) as LiveAtlasWorldDefinition, - nativeZoomLevels = tileset.zoomLevels, - tileSize = serverResponse.CONST.tileSize; - world.maps.add(new LiveAtlasMapDefinition({ world, name: tileset.path, displayName: tileset.name || tileset.path, - baseUrl: `${this.config}${tileset.base}/${tileset.path}`, + baseUrl, tileSize, projection: new OverviewerProjection({ upperRight: serverResponse.CONST.UPPERRIGHT, @@ -130,21 +136,23 @@ export default class OverviewerMapProvider extends MapProvider { nativeZoomLevels, tileSize, }), - prefix: tileset.base, + prefix, background: tileset.bgcolor, - imageFormat: tileset.imgextension, + imageFormat, nativeZoomLevels, - minZoom: tileset.minZoom, - maxZoom: tileset.maxZoom, + minZoom, + maxZoom, defaultZoom: tileset.defaultZoom, center: { x: tileset?.center[0] || 0, y: tileset?.center[1] || 64, z: tileset?.center[2] || 0, - } + }, + + overlays: new Map(), })); //Spawn marker @@ -169,9 +177,9 @@ export default class OverviewerMapProvider extends MapProvider { iconAnchor: [15, 33], tooltip: 'Spawn', location: { - x: tileset.spawn[0], - y: tileset.spawn[1], - z: tileset.spawn[2], + x: tileset.spawn[0] || 0, + y: tileset.spawn[1] || 64, + z: tileset.spawn[2] || 0, } } as LiveAtlasPointMarker); @@ -183,6 +191,38 @@ export default class OverviewerMapProvider extends MapProvider { }); + //Loop over tilesets again to handle overlays and add them to relevant maps + (serverResponse.tilesets || []).forEach((tileset: any) => { + if(!tileset.isOverlay) { + return; + } + + const overlay: LiveAtlasTileLayerOverlay = { + id: tileset.path, + label: tileset.name || tileset.path, + hidden: true, + priority: 0, + tileLayerOptions: { + baseUrl: `${this.config}${tileset.base}/${tileset.path}`, + tileSize, + prefix: tileset.base, + imageFormat: tileset.imgextension, + nativeZoomLevels: tileset.zoomLevels, + minZoom: tileset.minZoom, + maxZoom: tileset.maxZoom, + } + }; + + //Add to listed maps, or all maps in defined world if no maps are listed + (worlds.get(tileset.world)?.maps || []).forEach(map => { + if(!tileset?.tilesets?.length || tileset.tilesets.includes(map.name)) { + map.overlays.set(tileset.path, overlay); + } + }); + + return; + }); + return Array.from(worlds.values()); }