Showing
3 changed files
with
33 additions
and
21 deletions
@@ -20,12 +20,12 @@ import 'leaflet-providers'; | @@ -20,12 +20,12 @@ import 'leaflet-providers'; | ||
20 | import 'leaflet.markercluster/dist/leaflet.markercluster'; | 20 | import 'leaflet.markercluster/dist/leaflet.markercluster'; |
21 | 21 | ||
22 | import { | 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 | } from './map-models'; | 29 | } from './map-models'; |
30 | import { Marker } from './markers'; | 30 | import { Marker } from './markers'; |
31 | import { BehaviorSubject, Observable } from 'rxjs'; | 31 | import { BehaviorSubject, Observable } from 'rxjs'; |
@@ -346,26 +346,30 @@ export default abstract class LeafletMap { | @@ -346,26 +346,30 @@ export default abstract class LeafletMap { | ||
346 | // Polyline | 346 | // Polyline |
347 | 347 | ||
348 | updatePolylines(polyData: FormattedData[][], data?: FormattedData) { | 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 | this.updatePolyline(data, dataSource, this.options); | 353 | this.updatePolyline(data, dataSource, this.options); |
354 | } | 354 | } |
355 | else { | 355 | else { |
356 | this.createPolyline(data, dataSource, this.options); | 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 | createPolyline(data: FormattedData, dataSources: FormattedData[], settings: PolylineSettings) { | 366 | createPolyline(data: FormattedData, dataSources: FormattedData[], settings: PolylineSettings) { |
363 | this.ready$.subscribe(() => { | 367 | this.ready$.subscribe(() => { |
364 | const poly = new Polyline(this.map, | 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 | const bounds = poly.leafletPoly.getBounds(); | 370 | const bounds = poly.leafletPoly.getBounds(); |
367 | this.fitBounds(bounds); | 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,13 +377,21 @@ export default abstract class LeafletMap { | ||
373 | this.ready$.subscribe(() => { | 377 | this.ready$.subscribe(() => { |
374 | const poly = this.polylines.get(data.entityName); | 378 | const poly = this.polylines.get(data.entityName); |
375 | const oldBounds = poly.leafletPoly.getBounds(); | 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 | const newBounds = poly.leafletPoly.getBounds(); | 381 | const newBounds = poly.leafletPoly.getBounds(); |
378 | if (oldBounds.toBBoxString() !== newBounds.toBBoxString()) { | 382 | if (oldBounds.toBBoxString() !== newBounds.toBBoxString()) { |
379 | this.fitBounds(newBounds); | 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 | // Polygon | 396 | // Polygon |
385 | 397 |
@@ -65,7 +65,6 @@ export class Polyline { | @@ -65,7 +65,6 @@ export class Polyline { | ||
65 | this.dataSources = dataSources; | 65 | this.dataSources = dataSources; |
66 | this.leafletPoly.setLatLngs(locations); | 66 | this.leafletPoly.setLatLngs(locations); |
67 | this.leafletPoly.setStyle(this.getPolyStyle(settings)); | 67 | this.leafletPoly.setStyle(this.getPolyStyle(settings)); |
68 | - // this.setPolylineLatLngs(data); | ||
69 | if (this.polylineDecorator) | 68 | if (this.polylineDecorator) |
70 | this.polylineDecorator.setPaths(this.leafletPoly); | 69 | this.polylineDecorator.setPaths(this.leafletPoly); |
71 | } | 70 | } |
@@ -92,8 +91,4 @@ export class Polyline { | @@ -92,8 +91,4 @@ export class Polyline { | ||
92 | getPolylineLatLngs() { | 91 | getPolylineLatLngs() { |
93 | return this.leafletPoly.getLatLngs(); | 92 | return this.leafletPoly.getLatLngs(); |
94 | } | 93 | } |
95 | - | ||
96 | - setPolylineLatLngs(latLngs) { | ||
97 | - this.leafletPoly.setLatLngs(latLngs); | ||
98 | - } | ||
99 | } | 94 | } |
@@ -69,6 +69,7 @@ export class TripAnimationComponent implements OnInit, AfterViewInit { | @@ -69,6 +69,7 @@ export class TripAnimationComponent implements OnInit, AfterViewInit { | ||
69 | maxTimeFormat: string; | 69 | maxTimeFormat: string; |
70 | anchors: number[] = []; | 70 | anchors: number[] = []; |
71 | useAnchors: boolean; | 71 | useAnchors: boolean; |
72 | + currentTime: number; | ||
72 | 73 | ||
73 | static getSettingsSchema(): JsonSettingsSchema { | 74 | static getSettingsSchema(): JsonSettingsSchema { |
74 | const schema = initSchema(); | 75 | const schema = initSchema(); |
@@ -118,6 +119,7 @@ export class TripAnimationComponent implements OnInit, AfterViewInit { | @@ -118,6 +119,7 @@ export class TripAnimationComponent implements OnInit, AfterViewInit { | ||
118 | } | 119 | } |
119 | 120 | ||
120 | timeUpdated(time: number) { | 121 | timeUpdated(time: number) { |
122 | + this.currentTime = time; | ||
121 | const currentPosition = this.interpolatedTimeData | 123 | const currentPosition = this.interpolatedTimeData |
122 | .map(dataSource => dataSource[time]) | 124 | .map(dataSource => dataSource[time]) |
123 | .filter(ds => ds) | 125 | .filter(ds => ds) |
@@ -142,7 +144,6 @@ export class TripAnimationComponent implements OnInit, AfterViewInit { | @@ -142,7 +144,6 @@ export class TripAnimationComponent implements OnInit, AfterViewInit { | ||
142 | } | 144 | } |
143 | } | 145 | } |
144 | } | 146 | } |
145 | - this.activeTrip = currentPosition[0]; | ||
146 | this.calcLabel(); | 147 | this.calcLabel(); |
147 | this.calcTooltip(); | 148 | this.calcTooltip(); |
148 | if (this.mapWidget) { | 149 | if (this.mapWidget) { |
@@ -153,7 +154,10 @@ export class TripAnimationComponent implements OnInit, AfterViewInit { | @@ -153,7 +154,10 @@ export class TripAnimationComponent implements OnInit, AfterViewInit { | ||
153 | if (this.settings.showPoints) { | 154 | if (this.settings.showPoints) { |
154 | this.mapWidget.map.updatePoints(_.values(_.union(this.interpolatedTimeData)[0]), this.calcTooltip); | 155 | this.mapWidget.map.updatePoints(_.values(_.union(this.interpolatedTimeData)[0]), this.calcTooltip); |
155 | } | 156 | } |
156 | - this.mapWidget.map.updateMarkers(currentPosition, this.calcTooltip); | 157 | + this.mapWidget.map.updateMarkers(currentPosition, (trip) => { |
158 | + this.activeTrip = trip; | ||
159 | + this.timeUpdated(this.currentTime) | ||
160 | + }); | ||
157 | } | 161 | } |
158 | } | 162 | } |
159 | 163 | ||
@@ -193,6 +197,7 @@ export class TripAnimationComponent implements OnInit, AfterViewInit { | @@ -193,6 +197,7 @@ export class TripAnimationComponent implements OnInit, AfterViewInit { | ||
193 | SecurityContext.HTML, tooltipText); | 197 | SecurityContext.HTML, tooltipText); |
194 | this.cd.detectChanges(); | 198 | this.cd.detectChanges(); |
195 | } | 199 | } |
200 | + this.activeTrip = point; | ||
196 | return tooltipText; | 201 | return tooltipText; |
197 | } | 202 | } |
198 | 203 |