Support dynmap tilescale

This commit is contained in:
James Lyne 2022-02-17 19:38:03 +00:00
parent af8f197a3e
commit dfcaa6bf42
7 changed files with 21 additions and 7 deletions

6
src/dynmap.d.ts vendored
View File

@ -29,6 +29,12 @@ declare global {
} }
} }
declare module 'dynmap' {
interface WorldMapConfiguration {
tilescale?: number;
}
}
type DynmapUrlConfig = { type DynmapUrlConfig = {
configuration: string; configuration: string;
update: string; update: string;

View File

@ -56,7 +56,7 @@ export abstract class LiveAtlasTileLayer extends TileLayer {
options.maxZoom = this._mapSettings.nativeZoomLevels + this._mapSettings.extraZoomLevels; options.maxZoom = this._mapSettings.nativeZoomLevels + this._mapSettings.extraZoomLevels;
options.maxNativeZoom = this._mapSettings.nativeZoomLevels; options.maxNativeZoom = this._mapSettings.nativeZoomLevels;
options.zoomReverse = true; options.zoomReverse = true;
options.tileSize = 128; options.tileSize = this._mapSettings.tileSize;
options.minZoom = 0; options.minZoom = 0;
Util.setOptions(this, options); Util.setOptions(this, options);

View File

@ -26,7 +26,6 @@ export class Pl3xmapTileLayer extends LiveAtlasTileLayer {
super(`${baseUrl}${worldName}/{z}/{x}_{y}.png`, options); super(`${baseUrl}${worldName}/{z}/{x}_{y}.png`, options);
options.tileSize = 512;
options.zoomReverse = false; options.zoomReverse = false;
Util.setOptions(this, options); Util.setOptions(this, options);

View File

@ -30,6 +30,7 @@ export interface LiveAtlasMapDefinitionOptions {
backgroundDay?: string; backgroundDay?: string;
backgroundNight?: string; backgroundNight?: string;
imageFormat: ImageFormat; imageFormat: ImageFormat;
tileSize: number;
prefix?: string; prefix?: string;
mapToWorld?: [number, number, number, number, number, number, number, number, number]; mapToWorld?: [number, number, number, number, number, number, number, number, number];
worldToMap?: [number, number, number, number, number, number, number, number, number]; worldToMap?: [number, number, number, number, number, number, number, number, number];
@ -49,6 +50,7 @@ export default class LiveAtlasMapDefinition {
readonly backgroundDay?: string; readonly backgroundDay?: string;
readonly backgroundNight?: string; readonly backgroundNight?: string;
readonly imageFormat: ImageFormat; readonly imageFormat: ImageFormat;
readonly tileSize: number;
readonly prefix: string; readonly prefix: string;
private readonly projection?: Readonly<LiveAtlasProjection>; private readonly projection?: Readonly<LiveAtlasProjection>;
readonly nativeZoomLevels: number; readonly nativeZoomLevels: number;
@ -69,6 +71,7 @@ export default class LiveAtlasMapDefinition {
this.backgroundNight = options.backgroundNight || '#000000'; this.backgroundNight = options.backgroundNight || '#000000';
this.imageFormat = options.imageFormat; this.imageFormat = options.imageFormat;
this.tileSize = options.tileSize;
this.prefix = options.prefix || ''; this.prefix = options.prefix || '';
this.nativeZoomLevels = options.nativeZoomLevels || 1; this.nativeZoomLevels = options.nativeZoomLevels || 1;
@ -81,6 +84,7 @@ export default class LiveAtlasMapDefinition {
mapToWorld: options.mapToWorld || [0, 0, 0, 0, 0, 0, 0, 0, 0], mapToWorld: options.mapToWorld || [0, 0, 0, 0, 0, 0, 0, 0, 0],
worldToMap: options.worldToMap || [0, 0, 0, 0, 0, 0, 0, 0, 0], worldToMap: options.worldToMap || [0, 0, 0, 0, 0, 0, 0, 0, 0],
nativeZoomLevels: this.nativeZoomLevels, nativeZoomLevels: this.nativeZoomLevels,
tileSize: this.tileSize
}); });
} }
} }

View File

