Overviewer spawn marker

This commit is contained in:
James Lyne 2022-02-24 22:53:26 +00:00
parent 29bbc1cd76
commit bf300d977c
5 changed files with 46 additions and 6 deletions

1
src/index.d.ts vendored
View File

@ -219,6 +219,7 @@ interface LiveAtlasPointMarker extends LiveAtlasMarker {
type: LiveAtlasMarkerType.POINT;
iconUrl: string;
iconSize?: PointTuple;
iconAnchor?: PointTuple;
}
interface LiveAtlasPathMarker extends LiveAtlasMarker {

View File

@ -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<GenericIconOptions> {
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<GenericIconOptions> {
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<GenericIconOptions> {
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) {

View File

@ -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,
});

View File

@ -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<string, LiveAtlasMarkerSet>(),
markers = new Map<string, Map<string, LiveAtlasMarker>>();
if(Array.isArray(tileset.spawn)) {
markerSets.set('spawn', {
id: 'spawn',
label: tileset.poititle,
hidden: false,
priority: 0,
});
const setContents = new Map<string, LiveAtlasMarker>();
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());

View File

@ -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,
});
}