Pass projection into LiveAtlasMapDefinition instead of creating it internally
This commit is contained in:
parent
6b0317b595
commit
68eccb2b5b
7
src/index.d.ts
vendored
7
src/index.d.ts
vendored
@ -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<LiveAtlasMapDefinition>;
|
||||
}
|
||||
|
||||
interface LiveAtlasProjection {
|
||||
locationToLatLng(location: Coordinate): LatLng;
|
||||
latLngToLocation(latLng: LatLng, y: number): Coordinate;
|
||||
}
|
||||
|
||||
interface LiveAtlasWorldState {
|
||||
raining: boolean;
|
||||
thundering: boolean;
|
||||
|
@ -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;
|
@ -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<LiveAtlasProjection>;
|
||||
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 {
|
||||
|
@ -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<LiveAtlasWorldDefini
|
||||
return;
|
||||
}
|
||||
|
||||
const tileSize = 128 << (map.tilescale || 0),
|
||||
nativeZoomLevels = map.mapzoomout || 1;
|
||||
|
||||
// Maps with append_to_world set are added both the original and target world's map set
|
||||
// The world property is always the original world, an additional appendedWorld property contains the target world
|
||||
const mapDef = Object.freeze(new LiveAtlasMapDefinition({
|
||||
@ -136,14 +140,18 @@ export function buildWorlds(response: Configuration): Array<LiveAtlasWorldDefini
|
||||
backgroundNight: map.backgroundnight || '#000000',
|
||||
icon: (map.icon || undefined) as string | undefined,
|
||||
imageFormat: map['image-format'] || 'png',
|
||||
tileSize: 128 << (map.tilescale || 0),
|
||||
tileSize,
|
||||
name: map.name || '(Unnamed map)',
|
||||
nightAndDay: map.nightandday || false,
|
||||
prefix: map.prefix || '',
|
||||
displayName: map.title || '',
|
||||
mapToWorld: map.maptoworld || undefined,
|
||||
worldToMap: map.worldtomap || undefined,
|
||||
nativeZoomLevels: map.mapzoomout || 1,
|
||||
projection: new DynmapProjection({
|
||||
mapToWorld: map.maptoworld || undefined,
|
||||
worldToMap: map.worldtomap || undefined,
|
||||
nativeZoomLevels,
|
||||
tileSize,
|
||||
}),
|
||||
nativeZoomLevels,
|
||||
extraZoomLevels: map.mapzoomin || 0
|
||||
})) as LiveAtlasMapDefinition;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user