From bf300d977ca952cfdd53ad2680ba0e67fb96ef24 Mon Sep 17 00:00:00 2001 From: James Lyne Date: Thu, 24 Feb 2022 22:53:26 +0000 Subject: [PATCH] Overviewer spawn marker --- src/index.d.ts | 1 + src/leaflet/icon/GenericIcon.ts | 11 ++++++-- src/leaflet/marker/GenericMarker.ts | 1 + src/providers/OverviewerMapProvider.ts | 38 ++++++++++++++++++++++++-- src/util/points.ts | 1 + 5 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/index.d.ts b/src/index.d.ts index 82c5607..65e06d9 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -219,6 +219,7 @@ interface LiveAtlasPointMarker extends LiveAtlasMarker { type: LiveAtlasMarkerType.POINT; iconUrl: string; iconSize?: PointTuple; + iconAnchor?: PointTuple; } interface LiveAtlasPathMarker extends LiveAtlasMarker { diff --git a/src/leaflet/icon/GenericIcon.ts b/src/leaflet/icon/GenericIcon.ts index ebcc8a3..49837cf 100644 --- a/src/leaflet/icon/GenericIcon.ts +++ b/src/leaflet/icon/GenericIcon.ts @@ -25,6 +25,7 @@ export interface GenericIconOptions extends BaseIconOptions { isHtml?: boolean; showLabel?: boolean; iconSize?: PointTuple; + iconAnchor?: PointTuple; className?: string; } @@ -117,6 +118,7 @@ export class GenericIcon extends Layer implements Icon { if(options) { this.options.iconUrl = options.iconUrl; this.options.iconSize = options.iconSize; + this.options.iconAnchor = options.iconAnchor; this.options.isHtml = options.isHtml; this.options.label = options.label; } @@ -128,7 +130,10 @@ export class GenericIcon extends Layer implements Icon { this._container!.classList.toggle('marker--auto-size', !this.options.iconSize); if(this._image) { - const iconSize = this.options.iconSize ? point(this.options.iconSize as PointExpression) : undefined; + const iconSize = this.options.iconSize ? point(this.options.iconSize as PointExpression) : undefined, + iconAnchor = this.options.iconAnchor ? point(this.options.iconAnchor as PointExpression) : undefined, + marginLeft = iconAnchor ? -iconAnchor.x : iconSize ? -(iconSize.x / 2) : 0, + marginTop = iconAnchor ? -iconAnchor.y : iconSize ? -(iconSize.y / 2) : 0; if(iconSize) { this._image.width = iconSize.x; @@ -138,8 +143,8 @@ export class GenericIcon extends Layer implements Icon { this._image.removeAttribute('height'); } - this._container.style.marginLeft = iconSize ? `${-(iconSize.x / 2)}px` : ''; - this._container.style.marginTop = iconSize ? `${-(iconSize.y / 2)}px` : ''; + this._container.style.marginLeft = marginLeft ? `${marginLeft}px` : ''; + this._container.style.marginTop = marginTop ? `${marginTop}px` : ''; this._container.style.height = iconSize ? `${iconSize.y}px` : 'auto'; if(this._image.src !== this.options.iconUrl) { diff --git a/src/leaflet/marker/GenericMarker.ts b/src/leaflet/marker/GenericMarker.ts index 6bbee80..c9609eb 100644 --- a/src/leaflet/marker/GenericMarker.ts +++ b/src/leaflet/marker/GenericMarker.ts @@ -34,6 +34,7 @@ export class GenericMarker extends Marker { iconUrl: options.iconUrl, label: options.tooltipHTML || options.tooltip, iconSize: options.iconSize, + iconAnchor: options.iconAnchor, isHtml: !!options.tooltipHTML, }); diff --git a/src/providers/OverviewerMapProvider.ts b/src/providers/OverviewerMapProvider.ts index 813a6c0..18971c3 100644 --- a/src/providers/OverviewerMapProvider.ts +++ b/src/providers/OverviewerMapProvider.ts @@ -22,7 +22,7 @@ import { LiveAtlasComponentConfig, LiveAtlasDimension, LiveAtlasMarker, - LiveAtlasMarkerSet, + LiveAtlasMarkerSet, LiveAtlasPointMarker, LiveAtlasServerConfig, LiveAtlasServerMessageConfig, LiveAtlasWorldDefinition @@ -147,8 +147,40 @@ export default class OverviewerMapProvider extends MapProvider { } })); - this.mapMarkerSets.set(tileset.path, new Map()); - this.mapMarkers.set(tileset.path, new Map()); + //Spawn marker + const markerSets = new Map(), + markers = new Map>(); + + if(Array.isArray(tileset.spawn)) { + markerSets.set('spawn', { + id: 'spawn', + label: tileset.poititle, + hidden: false, + priority: 0, + }); + + const setContents = new Map(); + + setContents.set('spawn', { + id: 'spawn', + type: LiveAtlasMarkerType.POINT, + iconUrl: this.config + serverResponse?.CONST?.image?.spawnMarker, + iconSize: [32, 37], + iconAnchor: [15, 33], + tooltip: 'Spawn', + location: { + x: tileset.spawn[0], + y: tileset.spawn[1], + z: tileset.spawn[2], + } + } as LiveAtlasPointMarker); + + markers.set('spawn', setContents); + } + + this.mapMarkerSets.set(tileset.path, markerSets); + this.mapMarkers.set(tileset.path, markers); + }); return Array.from(worlds.values()); diff --git a/src/util/points.ts b/src/util/points.ts index acad10f..954da19 100644 --- a/src/util/points.ts +++ b/src/util/points.ts @@ -55,6 +55,7 @@ export const updatePointLayer = (marker: Marker | undefined, options: LiveAtlasP iconUrl: options.iconUrl, label: options.tooltipHTML || options.tooltip, iconSize: options.iconSize, + iconAnchor: options.iconAnchor, isHtml: !!options.tooltipHTML, }); }