diff --git a/src/index.d.ts b/src/index.d.ts index 5e833c3..4d3f468 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -20,7 +20,7 @@ import LiveAtlasMapDefinition from "@/model/LiveAtlasMapDefinition"; import { Coords, DoneCallback, FitBoundsOptions, - InternalTiles, + InternalTiles, LatLng, PathOptions, PointTuple, PolylineOptions @@ -160,6 +160,11 @@ interface LiveAtlasWorldDefinition { maps: Set; } +interface LiveAtlasProjection { + locationToLatLng(location: Coordinate): LatLng; + latLngToLocation(latLng: LatLng, y: number): Coordinate; +} + interface LiveAtlasWorldState { raining: boolean; thundering: boolean; diff --git a/src/model/LiveAtlasProjection.ts b/src/leaflet/projection/DynmapProjection.ts similarity index 91% rename from src/model/LiveAtlasProjection.ts rename to src/leaflet/projection/DynmapProjection.ts index b8006d6..e88a1d7 100644 --- a/src/model/LiveAtlasProjection.ts +++ b/src/leaflet/projection/DynmapProjection.ts @@ -18,22 +18,22 @@ */ import {LatLng} from 'leaflet'; -import {Coordinate} from "@/index"; +import {Coordinate, LiveAtlasProjection} from "@/index"; -export interface LiveAtlasProjectionOptions { +export interface DynmapProjectionOptions { mapToWorld: [number, number, number, number, number, number, number, number, number], worldToMap: [number, number, number, number, number, number, number, number, number], nativeZoomLevels: number, tileSize: number, } -export class LiveAtlasProjection { +export class DynmapProjection implements 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) { + constructor(options: DynmapProjectionOptions) { 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; diff --git a/src/model/LiveAtlasMapDefinition.ts b/src/model/LiveAtlasMapDefinition.ts index 3cbaf3d..f98cfa5 100644 --- a/src/model/LiveAtlasMapDefinition.ts +++ b/src/model/LiveAtlasMapDefinition.ts @@ -14,9 +14,8 @@ * limitations under the License. */ -import {Coordinate, LiveAtlasWorldDefinition} from "@/index"; +import {Coordinate, LiveAtlasProjection, LiveAtlasWorldDefinition} from "@/index"; import {LatLng} from "leaflet"; -import {LiveAtlasProjection} from "@/model/LiveAtlasProjection"; import {ImageFormat} from "dynmap"; export interface LiveAtlasMapDefinitionOptions { @@ -32,8 +31,7 @@ export interface LiveAtlasMapDefinitionOptions { 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]; + projection?: LiveAtlasProjection; nativeZoomLevels: number; extraZoomLevels: number; tileUpdateInterval?: number; @@ -52,7 +50,7 @@ export default class LiveAtlasMapDefinition { readonly imageFormat: ImageFormat; readonly tileSize: number; readonly prefix: string; - private readonly projection?: Readonly; + readonly projection?: LiveAtlasProjection; readonly nativeZoomLevels: number; readonly extraZoomLevels: number; readonly scale: number; @@ -73,20 +71,12 @@ export default class LiveAtlasMapDefinition { this.imageFormat = options.imageFormat; this.tileSize = options.tileSize; this.prefix = options.prefix || ''; + this.projection = options.projection || undefined; this.nativeZoomLevels = options.nativeZoomLevels || 1; this.extraZoomLevels = options.extraZoomLevels || 0; this.scale = (1 / Math.pow(2, this.nativeZoomLevels)); this.tileUpdateInterval = options.tileUpdateInterval || undefined; - - if(options.mapToWorld || options.worldToMap) { - this.projection = new LiveAtlasProjection({ - 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 - }); - } } locationToLatLng(location: Coordinate): LatLng { diff --git a/src/util/dynmap.ts b/src/util/dynmap.ts index 6f70b50..d986d4d 100644 --- a/src/util/dynmap.ts +++ b/src/util/dynmap.ts @@ -52,6 +52,7 @@ import { } from "dynmap"; import {PointTuple} from "leaflet"; import {LiveAtlasMarkerType} from "@/util/markers"; +import {DynmapProjection} from "@/leaflet/projection/DynmapProjection"; export function buildServerConfig(response: Options): LiveAtlasServerConfig { let title = 'Dynmap'; @@ -126,6 +127,9 @@ export function buildWorlds(response: Configuration): Array