From 6249eb904b17a4041a09ce661216442bf8c3bef5 Mon Sep 17 00:00:00 2001 From: James Lyne Date: Mon, 14 Dec 2020 00:27:49 +0000 Subject: [PATCH] Move marker set markers into single component. Start marker update handling. --- src/components/map/layer/MarkerSetLayer.vue | 6 +- src/components/map/vector/Markers.vue | 105 ++++++++++++++++++++ src/leaflet/icon/DynmapIcon.ts | 27 +++-- src/util/markers.ts | 28 ++++++ 4 files changed, 155 insertions(+), 11 deletions(-) create mode 100644 src/components/map/vector/Markers.vue create mode 100644 src/util/markers.ts diff --git a/src/components/map/layer/MarkerSetLayer.vue b/src/components/map/layer/MarkerSetLayer.vue index 2f9c0ab..95fc3d6 100644 --- a/src/components/map/layer/MarkerSetLayer.vue +++ b/src/components/map/layer/MarkerSetLayer.vue @@ -1,8 +1,8 @@ diff --git a/src/leaflet/icon/DynmapIcon.ts b/src/leaflet/icon/DynmapIcon.ts index 6dc27c9..75c411d 100644 --- a/src/leaflet/icon/DynmapIcon.ts +++ b/src/leaflet/icon/DynmapIcon.ts @@ -7,6 +7,15 @@ export interface DynmapIconOptions extends DivIconOptions { isHtml?: boolean; } +const markerContainer: HTMLDivElement = document.createElement('div'); +markerContainer.className = 'marker'; + +const markerIcon: HTMLImageElement = document.createElement('img'); +markerIcon.className = 'marker__icon'; + +const markerLabel: HTMLSpanElement = document.createElement('span'); +markerLabel.className = 'marker__label'; + export class DynmapIcon extends DivIcon { static defaultOptions: DynmapIconOptions = { icon: 'default', @@ -29,18 +38,23 @@ export class DynmapIcon extends DivIcon { DomUtil.remove(oldIcon); } - const div = document.createElement('div'), - img = document.createElement('img'), - label = document.createElement('span'), + const div = markerContainer.cloneNode(false) as HTMLDivElement, + img = markerIcon.cloneNode(false) as HTMLImageElement, + label = markerLabel.cloneNode(false) as HTMLSpanElement, + url = `${window.config.url.markers}_markers_/${this.options.icon}.png`, size = point(this.options.iconSize as PointExpression); const sizeClass = [size.x, size.y].join('x'); - img.className = `marker__icon marker__icon--${sizeClass}`; + img.width = size.x; + img.height = size.y; img.src = url; - label.className = this.options.showLabel ? 'marker__label marker__label--show' : 'marker__label'; + if(this.options.showLabel) { + label.classList.add('marker__label--show'); + } + label.classList.add(/*'markerName_' + set.id,*/ `marker__label--${sizeClass}`); if (this.options.isHtml) { @@ -54,15 +68,12 @@ export class DynmapIcon extends DivIcon { div.appendChild(img); div.appendChild(label); - div.classList.add('marker'); if(this.options.className) { div.classList.add(this.options.className); } - console.log(div.className); - return div; } } diff --git a/src/util/markers.ts b/src/util/markers.ts new file mode 100644 index 0000000..dd1e7c8 --- /dev/null +++ b/src/util/markers.ts @@ -0,0 +1,28 @@ +import {Marker} from "leaflet"; +import {DynmapMarker} from "@/dynmap"; +import {DynmapIcon} from "@/leaflet/icon/DynmapIcon"; +import {DynmapProjection} from "@/leaflet/projection/DynmapProjection"; + +export const createMarker = (options: DynmapMarker, projection: DynmapProjection): Marker => { + return new Marker(projection.locationToLatLng(options.location), { + icon: new DynmapIcon({ + icon: options.icon, + label: options.label, + iconSize: options.dimensions, + showLabel: false, + isHtml: options.isHTML, + }), + // maxZoom: this.options.maxZoom, + // minZoom: this.options.minZoom, + }); +}; + +export const updateMarker = (marker: Marker | undefined, options: DynmapMarker, projection: DynmapProjection): Marker => { + if (!marker) { + return createMarker(options, projection); + } + + //TODO + + return marker; +}; \ No newline at end of file