UNPKG

leaflet-tactical-markers

Version:

Display DV102 Tactical Markers on a Leaflet Map

69 lines (62 loc) 2.16 kB
import { erzeugeTaktischesZeichen } from "taktische-zeichen-core"; export const TacticalIcon = L.Icon.extend({ options: { tz: { } }, initialize: function(options) { let tz = erzeugeTaktischesZeichen(options.tz); options = { ...options, iconUrl: tz.dataUrl, iconSize: tz.size, // size of the icon iconAnchor: [tz.size[0] / 2, tz.size[1] / 2], // point of the icon which will correspond to marker's location popupAnchor: [0, -tz.size[1] / 2] // point from which the popup should open relative to the iconAnchor }; this.options = options; }, }); export class TacticalMarker extends L.Marker { constructor(latlng, options) { super(latlng, options); this.options["icon"] = new TacticalIcon(options); this._latlng = new L.LatLng(...latlng); } toGeoJSON() { let feature = super.toGeoJSON(); feature.properties = { ...feature.properties, "situation:type": "ts", "imageUrl": this.options.icon?.options?.iconUrl, ...toSDXF(this.options.tz), }; return feature; } } /** * Converts parameters of a tactical sign as expected by taktische-zeichen-core * to the properties defined in the * [SituationDataXchangeFormat](https://github.com/einsatzverwaltung/SituationDataXchangeFormat/blob/main/SituationMapJson.md#taktisches-zeichen) * @param {dict} parameters of a tactical sign for taktische-zeichen-core */ function toSDXF(tz_spec) { // some taktische-zeichen-core parameters are not covered by SDXF const key_mapping = { "grundzeichen": "situation:ts:grundzeichen", "organisation": "situation:ts:organisation", "fachaufgabe": "situation:ts:fachaufgabe", "einheit": "situation:ts:ordnung", "verwaltungsstufe": "situation:ts:verwaltungsstufe", "funktion": "situation:ts:personalfunktion", // "symbol": "", "text": "situation:ts:text", // "typ": "", "name": "name", // "organisationName", // "farbe", // "skipFontRegistration" } return Object.fromEntries( Object.entries(tz_spec).map(([tz_key, value]) => key_mapping[tz_key] ? [key_mapping[tz_key], value] : null) ); }