Commit e5e2c3f5bb356864735b823defb7a46ed18fbeab

Authored by Artem Halushko
1 parent f8af3404

selected trip on map

... ... @@ -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
... ...
... ... @@ -65,7 +65,6 @@ export class Polyline {
65 65 this.dataSources = dataSources;
66 66 this.leafletPoly.setLatLngs(locations);
67 67 this.leafletPoly.setStyle(this.getPolyStyle(settings));
68   - // this.setPolylineLatLngs(data);
69 68 if (this.polylineDecorator)
70 69 this.polylineDecorator.setPaths(this.leafletPoly);
71 70 }
... ... @@ -92,8 +91,4 @@ export class Polyline {
92 91 getPolylineLatLngs() {
93 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 69 maxTimeFormat: string;
70 70 anchors: number[] = [];
71 71 useAnchors: boolean;
  72 + currentTime: number;
72 73
73 74 static getSettingsSchema(): JsonSettingsSchema {
74 75 const schema = initSchema();
... ... @@ -118,6 +119,7 @@ export class TripAnimationComponent implements OnInit, AfterViewInit {
118 119 }
119 120
120 121 timeUpdated(time: number) {
  122 + this.currentTime = time;
121 123 const currentPosition = this.interpolatedTimeData
122 124 .map(dataSource => dataSource[time])
123 125 .filter(ds => ds)
... ... @@ -142,7 +144,6 @@ export class TripAnimationComponent implements OnInit, AfterViewInit {
142 144 }
143 145 }
144 146 }
145   - this.activeTrip = currentPosition[0];
146 147 this.calcLabel();
147 148 this.calcTooltip();
148 149 if (this.mapWidget) {
... ... @@ -153,7 +154,10 @@ export class TripAnimationComponent implements OnInit, AfterViewInit {
153 154 if (this.settings.showPoints) {
154 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 197 SecurityContext.HTML, tooltipText);
194 198 this.cd.detectChanges();
195 199 }
  200 + this.activeTrip = point;
196 201 return tooltipText;
197 202 }
198 203
... ...