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 {
|
export interface LiveAtlasMapDefinitionOptions {
|
||||||
world: LiveAtlasWorldDefinition;
|
world: LiveAtlasWorldDefinition;
|
||||||
appendedWorld?: LiveAtlasWorldDefinition; // append_to_world
|
appendedWorld?: LiveAtlasWorldDefinition; // append_to_world
|
||||||
|
|
||||||
name: string;
|
name: string;
|
||||||
displayName?: string;
|
displayName?: string;
|
||||||
icon?: string;
|
icon?: string;
|
||||||
|
|
||||||
|
baseUrl: string;
|
||||||
|
tileSize: number;
|
||||||
|
imageFormat: ImageFormat;
|
||||||
|
projection?: LiveAtlasProjection;
|
||||||
|
prefix?: string;
|
||||||
|
|
||||||
background?: string;
|
background?: string;
|
||||||
nightAndDay?: boolean;
|
nightAndDay?: boolean;
|
||||||
backgroundDay?: string;
|
backgroundDay?: string;
|
||||||
backgroundNight?: string;
|
backgroundNight?: string;
|
||||||
imageFormat: ImageFormat;
|
|
||||||
tileSize: number;
|
|
||||||
prefix?: string;
|
|
||||||
projection?: LiveAtlasProjection;
|
|
||||||
nativeZoomLevels: number;
|
nativeZoomLevels: number;
|
||||||
extraZoomLevels: number;
|
extraZoomLevels?: number;
|
||||||
|
minZoom?: number;
|
||||||
|
maxZoom?: number;
|
||||||
defaultZoom?: number;
|
defaultZoom?: number;
|
||||||
|
|
||||||
tileUpdateInterval?: number;
|
tileUpdateInterval?: number;
|
||||||
center?: Coordinate;
|
center?: Coordinate;
|
||||||
}
|
}
|
||||||
@ -42,47 +50,62 @@ export interface LiveAtlasMapDefinitionOptions {
|
|||||||
export default class LiveAtlasMapDefinition {
|
export default class LiveAtlasMapDefinition {
|
||||||
readonly world: LiveAtlasWorldDefinition;
|
readonly world: LiveAtlasWorldDefinition;
|
||||||
readonly appendedWorld?: LiveAtlasWorldDefinition;
|
readonly appendedWorld?: LiveAtlasWorldDefinition;
|
||||||
|
|
||||||
readonly name: string;
|
readonly name: string;
|
||||||
readonly icon?: string;
|
|
||||||
readonly displayName: string;
|
readonly displayName: string;
|
||||||
readonly background: string;
|
readonly icon?: string;
|
||||||
readonly nightAndDay: boolean;
|
|
||||||
readonly backgroundDay?: string;
|
readonly baseUrl: string;
|
||||||
readonly backgroundNight?: string;
|
|
||||||
readonly imageFormat: ImageFormat;
|
readonly imageFormat: ImageFormat;
|
||||||
readonly tileSize: number;
|
readonly tileSize: number;
|
||||||
readonly prefix: string;
|
|
||||||
readonly projection?: LiveAtlasProjection;
|
readonly projection?: LiveAtlasProjection;
|
||||||
|
readonly prefix: string;
|
||||||
|
|
||||||
|
readonly background: string;
|
||||||
|
readonly nightAndDay: boolean;
|
||||||
|
readonly backgroundDay: string;
|
||||||
|
readonly backgroundNight: string;
|
||||||
|
|
||||||
readonly nativeZoomLevels: number;
|
readonly nativeZoomLevels: number;
|
||||||
readonly extraZoomLevels: number;
|
readonly extraZoomLevels: number;
|
||||||
|
readonly minZoom: number;
|
||||||
|
readonly maxZoom?: number;
|
||||||
readonly defaultZoom?: number;
|
readonly defaultZoom?: number;
|
||||||
readonly scale: number;
|
|
||||||
readonly tileUpdateInterval?: number;
|
readonly tileUpdateInterval?: number;
|
||||||
readonly center?: Coordinate;
|
readonly center?: Coordinate;
|
||||||
|
|
||||||
|
readonly scale: number;
|
||||||
|
|
||||||
constructor(options: LiveAtlasMapDefinitionOptions) {
|
constructor(options: LiveAtlasMapDefinitionOptions) {
|
||||||
this.world = options.world;
|
this.world = options.world;
|
||||||
this.appendedWorld = options.appendedWorld; // append_to_world
|
this.appendedWorld = options.appendedWorld; // append_to_world
|
||||||
|
|
||||||
this.name = options.name;
|
this.name = options.name;
|
||||||
this.icon = options.icon || undefined;
|
|
||||||
this.displayName = options.displayName || '';
|
this.displayName = options.displayName || '';
|
||||||
|
this.icon = options.icon || undefined;
|
||||||
|
|
||||||
this.background = options.background || '#000000';
|
this.background = options.background || '#000000';
|
||||||
this.nightAndDay = options.nightAndDay || false;
|
this.nightAndDay = options.nightAndDay || false;
|
||||||
this.backgroundDay = options.backgroundDay || '#000000';
|
this.backgroundDay = options.backgroundDay || '#000000';
|
||||||
this.backgroundNight = options.backgroundNight || '#000000';
|
this.backgroundNight = options.backgroundNight || '#000000';
|
||||||
|
|
||||||
|
this.baseUrl = options.baseUrl;
|
||||||
this.imageFormat = options.imageFormat;
|
this.imageFormat = options.imageFormat;
|
||||||
this.tileSize = options.tileSize;
|
this.tileSize = options.tileSize;
|
||||||
this.prefix = options.prefix || '';
|
|
||||||
this.projection = options.projection || undefined;
|
this.projection = options.projection || undefined;
|
||||||
|
this.prefix = options.prefix || '';
|
||||||
|
|
||||||
this.nativeZoomLevels = options.nativeZoomLevels || 1;
|
this.nativeZoomLevels = options.nativeZoomLevels || 1;
|
||||||
this.extraZoomLevels = options.extraZoomLevels || 0;
|
this.extraZoomLevels = options.extraZoomLevels || 0;
|
||||||
this.defaultZoom = options.defaultZoom || 0;
|
this.minZoom = options.minZoom || 0;
|
||||||
this.scale = (1 / Math.pow(2, this.nativeZoomLevels));
|
this.maxZoom = options.maxZoom || undefined;
|
||||||
|
this.defaultZoom = options.defaultZoom || undefined;
|
||||||
|
|
||||||
this.tileUpdateInterval = options.tileUpdateInterval || undefined;
|
this.tileUpdateInterval = options.tileUpdateInterval || undefined;
|
||||||
this.center = options.center || undefined;
|
this.center = options.center || undefined;
|
||||||
|
|
||||||
|
this.scale = (1 / Math.pow(2, this.nativeZoomLevels));
|
||||||
}
|
}
|
||||||
|
|
||||||
locationToLatLng(location: Coordinate): LatLng {
|
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_SERVER_CONFIGURATION_HASH, response.confighash || 0);
|
||||||
this.store.commit(MutationTypes.SET_MAX_PLAYERS, response.maxcount || 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_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_COMPONENTS, buildComponents(response, this.config));
|
||||||
this.store.commit(MutationTypes.SET_LOGGED_IN, response.loggedin || false);
|
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.maps.add(new LiveAtlasMapDefinition({
|
||||||
world,
|
world,
|
||||||
|
|
||||||
name: tileset.path,
|
name: tileset.path,
|
||||||
displayName: tileset.name || tileset.path,
|
displayName: tileset.name || tileset.path,
|
||||||
background: tileset.bgcolor,
|
|
||||||
imageFormat: tileset.imgextension,
|
baseUrl: this.config,
|
||||||
nativeZoomLevels,
|
|
||||||
extraZoomLevels: 0,
|
|
||||||
defaultZoom: tileset.defaultZoom,
|
|
||||||
tileSize,
|
tileSize,
|
||||||
prefix: tileset.base,
|
|
||||||
projection: new OverviewerProjection({
|
projection: new OverviewerProjection({
|
||||||
upperRight: serverResponse.CONST.UPPERRIGHT,
|
upperRight: serverResponse.CONST.UPPERRIGHT,
|
||||||
lowerLeft: serverResponse.CONST.LOWERLEFT,
|
lowerLeft: serverResponse.CONST.LOWERLEFT,
|
||||||
@ -132,9 +129,19 @@ export default class OverviewerMapProvider extends MapProvider {
|
|||||||
nativeZoomLevels,
|
nativeZoomLevels,
|
||||||
tileSize,
|
tileSize,
|
||||||
}),
|
}),
|
||||||
|
prefix: tileset.base,
|
||||||
|
|
||||||
|
background: tileset.bgcolor,
|
||||||
|
imageFormat: tileset.imgextension,
|
||||||
|
|
||||||
|
nativeZoomLevels,
|
||||||
|
minZoom: tileset.minZoom,
|
||||||
|
maxZoom: tileset.maxZoom,
|
||||||
|
defaultZoom: tileset.defaultZoom,
|
||||||
|
|
||||||
center: {
|
center: {
|
||||||
x: tileset?.center[0] || 0,
|
x: tileset?.center[0] || 0,
|
||||||
y: tileset?.center[1] || 0,
|
y: tileset?.center[1] || 64,
|
||||||
z: tileset?.center[2] || 0,
|
z: tileset?.center[2] || 0,
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
@ -183,17 +183,20 @@ export default class Pl3xmapMapProvider extends MapProvider {
|
|||||||
maps.add(Object.freeze(new LiveAtlasMapDefinition({
|
maps.add(Object.freeze(new LiveAtlasMapDefinition({
|
||||||
world: w,
|
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',
|
background: 'transparent',
|
||||||
backgroundDay: 'transparent',
|
backgroundDay: 'transparent',
|
||||||
backgroundNight: '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,
|
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,
|
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>();
|
const worlds: Map<string, LiveAtlasWorldDefinition> = new Map<string, LiveAtlasWorldDefinition>();
|
||||||
|
|
||||||
//Get all the worlds first so we can handle append_to_world properly
|
//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({
|
const mapDef = Object.freeze(new LiveAtlasMapDefinition({
|
||||||
world: actualWorld,
|
world: actualWorld,
|
||||||
appendedWorld: actualWorld !== assignedWorld ? assignedWorld : undefined,
|
appendedWorld: actualWorld !== assignedWorld ? assignedWorld : undefined,
|
||||||
background: map.background || '#000000',
|
|
||||||
backgroundDay: map.backgroundday || '#000000',
|
name: map.name || '(Unnamed map)',
|
||||||
backgroundNight: map.backgroundnight || '#000000',
|
displayName: map.title,
|
||||||
icon: (map.icon || undefined) as string | undefined,
|
icon: (map.icon || undefined) as string | undefined,
|
||||||
|
|
||||||
|
baseUrl: config.tiles,
|
||||||
imageFormat: map['image-format'] || 'png',
|
imageFormat: map['image-format'] || 'png',
|
||||||
tileSize,
|
tileSize,
|
||||||
name: map.name || '(Unnamed map)',
|
|
||||||
nightAndDay: map.nightandday || false,
|
|
||||||
prefix: map.prefix || '',
|
|
||||||
displayName: map.title || '',
|
|
||||||
projection: new DynmapProjection({
|
projection: new DynmapProjection({
|
||||||
mapToWorld: map.maptoworld || undefined,
|
mapToWorld: map.maptoworld || undefined,
|
||||||
worldToMap: map.worldtomap || undefined,
|
worldToMap: map.worldtomap || undefined,
|
||||||
nativeZoomLevels,
|
nativeZoomLevels,
|
||||||
tileSize,
|
tileSize,
|
||||||
}),
|
}),
|
||||||
|
prefix: map.prefix || '',
|
||||||
|
|
||||||
|
background: map.background || '#000000',
|
||||||
|
nightAndDay: map.nightandday,
|
||||||
|
backgroundDay: map.backgroundday || '#000000',
|
||||||
|
backgroundNight: map.backgroundnight || '#000000',
|
||||||
|
|
||||||
nativeZoomLevels,
|
nativeZoomLevels,
|
||||||
extraZoomLevels: map.mapzoomin || 0
|
extraZoomLevels: map.mapzoomin
|
||||||
})) as LiveAtlasMapDefinition;
|
})) as LiveAtlasMapDefinition;
|
||||||
|
|
||||||
actualWorld.maps.add(mapDef);
|
actualWorld.maps.add(mapDef);
|
||||||
|
Loading…
Reference in New Issue
Block a user