@ -23,18 +23,21 @@ import {Coordinate} from "@/index";
export interface LiveAtlasProjectionOptions { export interface LiveAtlasProjectionOptions {
mapToWorld: [number, number, number, number, number, number, number, number, number], mapToWorld: [number, number, number, number, number, number, number, number, number],
worldToMap: [number, number, number, number, number, number, number, number, number], worldToMap: [number, number, number, number, number, number, number, number, number],
nativeZoomLevels: number nativeZoomLevels: number,
tileSize: number,
} }
export class LiveAtlasProjection { export class LiveAtlasProjection {
private readonly mapToWorld: [number, number, number, number, number, number, number, number, number]; private readonly mapToWorld: [number, number, number, number, number, number, number, number, number];
private readonly worldToMap: [number, number, number, number, number, number, number, number, number]; private readonly worldToMap: [number, number, number, number, number, number, number, number, number];
private readonly nativeZoomLevels: number; private readonly nativeZoomLevels: number;
private readonly tileSize: number;
constructor(options: LiveAtlasProjectionOptions) { constructor(options: LiveAtlasProjectionOptions) {
this.mapToWorld = options.mapToWorld || [0, 0, 0, 0, 0, 0, 0, 0]; this.mapToWorld = options.mapToWorld || [0, 0, 0, 0, 0, 0, 0, 0];
this.worldToMap = options.worldToMap || [0, 0, 0, 0, 0, 0, 0, 0]; this.worldToMap = options.worldToMap || [0, 0, 0, 0, 0, 0, 0, 0];
this.nativeZoomLevels = options.nativeZoomLevels || 1; this.nativeZoomLevels = options.nativeZoomLevels || 1;
this.tileSize = options.tileSize;
} }
locationToLatLng(location: Coordinate): LatLng { locationToLatLng(location: Coordinate): LatLng {
@ -43,16 +46,16 @@ export class LiveAtlasProjection {
lng = wtp[0] * location.x + wtp[1] * location.y + wtp[2] * location.z; lng = wtp[0] * location.x + wtp[1] * location.y + wtp[2] * location.z;
return new LatLng( return new LatLng(
-((128 - lat) / (1 << this.nativeZoomLevels)), -((this.tileSize - lat) / (1 << this.nativeZoomLevels)),
lng / (1 << this.nativeZoomLevels)); lng / (1 << this.nativeZoomLevels));
} }
latLngToLocation(latLng: LatLng, y: number): Coordinate { latLngToLocation(latLng: LatLng, y: number): Coordinate {
const ptw = this.mapToWorld, const ptw = this.mapToWorld,
lon = this.tileSize + latLng.lat * (1 << this.nativeZoomLevels),
lat = latLng.lng * (1 << this.nativeZoomLevels), lat = latLng.lng * (1 << this.nativeZoomLevels),
lon = 128 + latLng.lat * (1 << this.nativeZoomLevels), x = ptw[0] * lon + ptw[1] * lat + ptw[2] * y,
x = ptw[0] * lat + ptw[1] * lon + ptw[2] * y, z = ptw[6] * lon + ptw[7] * lat + ptw[8] * y;
z = ptw[6] * lat + ptw[7] * lon + ptw[8] * y;
return {x: x, y: y, z: z}; return {x: x, y: y, z: z};
} }

View File

@ -188,6 +188,7 @@ export default class Pl3xmapMapProvider extends MapProvider {
backgroundNight: 'transparent', backgroundNight: 'transparent',
icon: world.icon ? `${this.config}images/icon/${world.icon}.png` : undefined, icon: world.icon ? `${this.config}images/icon/${world.icon}.png` : undefined,
imageFormat: 'png', imageFormat: 'png',
tileSize: 512,
name: 'flat', name: 'flat',
displayName: 'Flat', displayName: 'Flat',

View File

@ -136,6 +136,7 @@ export function buildWorlds(response: Configuration): Array<LiveAtlasWorldDefini
backgroundNight: map.backgroundnight || '#000000', backgroundNight: map.backgroundnight || '#000000',
icon: (map.icon || undefined) as string | undefined, icon: (map.icon || undefined) as string | undefined,
imageFormat: map['image-format'] || 'png', imageFormat: map['image-format'] || 'png',
tileSize: 128 << (map.tilescale || 0),
name: map.name || '(Unnamed map)', name: map.name || '(Unnamed map)',
nightAndDay: map.nightandday || false, nightAndDay: map.nightandday || false,
prefix: map.prefix || '', prefix: map.prefix || '',