diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/maps/data-layer/trips-data-layer.ts b/ui-ngx/src/app/modules/home/components/widget/lib/maps/data-layer/trips-data-layer.ts index 82d2b23125..0883049517 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/maps/data-layer/trips-data-layer.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/maps/data-layer/trips-data-layer.ts @@ -87,7 +87,8 @@ class TbTripDataItem extends TbDataLayerItem this.dataLayer.dataProcessor.extractLocation(data, dsData)); + const locations = this.extractPathLocations(formattedRouteData, dsData); const pathStyle = this.dataLayer.getPathStyle(this.pointData, dsData); this.polyline = L.polyline(locations, pathStyle); this.polyline.addTo(this.layer); @@ -205,7 +225,7 @@ class TbTripDataItem extends TbDataLayerItem this.dataLayer.dataProcessor.extractLocation(data, dsData)); + const locations = this.extractPathLocations(formattedRouteData, dsData); this.polyline.setLatLngs(locations); if (this.settings.usePathDecorator) { this.polylineDecorator.setPaths(this.polyline); @@ -214,6 +234,10 @@ class TbTripDataItem extends TbDataLayerItem[], dsData: FormattedData[]): L.LatLng[] { + return data.map(item => this.dataLayer.dataProcessor.extractLocation(item, dsData)).filter(location => !!location); + } + private updatePoints() { if (this.settings.showPoints) { if (!this.pointsContainer) { @@ -285,15 +309,8 @@ class TbTripDataItem extends TbDataLayerItem, dsData: FormattedData[]) { - const location = this.dataLayer.dataProcessor.extractLocation(data, dsData); - if (!this.marker.getLatLng().equals(location)) { - this.marker.setLatLng(location); - } - } - private updateMarkerIcon(data: FormattedData, dsData: FormattedData[]) { - if (this.settings.showMarker) { + if (this.settings.showMarker && this.marker) { this.dataLayer.dataProcessor.createMarkerIcon(data, dsData, data.rotationAngle).subscribe( (iconInfo) => { const options = deepClone(iconInfo.icon.options); @@ -600,25 +617,22 @@ export class TbTripsDataLayer extends TbMapDataLayer[]): FormattedData[] { - const firstHistoricalDataIndexCoordinate = dataSource.findIndex(this.findFirstHistoricalDataIndexCoordinate); - if (firstHistoricalDataIndexCoordinate === -1) { + const firstValidIndex = dataSource.findIndex(this.hasValidLocation); + if (firstValidIndex === -1) { return []; } - let lastIndex = dataSource.length - 1; - for (lastIndex; lastIndex > 0; lastIndex--) { - if (this.findFirstHistoricalDataIndexCoordinate(dataSource[lastIndex])) { - lastIndex++; - break; - } + let lastValidIndex = dataSource.length - 1; + while (lastValidIndex > firstValidIndex && !this.hasValidLocation(dataSource[lastValidIndex])) { + lastValidIndex--; } - if (firstHistoricalDataIndexCoordinate > 0 || lastIndex < dataSource.length) { - return dataSource.slice(firstHistoricalDataIndexCoordinate, lastIndex); + if (firstValidIndex > 0 || lastValidIndex < dataSource.length - 1) { + return dataSource.slice(firstValidIndex, lastValidIndex + 1); } return dataSource; } - private findFirstHistoricalDataIndexCoordinate = (item: FormattedData): boolean => { - return isDefined(item[this.settings.xKey.label]) && isDefined(item[this.settings.yKey.label]); + private hasValidLocation = (item: FormattedData): boolean => { + return !!this.dataProcessor.extractLocationData(item); } }