...
|
...
|
@@ -20,12 +20,12 @@ import 'leaflet-providers'; |
20
|
20
|
import 'leaflet.markercluster/dist/leaflet.markercluster';
|
21
|
21
|
|
22
|
22
|
import {
|
23
|
|
- FormattedData,
|
24
|
|
- MapSettings,
|
25
|
|
- MarkerSettings,
|
26
|
|
- PolygonSettings,
|
27
|
|
- PolylineSettings,
|
28
|
|
- UnitedMapSettings
|
|
23
|
+ FormattedData,
|
|
24
|
+ MapSettings,
|
|
25
|
+ MarkerSettings,
|
|
26
|
+ PolygonSettings,
|
|
27
|
+ PolylineSettings,
|
|
28
|
+ UnitedMapSettings
|
29
|
29
|
} from './map-models';
|
30
|
30
|
import { Marker } from './markers';
|
31
|
31
|
import { BehaviorSubject, Observable } from 'rxjs';
|
...
|
...
|
@@ -346,26 +346,30 @@ export default abstract class LeafletMap { |
346
|
346
|
// Polyline
|
347
|
347
|
|
348
|
348
|
updatePolylines(polyData: FormattedData[][], data?: FormattedData) {
|
349
|
|
- polyData.forEach((dataSource) => {
|
350
|
|
- if (dataSource.length) {
|
351
|
|
- data = data || dataSource[0];
|
352
|
|
- if (this.polylines.get(data.$datasource.entityName)) {
|
|
349
|
+ polyData.forEach((dataSource: FormattedData[]) => {
|
|
350
|
+ data = data || dataSource[0];
|
|
351
|
+ if (dataSource.length && data.entityName === dataSource[0].entityName) {
|
|
352
|
+ if (this.polylines.get(data.entityName)) {
|
353
|
353
|
this.updatePolyline(data, dataSource, this.options);
|
354
|
354
|
}
|
355
|
355
|
else {
|
356
|
356
|
this.createPolyline(data, dataSource, this.options);
|
357
|
357
|
}
|
358
|
358
|
}
|
|
359
|
+ else {
|
|
360
|
+ if (data)
|
|
361
|
+ this.removePolyline(dataSource[0]?.entityName)
|
|
362
|
+ }
|
359
|
363
|
})
|
360
|
364
|
}
|
361
|
365
|
|
362
|
366
|
createPolyline(data: FormattedData, dataSources: FormattedData[], settings: PolylineSettings) {
|
363
|
367
|
this.ready$.subscribe(() => {
|
364
|
368
|
const poly = new Polyline(this.map,
|
365
|
|
- dataSources.map(el => this.convertPosition(el)).filter(el => !!el), data, dataSources, settings);
|
|
369
|
+ dataSources.map(el => this.convertPosition(el)).filter(el => !!el), data, dataSources, settings);
|
366
|
370
|
const bounds = poly.leafletPoly.getBounds();
|
367
|
371
|
this.fitBounds(bounds);
|
368
|
|
- this.polylines.set(data.$datasource.entityName, poly);
|
|
372
|
+ this.polylines.set(data.entityName, poly);
|
369
|
373
|
});
|
370
|
374
|
}
|
371
|
375
|
|
...
|
...
|
@@ -373,13 +377,21 @@ export default abstract class LeafletMap { |
373
|
377
|
this.ready$.subscribe(() => {
|
374
|
378
|
const poly = this.polylines.get(data.entityName);
|
375
|
379
|
const oldBounds = poly.leafletPoly.getBounds();
|
376
|
|
- poly.updatePolyline(settings, data.map(el => this.convertPosition(el)).filter(el => !!el), dataSources);
|
|
380
|
+ poly.updatePolyline(dataSources.map(el => this.convertPosition(el)).filter(el => !!el), data, dataSources, settings);
|
377
|
381
|
const newBounds = poly.leafletPoly.getBounds();
|
378
|
382
|
if (oldBounds.toBBoxString() !== newBounds.toBBoxString()) {
|
379
|
383
|
this.fitBounds(newBounds);
|
380
|
384
|
}
|
381
|
385
|
});
|
382
|
|
- }Я
|
|
386
|
+ }
|
|
387
|
+
|
|
388
|
+ removePolyline(name: string) {
|
|
389
|
+ const poly = this.polylines.get(name);
|
|
390
|
+ if (poly) {
|
|
391
|
+ this.map.removeLayer(poly.leafletPoly);
|
|
392
|
+ this.polylines.delete(name);
|
|
393
|
+ }
|
|
394
|
+ }
|
383
|
395
|
|
384
|
396
|
// Polygon
|
385
|
397
|
|
...
|
...
|
|