|
|
@ -14,7 +14,7 @@ |
|
|
/// limitations under the License.
|
|
|
/// limitations under the License.
|
|
|
///
|
|
|
///
|
|
|
|
|
|
|
|
|
import L, { LeafletMouseEvent } from 'leaflet'; |
|
|
import L, { Icon, LeafletMouseEvent } from 'leaflet'; |
|
|
import { FormattedData, MarkerSettings } from './map-models'; |
|
|
import { FormattedData, MarkerSettings } from './map-models'; |
|
|
import { |
|
|
import { |
|
|
aspectCache, |
|
|
aspectCache, |
|
|
@ -26,7 +26,7 @@ import { |
|
|
safeExecute |
|
|
safeExecute |
|
|
} from './maps-utils'; |
|
|
} from './maps-utils'; |
|
|
import tinycolor from 'tinycolor2'; |
|
|
import tinycolor from 'tinycolor2'; |
|
|
import { isDefined } from '@core/utils'; |
|
|
import { isDefined, isDefinedAndNotNull } from '@core/utils'; |
|
|
import LeafletMap from './leaflet-map'; |
|
|
import LeafletMap from './leaflet-map'; |
|
|
|
|
|
|
|
|
export class Marker { |
|
|
export class Marker { |
|
|
@ -138,8 +138,14 @@ export class Marker { |
|
|
const currentImage = this.settings.useMarkerImageFunction ? |
|
|
const currentImage = this.settings.useMarkerImageFunction ? |
|
|
safeExecute(this.settings.markerImageFunction, |
|
|
safeExecute(this.settings.markerImageFunction, |
|
|
[this.data, this.settings.markerImages, this.dataSources, this.data.dsIndex]) : this.settings.currentImage; |
|
|
[this.data, this.settings.markerImages, this.dataSources, this.data.dsIndex]) : this.settings.currentImage; |
|
|
const currentColor = tinycolor(this.settings.useColorFunction ? safeExecute(this.settings.colorFunction, |
|
|
let currentColor = this.settings.tinyColor; |
|
|
[this.data, this.dataSources, this.data.dsIndex]) : this.settings.color).toHex(); |
|
|
if (this.settings.useColorFunction) { |
|
|
|
|
|
const functionColor = safeExecute(this.settings.colorFunction, |
|
|
|
|
|
[this.data, this.dataSources, this.data.dsIndex]); |
|
|
|
|
|
if (isDefinedAndNotNull(functionColor)) { |
|
|
|
|
|
currentColor = tinycolor(functionColor); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
if (currentImage && currentImage.url) { |
|
|
if (currentImage && currentImage.url) { |
|
|
aspectCache(currentImage.url).subscribe( |
|
|
aspectCache(currentImage.url).subscribe( |
|
|
(aspect) => { |
|
|
(aspect) => { |
|
|
@ -174,23 +180,32 @@ export class Marker { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
createDefaultMarkerIcon(color, onMarkerIconReady) { |
|
|
createDefaultMarkerIcon(color: tinycolor.Instance, onMarkerIconReady) { |
|
|
if (!this.map.defaultMarkerIconInfo) { |
|
|
let icon: { size: number[], icon: Icon }; |
|
|
const icon = L.icon({ |
|
|
if (!tinycolor.equals(color, this.settings.tinyColor)) { |
|
|
iconUrl: 'https://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|' + color, |
|
|
icon = this.createColoredMarkerIcon(color); |
|
|
iconSize: [21, 34], |
|
|
} else { |
|
|
iconAnchor: [21 * this.markerOffset[0], 34 * this.markerOffset[1]], |
|
|
if (!this.map.defaultMarkerIconInfo) { |
|
|
popupAnchor: [0, -34], |
|
|
this.map.defaultMarkerIconInfo = this.createColoredMarkerIcon(color); |
|
|
shadowUrl: 'https://chart.apis.google.com/chart?chst=d_map_pin_shadow', |
|
|
} |
|
|
shadowSize: [40, 37], |
|
|
icon = this.map.defaultMarkerIconInfo; |
|
|
shadowAnchor: [12, 35] |
|
|
|
|
|
}); |
|
|
|
|
|
this.map.defaultMarkerIconInfo = { |
|
|
|
|
|
size: [21, 34], |
|
|
|
|
|
icon |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
} |
|
|
onMarkerIconReady(this.map.defaultMarkerIconInfo); |
|
|
onMarkerIconReady(icon); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
createColoredMarkerIcon(color: tinycolor.Instance): { size: number[], icon: Icon } { |
|
|
|
|
|
return { |
|
|
|
|
|
size: [21, 34], |
|
|
|
|
|
icon: L.icon({ |
|
|
|
|
|
iconUrl: 'https://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|' + color.toHex(), |
|
|
|
|
|
iconSize: [21, 34], |
|
|
|
|
|
iconAnchor: [21 * this.markerOffset[0], 34 * this.markerOffset[1]], |
|
|
|
|
|
popupAnchor: [0, -34], |
|
|
|
|
|
shadowUrl: 'https://chart.apis.google.com/chart?chst=d_map_pin_shadow', |
|
|
|
|
|
shadowSize: [40, 37], |
|
|
|
|
|
shadowAnchor: [12, 35] |
|
|
|
|
|
}) |
|
|
|
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
removeMarker() { |
|
|
removeMarker() { |
|
|
|