LiveAtlasMapDefinition cleanup
- Reorganise options for improved readability - Make options with defaults optional - Add baseUrl option for later TileLayer use
This commit is contained in:
parent
c4f2d106bf
commit
1c5351313f
@ -21,20 +21,28 @@ import {ImageFormat} from "dynmap";
|
||||
export interface LiveAtlasMapDefinitionOptions {
|
||||
world: LiveAtlasWorldDefinition;
|
||||
appendedWorld?: LiveAtlasWorldDefinition; // append_to_world
|
||||
|
||||
name: string;
|
||||
displayName?: string;
|
||||
icon?: string;
|
||||
|
||||
baseUrl: string;
|
||||
tileSize: number;
|
||||
imageFormat: ImageFormat;
|
||||
projection?: LiveAtlasProjection;
|
||||
prefix?: string;
|
||||
|
||||
background?: string;
|
||||
nightAndDay?: boolean;
|
||||
backgroundDay?: string;
|
||||
backgroundNight?: string;
|
||||
imageFormat: ImageFormat;
|
||||
tileSize: number;
|
||||
prefix?: string;
|
||||
projection?: LiveAtlasProjection;
|
||||
|
||||
nativeZoomLevels: number;
|
||||
extraZoomLevels: number;
|
||||
extraZoomLevels?: number;
|
||||
minZoom?: number;
|
||||
maxZoom?: number;
|
||||
defaultZoom?: number;
|
||||
|
||||
tileUpdateInterval?: number;
|
||||
center?: Coordinate;
|
||||
}
|
||||
@ -42,47 +50,62 @@ export interface LiveAtlasMapDefinitionOptions {
|
||||
export default class LiveAtlasMapDefinition {
|
||||
readonly world: LiveAtlasWorldDefinition;
|
||||
readonly appendedWorld?: LiveAtlasWorldDefinition;
|
||||
|
||||
readonly name: string;
|
||||
readonly icon?: string;
|
||||
readonly displayName: string;
|
||||
readonly background: string;
|
||||
readonly nightAndDay: boolean;
|
||||
readonly backgroundDay?: string;
|
||||
readonly backgroundNight?: string;
|
||||
readonly icon?: string;
|
||||
|
||||
readonly baseUrl: string;
|
||||
readonly imageFormat: ImageFormat;
|
||||
readonly tileSize: number;
|
||||
readonly prefix: string;
|
||||
readonly projection?: LiveAtlasProjection;
|
||||
readonly prefix: string;
|
||||
|
||||
readonly background: string;
|
||||
readonly nightAndDay: boolean;
|
||||
readonly backgroundDay: string;
|
||||
readonly backgroundNight: string;
|
||||
|
||||
readonly nativeZoomLevels: number;
|
||||
readonly extraZoomLevels: number;
|
||||
readonly minZoom: number;
|
||||
readonly maxZoom?: number;
|
||||
readonly defaultZoom?: number;
|
||||
readonly scale: number;
|
||||
|
||||
readonly tileUpdateInterval?: number;
|
||||
readonly center?: Coordinate;
|
||||
|
||||
readonly scale: number;
|
||||
|
||||
constructor(options: LiveAtlasMapDefinitionOptions) {
|
||||
this.world = options.world;
|
||||
this.appendedWorld = options.appendedWorld; // append_to_world
|
||||
|
||||
this.name = options.name;
|
||||
this.icon = options.icon || undefined;
|
||||
this.displayName = options.displayName || '';
|
||||
this.icon = options.icon || undefined;
|
||||
|
||||
this.background = options.background || '#000000';
|
||||
this.nightAndDay = options.nightAndDay || false;
|
||||
this.backgroundDay = options.backgroundDay || '#000000';
|
||||
this.backgroundNight = options.backgroundNight || '#000000';
|
||||
|
||||
this.baseUrl = options.baseUrl;
|
||||
this.imageFormat = options.imageFormat;
|
||||
this.tileSize = options.tileSize;
|
||||
this.prefix = options.prefix || '';
|
||||
this.projection = options.projection || undefined;
|
||||
this.prefix = options.prefix || '';
|
||||
|
||||
this.nativeZoomLevels = options.nativeZoomLevels || 1;
|
||||
this.extraZoomLevels = options.extraZoomLevels || 0;
|
||||
this.defaultZoom = options.defaultZoom || 0;
|
||||
this.scale = (1 / Math.pow(2, this.nativeZoomLevels));
|
||||
this.minZoom = options.minZoom || 0;
|
||||
this.maxZoom = options.maxZoom || undefined;
|
||||
this.defaultZoom = options.defaultZoom || undefined;
|
||||
|
||||
this.tileUpdateInterval = options.tileUpdateInterval || undefined;
|
||||
this.center = options.center || undefined;
|
||||
|
||||
this.scale = (1 / Math.pow(2, this.nativeZoomLevels));
|
||||
}
|
||||
|
||||
locationToLatLng(location: Coordinate): LatLng {
|
||||
|
@ -141,7 +141,7 @@ export default class DynmapMapProvider extends MapProvider {
|
||||
this.store.commit(MutationTypes.SET_SERVER_CONFIGURATION_HASH, response.confighash || 0);
|
||||
this.store.commit(MutationTypes.SET_MAX_PLAYERS, response.maxcount || 0);
|
||||
this.store.commit(MutationTypes.SET_SERVER_MESSAGES, buildMessagesConfig(response));
|
||||
this.store.commit(MutationTypes.SET_WORLDS, buildWorlds(response));
|
||||
this.store.commit(MutationTypes.SET_WORLDS, buildWorlds(response, this.config));
|
||||
this.store.commit(MutationTypes.SET_COMPONENTS, buildComponents(response, this.config));
|
||||
this.store.commit(MutationTypes.SET_LOGGED_IN, response.loggedin || false);
|
||||
}
|
||||
|
@ -115,15 +115,12 @@ export default class OverviewerMapProvider extends MapProvider {
|
||||
|
||||
world.maps.add(new LiveAtlasMapDefinition({
|
||||
world,
|
||||
|
||||
name: tileset.path,
|
||||
displayName: tileset.name || tileset.path,
|
||||
background: tileset.bgcolor,
|
||||
imageFormat: tileset.imgextension,
|
||||
nativeZoomLevels,
|
||||
extraZoomLevels: 0,
|
||||
defaultZoom: tileset.defaultZoom,
|
||||
|
||||
baseUrl: this.config,
|
||||
tileSize,
|
||||
prefix: tileset.base,
|
||||
projection: new OverviewerProjection({
|
||||
upperRight: serverResponse.CONST.UPPERRIGHT,
|
||||
lowerLeft: serverResponse.CONST.LOWERLEFT,
|
||||
@ -132,9 +129,19 @@ export default class OverviewerMapProvider extends MapProvider {
|
||||
nativeZoomLevels,
|
||||
tileSize,
|
||||
}),
|
||||
prefix: tileset.base,
|
||||
|
||||
background: tileset.bgcolor,
|
||||
imageFormat: tileset.imgextension,
|
||||
|
||||
nativeZoomLevels,
|
||||
minZoom: tileset.minZoom,
|
||||
maxZoom: tileset.maxZoom,
|
||||
defaultZoom: tileset.defaultZoom,
|
||||
|
||||
center: {
|
||||
x: tileset?.center[0] || 0,
|
||||
y: tileset?.center[1] || 0,
|
||||
y: tileset?.center[1] || 64,
|
||||
z: tileset?.center[2] || 0,
|
||||
}
|
||||
}));
|
||||
|
@ -183,17 +183,20 @@ export default class Pl3xmapMapProvider extends MapProvider {
|
||||
maps.add(Object.freeze(new LiveAtlasMapDefinition({
|
||||
world: w,
|
||||
|
||||
name: 'flat',
|
||||
displayName: 'Flat',
|
||||
icon: world.icon ? `${this.config}images/icon/${world.icon}.png` : undefined,
|
||||
|
||||
baseUrl: `${this.config}tiles/`,
|
||||
imageFormat: 'png',
|
||||
tileSize: 512,
|
||||
|
||||
background: 'transparent',
|
||||
backgroundDay: 'transparent',
|
||||
backgroundNight: 'transparent',
|
||||
icon: world.icon ? `${this.config}images/icon/${world.icon}.png` : undefined,
|
||||
imageFormat: 'png',
|
||||
tileSize: 512,
|
||||
name: 'flat',
|
||||
displayName: 'Flat',
|
||||
|
||||
nativeZoomLevels: worldResponse.zoom.max || 1,
|
||||
extraZoomLevels: worldResponse.zoom.extra || 0,
|
||||
extraZoomLevels: worldResponse.zoom.extra,
|
||||
tileUpdateInterval: worldResponse.tiles_update_interval ? worldResponse.tiles_update_interval * 1000 : undefined,
|
||||
})));
|
||||
|
||||
|
@ -91,7 +91,7 @@ export function buildMessagesConfig(response: Options): LiveAtlasServerMessageCo
|
||||
}
|
||||
}
|
||||
|
||||
export function buildWorlds(response: Configuration): Array<LiveAtlasWorldDefinition> {
|
||||
export function buildWorlds(response: Configuration, config: DynmapUrlConfig): Array<LiveAtlasWorldDefinition> {
|
||||
const worlds: Map<string, LiveAtlasWorldDefinition> = new Map<string, LiveAtlasWorldDefinition>();
|
||||
|
||||
//Get all the worlds first so we can handle append_to_world properly
|
||||
@ -138,24 +138,29 @@ export function buildWorlds(response: Configuration): Array<LiveAtlasWorldDefini
|
||||
const mapDef = Object.freeze(new LiveAtlasMapDefinition({
|
||||
world: actualWorld,
|
||||
appendedWorld: actualWorld !== assignedWorld ? assignedWorld : undefined,
|
||||
background: map.background || '#000000',
|
||||
backgroundDay: map.backgroundday || '#000000',
|
||||
backgroundNight: map.backgroundnight || '#000000',
|
||||
|
||||
name: map.name || '(Unnamed map)',
|
||||
displayName: map.title,
|
||||
icon: (map.icon || undefined) as string | undefined,
|
||||
|
||||
baseUrl: config.tiles,
|
||||
imageFormat: map['image-format'] || 'png',
|
||||
tileSize,
|
||||
name: map.name || '(Unnamed map)',
|
||||
nightAndDay: map.nightandday || false,
|
||||
prefix: map.prefix || '',
|
||||
displayName: map.title || '',
|
||||
projection: new DynmapProjection({
|
||||
mapToWorld: map.maptoworld || undefined,
|
||||
worldToMap: map.worldtomap || undefined,
|
||||
nativeZoomLevels,
|
||||
tileSize,
|
||||
}),
|
||||
prefix: map.prefix || '',
|
||||
|
||||
background: map.background || '#000000',
|
||||
nightAndDay: map.nightandday,
|
||||
backgroundDay: map.backgroundday || '#000000',
|
||||
backgroundNight: map.backgroundnight || '#000000',
|
||||
|
||||
nativeZoomLevels,
|
||||
extraZoomLevels: map.mapzoomin || 0
|
||||
extraZoomLevels: map.mapzoomin
|
||||
})) as LiveAtlasMapDefinition;
|
||||
|
||||
actualWorld.maps.add(mapDef);
|
||||
|
Loading…
Reference in New Issue
Block a user