diff --git a/src/index.d.ts b/src/index.d.ts index 6d7d28b..eb64a3d 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -180,24 +180,25 @@ interface LiveAtlasMarkerSetContents { circles: Map; } -interface LiveAtlasPointMarker { +interface LiveAtlasMarker { + tooltip: string; + isTooltipHTML: boolean; + popup?: string; + isPopupHTML: boolean; +} + +interface LiveAtlasPointMarker extends LiveAtlasMarker { dimensions: PointTuple; icon: string; - label: string; - isLabelHTML: boolean; location: Coordinate; minZoom?: number; maxZoom?: number; - popupContent?: string; } -interface LiveAtlasPathMarker { +interface LiveAtlasPathMarker extends LiveAtlasMarker { style: PathOptions; minZoom?: number; maxZoom?: number; - popupContent?: string; - tooltipContent?: string; - isPopupHTML: boolean; } interface LiveAtlasAreaMarker extends LiveAtlasPathMarker { diff --git a/src/leaflet/marker/GenericMarker.ts b/src/leaflet/marker/GenericMarker.ts index 065e062..a745932 100644 --- a/src/leaflet/marker/GenericMarker.ts +++ b/src/leaflet/marker/GenericMarker.ts @@ -32,9 +32,9 @@ export class GenericMarker extends Marker { this.options.icon = new GenericIcon({ icon: options.icon, - label: options.label, + label: options.tooltip, iconSize: options.dimensions, - isHtml: options.isLabelHTML, + isHtml: options.isTooltipHTML, }); this.options.maxZoom = options.maxZoom; diff --git a/src/providers/Pl3xmapMapProvider.ts b/src/providers/Pl3xmapMapProvider.ts index 8caeaf7..b884882 100644 --- a/src/providers/Pl3xmapMapProvider.ts +++ b/src/providers/Pl3xmapMapProvider.ts @@ -300,8 +300,10 @@ export default class Pl3xmapMapProvider extends MapProvider { dimensions: marker.size ? [marker.size.x || 16, marker.size.z || 16] : [16, 16], icon: marker.icon || "default", - label: (marker.tooltip || '').trim(), - isLabelHTML: true + tooltip: (marker.tooltip || '').trim(), + isTooltipHTML: true, + popup: marker.popup, + isPopupHTML: true, }; } @@ -325,8 +327,9 @@ export default class Pl3xmapMapProvider extends MapProvider { ], outline: false, - tooltipContent: area.tooltip, - popupContent: area.popup, + tooltip: area.tooltip, + isTooltipHTML: true, + popup: area.popup, isPopupHTML: true, }; } @@ -346,8 +349,9 @@ export default class Pl3xmapMapProvider extends MapProvider { points: area.points, outline: false, - tooltipContent: area.tooltip, - popupContent: area.popup, + tooltip: area.tooltip, + isTooltipHTML: true, + popup: area.popup, isPopupHTML: true, }; } @@ -362,8 +366,9 @@ export default class Pl3xmapMapProvider extends MapProvider { }, points: line.points, - tooltipContent: line.tooltip, - popupContent: line.popup, + tooltip: line.tooltip, + isTooltipHTML: true, + popup: line.popup, isPopupHTML: true, }; } @@ -387,8 +392,9 @@ export default class Pl3xmapMapProvider extends MapProvider { fillRule: circle.fillRule, }, - tooltipContent: circle.tooltip, - popupContent: circle.popup, + tooltip: circle.tooltip, + isTooltipHTML: true, + popup: circle.popup, isPopupHTML: true }; } diff --git a/src/util/areas.ts b/src/util/areas.ts index c894a43..063b0c9 100644 --- a/src/util/areas.ts +++ b/src/util/areas.ts @@ -28,12 +28,12 @@ export const createArea = (options: LiveAtlasAreaMarker, converter: Function): L points = options.points.map(projectPointsMapCallback, converter) as LatLngExpression[] | LatLngExpression[][], area = outline ? new LiveAtlasPolyline(points, options) : new LiveAtlasPolygon(points, options); - if (options.popupContent) { + if (options.popup) { area.bindPopup(() => createPopup(options, 'AreaPopup')); } - if (options.tooltipContent) { - area.bindTooltip(() => options.tooltipContent as string, tooltipOptions); + if (options.tooltip) { + area.bindTooltip(() => options.tooltip as string, tooltipOptions); } return area; diff --git a/src/util/circles.ts b/src/util/circles.ts index af954ba..6926633 100644 --- a/src/util/circles.ts +++ b/src/util/circles.ts @@ -28,12 +28,12 @@ export const createCircle = (options: LiveAtlasCircleMarker, converter: Function points = getCirclePoints(options, converter, outline), circle = outline ? new LiveAtlasPolyline(points, options) : new LiveAtlasPolygon(points, options); - if(options.popupContent) { + if(options.popup) { circle.bindPopup(() => createPopup(options, 'CirclePopup')); } - if (options.tooltipContent) { - circle.bindTooltip(() => options.tooltipContent as string, tooltipOptions); + if (options.tooltip) { + circle.bindTooltip(() => options.tooltip as string, tooltipOptions); } return circle; diff --git a/src/util/dynmap.ts b/src/util/dynmap.ts index d3c1393..3f20971 100644 --- a/src/util/dynmap.ts +++ b/src/util/dynmap.ts @@ -293,8 +293,6 @@ export function buildMarker(data: Marker): LiveAtlasPointMarker { } const marker = { - label: data.label || '', - isLabelHTML: data.markup || false, location: { x: data.x || 0, y: data.y || 0, @@ -304,12 +302,15 @@ export function buildMarker(data: Marker): LiveAtlasPointMarker { icon: data.icon || "default", minZoom: typeof data.minzoom !== 'undefined' && data.minzoom > -1 ? data.minzoom : undefined, maxZoom: typeof data.maxzoom !== 'undefined' && data.maxzoom > -1 ? data.maxzoom : undefined, - popupContent: data.desc || undefined, + tooltip: data.label || '', + isTooltipHTML: data.markup || false, + popup: data.desc || undefined, + isPopupHTML: true, }; //Fix double escaping on non-HTML labels - if(!marker.isLabelHTML) { - marker.label = decodeHTMLEntities(marker.label); + if(!marker.isTooltipHTML) { + marker.tooltip = decodeHTMLEntities(marker.tooltip); } return marker; @@ -347,8 +348,10 @@ export function buildArea(area: MarkerArea): LiveAtlasAreaMarker { minZoom: typeof area.minzoom !== 'undefined' && area.minzoom > -1 ? area.minzoom : undefined, maxZoom: typeof area.maxzoom !== 'undefined' && area.maxzoom > -1 ? area.maxzoom : undefined, + tooltip: area.label, + isTooltipHTML: area.markup || false, + popup: area.desc || area.label || undefined, isPopupHTML: area.desc ? true : area.markup || false, - popupContent: area.desc || area.label || undefined, }; } @@ -377,8 +380,10 @@ export function buildLine(line: MarkerLine): LiveAtlasLineMarker { minZoom: typeof line.minzoom !== 'undefined' && line.minzoom > -1 ? line.minzoom : undefined, maxZoom: typeof line.maxzoom !== 'undefined' && line.maxzoom > -1 ? line.maxzoom : undefined, + tooltip: line.label, + isTooltipHTML: line.markup || false, + popup: line.desc || line.label || undefined, isPopupHTML: line.desc ? true : line.markup || false, - popupContent: line.desc || line.label || undefined, }; } @@ -414,8 +419,10 @@ export function buildCircle(circle: MarkerCircle): LiveAtlasCircleMarker { minZoom: typeof circle.minzoom !== 'undefined' && circle.minzoom > -1 ? circle.minzoom : undefined, maxZoom: typeof circle.maxzoom !== 'undefined' && circle.maxzoom > -1 ? circle.maxzoom : undefined, + tooltip: circle.label, + isTooltipHTML: circle.markup || false, + popup: circle.desc || circle.label || undefined, isPopupHTML: circle.desc ? true : circle.markup || false, - popupContent: circle.desc || circle.label || undefined, }; } diff --git a/src/util/lines.ts b/src/util/lines.ts index 2325e33..50bc7dc 100644 --- a/src/util/lines.ts +++ b/src/util/lines.ts @@ -26,12 +26,12 @@ export const createLine = (options: LiveAtlasLineMarker, converter: Function): L const points = options.points.map(projectPointsMapCallback, converter), line = new LiveAtlasPolyline(points, options); - if(options.popupContent) { + if(options.popup) { line.bindPopup(() => createPopup(options, 'LinePopup')); } - if (options.tooltipContent) { - line.bindTooltip(() => options.tooltipContent as string, tooltipOptions); + if (options.tooltip) { + line.bindTooltip(() => options.tooltip as string, tooltipOptions); } return line; diff --git a/src/util/markers.ts b/src/util/markers.ts index b746757..1f442d5 100644 --- a/src/util/markers.ts +++ b/src/util/markers.ts @@ -31,7 +31,7 @@ export const createMarker = (options: LiveAtlasPointMarker, converter: Function) } }); - if(options.popupContent) { + if(options.popup) { marker.bindPopup(() => createPopup(options)); } @@ -56,9 +56,9 @@ export const updateMarker = (marker: Marker | undefined, options: LiveAtlasPoint if(icon && icon instanceof GenericIcon) { icon.update({ icon: options.icon, - label: options.label, + label: options.tooltip, iconSize: options.dimensions, - isHtml: options.isLabelHTML, + isHtml: options.isTooltipHTML, }); } } @@ -66,7 +66,7 @@ export const updateMarker = (marker: Marker | undefined, options: LiveAtlasPoint marker.closePopup(); marker.unbindPopup(); - if(options.popupContent) { + if(options.popup) { marker.bindPopup(() => createPopup(options)); } @@ -76,9 +76,9 @@ export const updateMarker = (marker: Marker | undefined, options: LiveAtlasPoint const createPopup = (options: LiveAtlasPointMarker) => { const popup = document.createElement('span'); - if (options.popupContent) { + if (options.popup) { popup.classList.add('MarkerPopup'); - popup.insertAdjacentHTML('afterbegin', options.popupContent); + popup.insertAdjacentHTML('afterbegin', options.popup); } return popup; diff --git a/src/util/paths.ts b/src/util/paths.ts index 640af04..808c238 100644 --- a/src/util/paths.ts +++ b/src/util/paths.ts @@ -43,9 +43,9 @@ export const createPopup = (options: LiveAtlasPathMarker, className: string): HT if(options.isPopupHTML) { popup.classList.add(className); - popup.insertAdjacentHTML('afterbegin', options.popupContent as string); + popup.insertAdjacentHTML('afterbegin', options.popup as string); } else { - popup.textContent = options.popupContent as string; + popup.textContent = options.popup as string; } return popup;