|
|
@ -15,7 +15,7 @@ |
|
|
///
|
|
|
///
|
|
|
|
|
|
|
|
|
import L, { |
|
|
import L, { |
|
|
FeatureGroup, |
|
|
FeatureGroup, Icon, |
|
|
LatLngBounds, |
|
|
LatLngBounds, |
|
|
LatLngTuple, |
|
|
LatLngTuple, |
|
|
markerClusterGroup, |
|
|
markerClusterGroup, |
|
|
@ -59,6 +59,7 @@ export default abstract class LeafletMap { |
|
|
points: FeatureGroup; |
|
|
points: FeatureGroup; |
|
|
markersData: FormattedData[] = []; |
|
|
markersData: FormattedData[] = []; |
|
|
polygonsData: FormattedData[] = []; |
|
|
polygonsData: FormattedData[] = []; |
|
|
|
|
|
defaultMarkerIconInfo: { size: number[], icon: Icon }; |
|
|
|
|
|
|
|
|
protected constructor(public ctx: WidgetContext, |
|
|
protected constructor(public ctx: WidgetContext, |
|
|
public $container: HTMLElement, |
|
|
public $container: HTMLElement, |
|
|
@ -308,7 +309,11 @@ export default abstract class LeafletMap { |
|
|
updateMarkers(markersData: FormattedData[], updateBounds = true, callback?) { |
|
|
updateMarkers(markersData: FormattedData[], updateBounds = true, callback?) { |
|
|
const rawMarkers = markersData.filter(mdata => !!this.convertPosition(mdata)); |
|
|
const rawMarkers = markersData.filter(mdata => !!this.convertPosition(mdata)); |
|
|
this.ready$.subscribe(() => { |
|
|
this.ready$.subscribe(() => { |
|
|
const keys: string[] = []; |
|
|
const toDelete = new Set(Array.from(this.markers.keys())); |
|
|
|
|
|
const createdMarkers: Marker[] = []; |
|
|
|
|
|
const updatedMarkers: Marker[] = []; |
|
|
|
|
|
const deletedMarkers: Marker[] = []; |
|
|
|
|
|
let m: Marker; |
|
|
rawMarkers.forEach(data => { |
|
|
rawMarkers.forEach(data => { |
|
|
if (data.rotationAngle || data.rotationAngle === 0) { |
|
|
if (data.rotationAngle || data.rotationAngle === 0) { |
|
|
const currentImage = this.options.useMarkerImageFunction ? |
|
|
const currentImage = this.options.useMarkerImageFunction ? |
|
|
@ -325,22 +330,36 @@ export default abstract class LeafletMap { |
|
|
this.options.icon = null; |
|
|
this.options.icon = null; |
|
|
} |
|
|
} |
|
|
if (this.markers.get(data.entityName)) { |
|
|
if (this.markers.get(data.entityName)) { |
|
|
this.updateMarker(data.entityName, data, markersData, this.options) |
|
|
m = this.updateMarker(data.entityName, data, markersData, this.options); |
|
|
|
|
|
if (m) { |
|
|
|
|
|
updatedMarkers.push(m); |
|
|
|
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
this.createMarker(data.entityName, data, markersData, this.options as MarkerSettings, updateBounds, callback); |
|
|
m = this.createMarker(data.entityName, data, markersData, this.options as MarkerSettings, updateBounds, callback); |
|
|
} |
|
|
if (m) { |
|
|
keys.push(data.entityName); |
|
|
createdMarkers.push(m); |
|
|
}); |
|
|
} |
|
|
const toDelete: string[] = []; |
|
|
|
|
|
this.markers.forEach((v, mKey) => { |
|
|
|
|
|
if (!keys.includes(mKey)) { |
|
|
|
|
|
toDelete.push(mKey); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
toDelete.delete(data.entityName); |
|
|
}); |
|
|
}); |
|
|
toDelete.forEach((key) => { |
|
|
toDelete.forEach((key) => { |
|
|
this.deleteMarker(key); |
|
|
m = this.deleteMarker(key); |
|
|
|
|
|
if (m) { |
|
|
|
|
|
deletedMarkers.push(m); |
|
|
|
|
|
} |
|
|
}); |
|
|
}); |
|
|
this.markersData = markersData; |
|
|
this.markersData = markersData; |
|
|
|
|
|
if ((this.options as MarkerSettings).useClusterMarkers) { |
|
|
|
|
|
if (createdMarkers.length) { |
|
|
|
|
|
this.markersCluster.addLayers(createdMarkers.map(marker => marker.leafletMarker)); |
|
|
|
|
|
} |
|
|
|
|
|
if (updatedMarkers.length) { |
|
|
|
|
|
this.markersCluster.refreshClusters(updatedMarkers.map(marker => marker.leafletMarker)) |
|
|
|
|
|
} |
|
|
|
|
|
if (deletedMarkers.length) { |
|
|
|
|
|
this.markersCluster.removeLayers(deletedMarkers.map(marker => marker.leafletMarker)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -350,22 +369,20 @@ export default abstract class LeafletMap { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private createMarker(key: string, data: FormattedData, dataSources: FormattedData[], settings: MarkerSettings, |
|
|
private createMarker(key: string, data: FormattedData, dataSources: FormattedData[], settings: MarkerSettings, |
|
|
updateBounds = true, callback?) { |
|
|
updateBounds = true, callback?): Marker { |
|
|
const newMarker = new Marker(this.convertPosition(data), settings, data, dataSources, this.dragMarker); |
|
|
const newMarker = new Marker(this, this.convertPosition(data), settings, data, dataSources, this.dragMarker); |
|
|
if (callback) |
|
|
if (callback) |
|
|
newMarker.leafletMarker.on('click', () => { callback(data, true) }); |
|
|
newMarker.leafletMarker.on('click', () => { callback(data, true) }); |
|
|
if (this.bounds && updateBounds) |
|
|
if (this.bounds && updateBounds) |
|
|
this.fitBounds(this.bounds.extend(newMarker.leafletMarker.getLatLng())); |
|
|
this.fitBounds(this.bounds.extend(newMarker.leafletMarker.getLatLng())); |
|
|
this.markers.set(key, newMarker); |
|
|
this.markers.set(key, newMarker); |
|
|
if (this.options.useClusterMarkers) { |
|
|
if (!this.options.useClusterMarkers) { |
|
|
this.markersCluster.addLayer(newMarker.leafletMarker); |
|
|
this.map.addLayer(newMarker.leafletMarker); |
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
this.map.addLayer(newMarker.leafletMarker); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
return newMarker; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private updateMarker(key: string, data: FormattedData, dataSources: FormattedData[], settings: MarkerSettings) { |
|
|
private updateMarker(key: string, data: FormattedData, dataSources: FormattedData[], settings: MarkerSettings): Marker { |
|
|
const marker: Marker = this.markers.get(key); |
|
|
const marker: Marker = this.markers.get(key); |
|
|
const location = this.convertPosition(data) |
|
|
const location = this.convertPosition(data) |
|
|
if (!location.equals(marker.location)) { |
|
|
if (!location.equals(marker.location)) { |
|
|
@ -374,24 +391,21 @@ export default abstract class LeafletMap { |
|
|
if (settings.showTooltip) { |
|
|
if (settings.showTooltip) { |
|
|
marker.updateMarkerTooltip(data); |
|
|
marker.updateMarkerTooltip(data); |
|
|
} |
|
|
} |
|
|
if (settings.useClusterMarkers) { |
|
|
|
|
|
this.markersCluster.refreshClusters() |
|
|
|
|
|
} |
|
|
|
|
|
marker.setDataSources(data, dataSources); |
|
|
marker.setDataSources(data, dataSources); |
|
|
marker.updateMarkerIcon(settings); |
|
|
marker.updateMarkerIcon(settings); |
|
|
|
|
|
return marker; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
deleteMarker(key: string) { |
|
|
deleteMarker(key: string): Marker { |
|
|
let marker = this.markers.get(key)?.leafletMarker; |
|
|
const marker = this.markers.get(key); |
|
|
if (marker) { |
|
|
const leafletMarker = marker?.leafletMarker; |
|
|
if (this.options.useClusterMarkers) { |
|
|
if (leafletMarker) { |
|
|
this.markersCluster.removeLayer(marker); |
|
|
if (!this.options.useClusterMarkers) { |
|
|
} else { |
|
|
this.map.removeLayer(leafletMarker); |
|
|
this.map.removeLayer(marker); |
|
|
} |
|
|
} |
|
|
this.markers.delete(key); |
|
|
this.markers.delete(key); |
|
|
} |
|
|
marker = null; |
|
|
return marker; |
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
updatePoints(pointsData: FormattedData[], getTooltip: (point: FormattedData, setTooltip?: boolean) => string) { |
|
|
updatePoints(pointsData: FormattedData[], getTooltip: (point: FormattedData, setTooltip?: boolean) => string) { |
|
|
|