|
|
|
@ -15,7 +15,7 @@ |
|
|
|
///
|
|
|
|
|
|
|
|
import L, { Icon, LeafletMouseEvent } from 'leaflet'; |
|
|
|
import { FormattedData, MarkerSettings } from './map-models'; |
|
|
|
import { FormattedData, MarkerIconInfo, MarkerIconReadyFunction, MarkerImageInfo, MarkerSettings } from './map-models'; |
|
|
|
import { |
|
|
|
bindPopupActions, |
|
|
|
createTooltip, |
|
|
|
@ -55,11 +55,7 @@ export class Marker { |
|
|
|
isDefined(settings.tooltipOffsetY) ? settings.tooltipOffsetY : -1, |
|
|
|
]; |
|
|
|
|
|
|
|
this.createMarkerIcon((iconInfo) => { |
|
|
|
this.leafletMarker.setIcon(iconInfo.icon); |
|
|
|
this.labelOffset = [0, -iconInfo.size[1] * this.markerOffset[1] + 10]; |
|
|
|
this.updateMarkerLabel(settings); |
|
|
|
}); |
|
|
|
this.updateMarkerIcon(settings); |
|
|
|
|
|
|
|
if (settings.showTooltip) { |
|
|
|
this.tooltip = createTooltip(this.leafletMarker, settings, data.$datasource); |
|
|
|
@ -130,20 +126,22 @@ export class Marker { |
|
|
|
updateMarkerIcon(settings: MarkerSettings) { |
|
|
|
this.createMarkerIcon((iconInfo) => { |
|
|
|
this.leafletMarker.setIcon(iconInfo.icon); |
|
|
|
this.labelOffset = [0, -iconInfo.size[1] * this.markerOffset[1] + 10]; |
|
|
|
const anchor = iconInfo.icon.options.iconAnchor; |
|
|
|
if (anchor && Array.isArray(anchor)) { |
|
|
|
this.labelOffset = [iconInfo.size[0] / 2 - anchor[0], 10 - anchor[1]]; |
|
|
|
} else { |
|
|
|
this.labelOffset = [0, -iconInfo.size[1] * this.markerOffset[1] + 10]; |
|
|
|
} |
|
|
|
this.updateMarkerLabel(settings); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
createMarkerIcon(onMarkerIconReady) { |
|
|
|
private createMarkerIcon(onMarkerIconReady: MarkerIconReadyFunction) { |
|
|
|
if (this.settings.icon) { |
|
|
|
onMarkerIconReady({ |
|
|
|
size: [30, 30], |
|
|
|
icon: this.settings.icon, |
|
|
|
}); |
|
|
|
return; |
|
|
|
onMarkerIconReady(this.settings.icon); |
|
|
|
return; |
|
|
|
} |
|
|
|
const currentImage = this.settings.useMarkerImageFunction ? |
|
|
|
const currentImage: MarkerImageInfo = this.settings.useMarkerImageFunction ? |
|
|
|
safeExecute(this.settings.markerImageFunction, |
|
|
|
[this.data, this.settings.markerImages, this.dataSources, this.data.dsIndex]) : this.settings.currentImage; |
|
|
|
let currentColor = this.settings.tinyColor; |
|
|
|
@ -167,13 +165,21 @@ export class Marker { |
|
|
|
width = currentImage.size * aspect; |
|
|
|
height = currentImage.size; |
|
|
|
} |
|
|
|
let iconAnchor = currentImage.markerOffset; |
|
|
|
let popupAnchor = currentImage.tooltipOffset; |
|
|
|
if (!iconAnchor) { |
|
|
|
iconAnchor = [width * this.markerOffset[0], height * this.markerOffset[1]]; |
|
|
|
} |
|
|
|
if (!popupAnchor) { |
|
|
|
popupAnchor = [width * this.tooltipOffset[0], height * this.tooltipOffset[1]]; |
|
|
|
} |
|
|
|
const icon = L.icon({ |
|
|
|
iconUrl: currentImage.url, |
|
|
|
iconSize: [width, height], |
|
|
|
iconAnchor: [width * this.markerOffset[0], height * this.markerOffset[1]], |
|
|
|
popupAnchor: [width * this.tooltipOffset[0], height * this.tooltipOffset[1]] |
|
|
|
iconAnchor, |
|
|
|
popupAnchor |
|
|
|
}); |
|
|
|
const iconInfo = { |
|
|
|
const iconInfo: MarkerIconInfo = { |
|
|
|
size: [width, height], |
|
|
|
icon |
|
|
|
}; |
|
|
|
@ -188,8 +194,8 @@ export class Marker { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
createDefaultMarkerIcon(color: tinycolor.Instance, onMarkerIconReady) { |
|
|
|
let icon: { size: number[], icon: Icon }; |
|
|
|
createDefaultMarkerIcon(color: tinycolor.Instance, onMarkerIconReady: MarkerIconReadyFunction) { |
|
|
|
let icon: MarkerIconInfo; |
|
|
|
if (!tinycolor.equals(color, this.settings.tinyColor)) { |
|
|
|
icon = this.createColoredMarkerIcon(color); |
|
|
|
} else { |
|
|
|
@ -201,7 +207,7 @@ export class Marker { |
|
|
|
onMarkerIconReady(icon); |
|
|
|
} |
|
|
|
|
|
|
|
createColoredMarkerIcon(color: tinycolor.Instance): { size: number[], icon: Icon } { |
|
|
|
createColoredMarkerIcon(color: tinycolor.Instance): MarkerIconInfo { |
|
|
|
return { |
|
|
|
size: [21, 34], |
|
|
|
icon: L.icon({ |
|
|
|
|