From dfcaa6bf42f6d8bf71e0e3f93475eaedce74c4ac Mon Sep 17 00:00:00 2001 From: James Lyne Date: Thu, 17 Feb 2022 19:38:03 +0000 Subject: [PATCH] Support dynmap tilescale --- src/dynmap.d.ts | 6 ++++++ src/leaflet/tileLayer/LiveAtlasTileLayer.ts | 2 +- src/leaflet/tileLayer/Pl3xmapTileLayer.ts | 1 - src/model/LiveAtlasMapDefinition.ts | 4 ++++ src/model/LiveAtlasProjection.ts | 13 ++++++++----- src/providers/Pl3xmapMapProvider.ts | 1 + src/util/dynmap.ts | 1 + 7 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/dynmap.d.ts b/src/dynmap.d.ts index faa20fd..af078b2 100644 --- a/src/dynmap.d.ts +++ b/src/dynmap.d.ts @@ -29,6 +29,12 @@ declare global { } } +declare module 'dynmap' { + interface WorldMapConfiguration { + tilescale?: number; + } +} + type DynmapUrlConfig = { configuration: string; update: string; diff --git a/src/leaflet/tileLayer/LiveAtlasTileLayer.ts b/src/leaflet/tileLayer/LiveAtlasTileLayer.ts index 01edcfb..f9f1465 100644 --- a/src/leaflet/tileLayer/LiveAtlasTileLayer.ts +++ b/src/leaflet/tileLayer/LiveAtlasTileLayer.ts @@ -56,7 +56,7 @@ export abstract class LiveAtlasTileLayer extends TileLayer { options.maxZoom = this._mapSettings.nativeZoomLevels + this._mapSettings.extraZoomLevels; options.maxNativeZoom = this._mapSettings.nativeZoomLevels; options.zoomReverse = true; - options.tileSize = 128; + options.tileSize = this._mapSettings.tileSize; options.minZoom = 0; Util.setOptions(this, options); diff --git a/src/leaflet/tileLayer/Pl3xmapTileLayer.ts b/src/leaflet/tileLayer/Pl3xmapTileLayer.ts index 9deff9c..dac3c5b 100644 --- a/src/leaflet/tileLayer/Pl3xmapTileLayer.ts +++ b/src/leaflet/tileLayer/Pl3xmapTileLayer.ts @@ -26,7 +26,6 @@ export class Pl3xmapTileLayer extends LiveAtlasTileLayer { super(`${baseUrl}${worldName}/{z}/{x}_{y}.png`, options); - options.tileSize = 512; options.zoomReverse = false; Util.setOptions(this, options); diff --git a/src/model/LiveAtlasMapDefinition.ts b/src/model/LiveAtlasMapDefinition.ts index 03e14fa..3cbaf3d 100644 --- a/src/model/LiveAtlasMapDefinition.ts +++ b/src/model/LiveAtlasMapDefinition.ts @@ -30,6 +30,7 @@ export interface LiveAtlasMapDefinitionOptions { backgroundDay?: string; backgroundNight?: string; imageFormat: ImageFormat; + tileSize: number; prefix?: string; mapToWorld?: [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 backgroundNight?: string; readonly imageFormat: ImageFormat; + readonly tileSize: number; readonly prefix: string; private readonly projection?: Readonly; readonly nativeZoomLevels: number; @@ -69,6 +71,7 @@ export default class LiveAtlasMapDefinition { this.backgroundNight = options.backgroundNight || '#000000'; this.imageFormat = options.imageFormat; + this.tileSize = options.tileSize; this.prefix = options.prefix || ''; 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], worldToMap: options.worldToMap || [0, 0, 0, 0, 0, 0, 0, 0, 0], nativeZoomLevels: this.nativeZoomLevels, + tileSize: this.tileSize }); } } diff --git a/src/model/LiveAtlasProjection.ts b/src/model/LiveAtlasProjection.ts index 692e1a5..be361ef 100644 --- a/src/model/LiveAtlasProjection.ts +++ b/src/model/LiveAtlasProjection.ts @@ -23,18 +23,21 @@ import {Coordinate} from "@/index"; export interface LiveAtlasProjectionOptions { mapToWorld: [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 { 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 nativeZoomLevels: number; + private readonly tileSize: number; constructor(options: LiveAtlasProjectionOptions) { 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.nativeZoomLevels = options.nativeZoomLevels || 1; + this.tileSize = options.tileSize; } locationToLatLng(location: Coordinate): LatLng { @@ -43,16 +46,16 @@ export class LiveAtlasProjection { lng = wtp[0] * location.x + wtp[1] * location.y + wtp[2] * location.z; return new LatLng( - -((128 - lat) / (1 << this.nativeZoomLevels)), + -((this.tileSize - lat) / (1 << this.nativeZoomLevels)), lng / (1 << this.nativeZoomLevels)); } latLngToLocation(latLng: LatLng, y: number): Coordinate { const ptw = this.mapToWorld, + lon = this.tileSize + latLng.lat * (1 << this.nativeZoomLevels), lat = latLng.lng * (1 << this.nativeZoomLevels), - lon = 128 + latLng.lat * (1 << this.nativeZoomLevels), - x = ptw[0] * lat + ptw[1] * lon + ptw[2] * y, - z = ptw[6] * lat + ptw[7] * lon + ptw[8] * y; + x = ptw[0] * lon + ptw[1] * lat + ptw[2] * y, + z = ptw[6] * lon + ptw[7] * lat + ptw[8] * y; return {x: x, y: y, z: z}; } diff --git a/src/providers/Pl3xmapMapProvider.ts b/src/providers/Pl3xmapMapProvider.ts index 151b3e6..c092b2a 100644 --- a/src/providers/Pl3xmapMapProvider.ts +++ b/src/providers/Pl3xmapMapProvider.ts @@ -188,6 +188,7 @@ export default class Pl3xmapMapProvider extends MapProvider { backgroundNight: 'transparent', icon: world.icon ? `${this.config}images/icon/${world.icon}.png` : undefined, imageFormat: 'png', + tileSize: 512, name: 'flat', displayName: 'Flat', diff --git a/src/util/dynmap.ts b/src/util/dynmap.ts index c88d067..6f70b50 100644 --- a/src/util/dynmap.ts +++ b/src/util/dynmap.ts @@ -136,6 +136,7 @@ export function buildWorlds(response: Configuration): Array