From 50aba2dd7b4a6e950600c50ec3246f3b8d8bfedf Mon Sep 17 00:00:00 2001 From: James Lyne Date: Wed, 23 Feb 2022 00:42:53 +0000 Subject: [PATCH] MapProvider changes - Add populateMap method to allow reacting to the current map changes - populateWorld, startUpdates and stopUpdates are no longer abstract --- src/components/Map.vue | 34 ++++++++++++++++++++-------------- src/index.d.ts | 3 ++- src/providers/MapProvider.ts | 12 +++++++----- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/components/Map.vue b/src/components/Map.vue index 547f0bf..be7aa1f 100644 --- a/src/components/Map.vue +++ b/src/components/Map.vue @@ -149,22 +149,28 @@ export default defineComponent({ deep: true }, currentMap(newValue, oldValue) { - if(this.leaflet && newValue) { - let viewTarget = this.scheduledView; + const store = useStore(); - if(!viewTarget && oldValue) { - viewTarget = {location: oldValue.latLngToLocation(this.leaflet.getCenter(), 64) as LiveAtlasLocation}; - } else if(!viewTarget) { - viewTarget = {location: {x: 0, y: 0, z: 0} as LiveAtlasLocation}; + if(newValue) { + store.state.currentMapProvider!.populateMap(newValue); + + if(this.leaflet) { + let viewTarget = this.scheduledView; + + if(!viewTarget && oldValue) { + viewTarget = {location: oldValue.latLngToLocation(this.leaflet.getCenter(), 64) as LiveAtlasLocation}; + } else if(!viewTarget) { + viewTarget = {location: {x: 0, y: 0, z: 0} as LiveAtlasLocation}; + } + + viewTarget.options = { + animate: false, + noMoveStart: false, + } + + this.setView(viewTarget); + this.scheduledView = null; } - - viewTarget.options = { - animate: false, - noMoveStart: false, - } - - this.setView(viewTarget); - this.scheduledView = null; } }, currentWorld(newValue, oldValue) { diff --git a/src/index.d.ts b/src/index.d.ts index 297fde3..f35b241 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -30,7 +30,7 @@ import {ClockControlOptions} from "@/leaflet/control/ClockControl"; import {LogoControlOptions} from "@/leaflet/control/LogoControl"; import {globalMessages, serverMessages} from "../messages"; import {LiveAtlasMarkerType} from "@/util/markers"; -import {LiveAtlasTileLayerOptions} from "@/leaflet/tileLayer/LiveAtlasTileLayer"; +import {LiveAtlasTileLayer, LiveAtlasTileLayerOptions} from "@/leaflet/tileLayer/LiveAtlasTileLayer"; declare module "*.png" { const value: any; @@ -183,6 +183,7 @@ interface LiveAtlasParsedUrl { interface LiveAtlasMapProvider { loadServerConfiguration(): Promise; populateWorld(world: LiveAtlasWorldDefinition): Promise; + populateMap(map: LiveAtlasMapDefinition): Promise; startUpdates(): void; stopUpdates(): void; createTileLayer(options: LiveAtlasTileLayerOptions): LiveAtlasTileLayer; diff --git a/src/providers/MapProvider.ts b/src/providers/MapProvider.ts index a81a681..2a8b0a4 100644 --- a/src/providers/MapProvider.ts +++ b/src/providers/MapProvider.ts @@ -15,12 +15,12 @@ */ import { - HeadQueueEntry, LiveAtlasMapProvider, LiveAtlasWorldDefinition } from "@/index"; import {useStore} from "@/store"; import {LiveAtlasTileLayer, LiveAtlasTileLayerOptions} from "@/leaflet/tileLayer/LiveAtlasTileLayer"; +import LiveAtlasMapDefinition from "@/model/LiveAtlasMapDefinition"; export default abstract class MapProvider implements LiveAtlasMapProvider { protected readonly store = useStore(); @@ -31,15 +31,17 @@ export default abstract class MapProvider implements LiveAtlasMapProvider { } abstract loadServerConfiguration(): Promise; - abstract populateWorld(world: LiveAtlasWorldDefinition): Promise; abstract createTileLayer(options: LiveAtlasTileLayerOptions): LiveAtlasTileLayer; - abstract startUpdates(): void; - abstract stopUpdates(): void; - abstract getTilesUrl(): string; abstract getMarkerIconUrl(icon: string): string; + async populateWorld(world: LiveAtlasWorldDefinition): Promise {} + async populateMap(map: LiveAtlasMapDefinition): Promise {} + + startUpdates(): void {} + stopUpdates(): void {} + sendChatMessage(message: string) { throw new Error('Provider does not support chat'); }