MapProvider changes

- Add populateMap method to allow reacting to  the current map changes
- populateWorld, startUpdates and stopUpdates are no longer abstract
This commit is contained in:
James Lyne 2022-02-23 00:42:53 +00:00
parent 3eb9446a5d
commit 50aba2dd7b
3 changed files with 29 additions and 20 deletions

View File

@ -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) {

3
src/index.d.ts vendored
View File

@ -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<void>;
populateWorld(world: LiveAtlasWorldDefinition): Promise<void>;
populateMap(map: LiveAtlasMapDefinition): Promise<void>;
startUpdates(): void;
stopUpdates(): void;
createTileLayer(options: LiveAtlasTileLayerOptions): LiveAtlasTileLayer;

View File

@ -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<void>;
abstract populateWorld(world: LiveAtlasWorldDefinition): Promise<void>;
abstract createTileLayer(options: LiveAtlasTileLayerOptions): LiveAtlasTileLayer;
abstract startUpdates(): void;
abstract stopUpdates(): void;
abstract getTilesUrl(): string;
abstract getMarkerIconUrl(icon: string): string;
async populateWorld(world: LiveAtlasWorldDefinition): Promise<void> {}
async populateMap(map: LiveAtlasMapDefinition): Promise<void> {}
startUpdates(): void {}
stopUpdates(): void {}
sendChatMessage(message: string) {
throw new Error('Provider does not support chat');
}