|
|
@ -20,12 +20,12 @@ import 'leaflet-providers'; |
|
|
import 'leaflet.markercluster/dist/leaflet.markercluster'; |
|
|
import 'leaflet.markercluster/dist/leaflet.markercluster'; |
|
|
|
|
|
|
|
|
import { |
|
|
import { |
|
|
FormattedData, |
|
|
FormattedData, |
|
|
MapSettings, |
|
|
MapSettings, |
|
|
MarkerSettings, |
|
|
MarkerSettings, |
|
|
PolygonSettings, |
|
|
PolygonSettings, |
|
|
PolylineSettings, |
|
|
PolylineSettings, |
|
|
UnitedMapSettings |
|
|
UnitedMapSettings |
|
|
} from './map-models'; |
|
|
} from './map-models'; |
|
|
import { Marker } from './markers'; |
|
|
import { Marker } from './markers'; |
|
|
import { BehaviorSubject, Observable } from 'rxjs'; |
|
|
import { BehaviorSubject, Observable } from 'rxjs'; |
|
|
@ -346,26 +346,30 @@ export default abstract class LeafletMap { |
|
|
// Polyline
|
|
|
// Polyline
|
|
|
|
|
|
|
|
|
updatePolylines(polyData: FormattedData[][], data?: FormattedData) { |
|
|
updatePolylines(polyData: FormattedData[][], data?: FormattedData) { |
|
|
polyData.forEach((dataSource) => { |
|
|
polyData.forEach((dataSource: FormattedData[]) => { |
|
|
if (dataSource.length) { |
|
|
data = data || dataSource[0]; |
|
|
data = data || dataSource[0]; |
|
|
if (dataSource.length && data.entityName === dataSource[0].entityName) { |
|
|
if (this.polylines.get(data.$datasource.entityName)) { |
|
|
if (this.polylines.get(data.entityName)) { |
|
|
this.updatePolyline(data, dataSource, this.options); |
|
|
this.updatePolyline(data, dataSource, this.options); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
this.createPolyline(data, dataSource, this.options); |
|
|
this.createPolyline(data, dataSource, this.options); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
if (data) |
|
|
|
|
|
this.removePolyline(dataSource[0]?.entityName) |
|
|
|
|
|
} |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
createPolyline(data: FormattedData, dataSources: FormattedData[], settings: PolylineSettings) { |
|
|
createPolyline(data: FormattedData, dataSources: FormattedData[], settings: PolylineSettings) { |
|
|
this.ready$.subscribe(() => { |
|
|
this.ready$.subscribe(() => { |
|
|
const poly = new Polyline(this.map, |
|
|
const poly = new Polyline(this.map, |
|
|
dataSources.map(el => this.convertPosition(el)).filter(el => !!el), data, dataSources, settings); |
|
|
dataSources.map(el => this.convertPosition(el)).filter(el => !!el), data, dataSources, settings); |
|
|
const bounds = poly.leafletPoly.getBounds(); |
|
|
const bounds = poly.leafletPoly.getBounds(); |
|
|
this.fitBounds(bounds); |
|
|
this.fitBounds(bounds); |
|
|
this.polylines.set(data.$datasource.entityName, poly); |
|
|
this.polylines.set(data.entityName, poly); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -373,13 +377,21 @@ export default abstract class LeafletMap { |
|
|
this.ready$.subscribe(() => { |
|
|
this.ready$.subscribe(() => { |
|
|
const poly = this.polylines.get(data.entityName); |
|
|
const poly = this.polylines.get(data.entityName); |
|
|
const oldBounds = poly.leafletPoly.getBounds(); |
|
|
const oldBounds = poly.leafletPoly.getBounds(); |
|
|
poly.updatePolyline(settings, data.map(el => this.convertPosition(el)).filter(el => !!el), dataSources); |
|
|
poly.updatePolyline(dataSources.map(el => this.convertPosition(el)).filter(el => !!el), data, dataSources, settings); |
|
|
const newBounds = poly.leafletPoly.getBounds(); |
|
|
const newBounds = poly.leafletPoly.getBounds(); |
|
|
if (oldBounds.toBBoxString() !== newBounds.toBBoxString()) { |
|
|
if (oldBounds.toBBoxString() !== newBounds.toBBoxString()) { |
|
|
this.fitBounds(newBounds); |
|
|
this.fitBounds(newBounds); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
}Я |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
removePolyline(name: string) { |
|
|
|
|
|
const poly = this.polylines.get(name); |
|
|
|
|
|
if (poly) { |
|
|
|
|
|
this.map.removeLayer(poly.leafletPoly); |
|
|
|
|
|
this.polylines.delete(name); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Polygon
|
|
|
// Polygon
|
|
|
|
|
|
|
|
|
|