2020-03-10 18:51:31 +02:00
|
|
|
import { Component, OnInit, Input, ViewChild, AfterViewInit, ChangeDetectorRef } from '@angular/core';
|
2020-03-06 19:22:47 +02:00
|
|
|
import { MapWidgetController } from '../lib/maps/map-widget2';
|
|
|
|
|
import { MapProviders } from '../lib/maps/map-models';
|
|
|
|
|
import { parseArray } from '@app/core/utils';
|
2020-03-10 18:51:31 +02:00
|
|
|
import { interpolateArray } from '../lib/maps/maps-utils';
|
2020-03-06 19:22:47 +02:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'trip-animation',
|
|
|
|
|
templateUrl: './trip-animation.component.html',
|
|
|
|
|
styleUrls: ['./trip-animation.component.scss']
|
|
|
|
|
})
|
|
|
|
|
export class TripAnimationComponent implements OnInit, AfterViewInit {
|
|
|
|
|
|
|
|
|
|
@Input() ctx;
|
|
|
|
|
|
|
|
|
|
@ViewChild('map') mapContainer;
|
|
|
|
|
|
|
|
|
|
mapWidget: MapWidgetController;
|
2020-03-10 18:51:31 +02:00
|
|
|
historicalData;
|
|
|
|
|
intervals;
|
|
|
|
|
normalizationStep = 500;
|
|
|
|
|
interpolatedData = [];
|
2020-03-06 19:22:47 +02:00
|
|
|
|
2020-03-10 18:51:31 +02:00
|
|
|
|
|
|
|
|
constructor(private cd: ChangeDetectorRef) { }
|
2020-03-06 19:22:47 +02:00
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
2020-03-10 18:51:31 +02:00
|
|
|
let subscription = this.ctx.subscriptions[Object.keys(this.ctx.subscriptions)[0]];
|
|
|
|
|
if (subscription) subscription.callbacks.onDataUpdated = (updated) => {
|
|
|
|
|
this.historicalData = parseArray(this.ctx.data);
|
|
|
|
|
this.historicalData.forEach(el => {
|
|
|
|
|
console.log("TripAnimationComponent -> if -> el", el)
|
|
|
|
|
el.longitude += (Math.random() - 0.5)
|
|
|
|
|
el.latitude += (Math.random() - 0.5)
|
|
|
|
|
});
|
|
|
|
|
this.calculateIntervals();
|
|
|
|
|
this.cd.detectChanges();
|
|
|
|
|
}
|
2020-03-06 19:22:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngAfterViewInit() {
|
|
|
|
|
this.mapWidget = new MapWidgetController(MapProviders.openstreet, false, this.ctx, this.mapContainer.nativeElement);
|
|
|
|
|
this.mapWidget.data
|
|
|
|
|
}
|
2020-03-10 18:51:31 +02:00
|
|
|
|
|
|
|
|
timeUpdated(time) {
|
|
|
|
|
//this.mapWidget.ma
|
|
|
|
|
const currentPosition = this.interpolatedData.map(dataSource=>dataSource[time]);
|
|
|
|
|
console.log("TripAnimationComponent -> timeUpdated -> currentPosition", currentPosition)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
calculateIntervals() {
|
|
|
|
|
this.historicalData.forEach((dataSource, index) => {
|
|
|
|
|
this.intervals = [];
|
|
|
|
|
for (let time = dataSource[0]?.time; time < dataSource[dataSource.length - 1]?.time; time += this.normalizationStep) {
|
|
|
|
|
this.intervals.push(time);
|
|
|
|
|
}
|
|
|
|
|
this.intervals.push(dataSource[dataSource.length - 1]?.time);
|
|
|
|
|
this.interpolatedData[index] = interpolateArray(dataSource, this.intervals);
|
|
|
|
|
console.log("TripAnimationComponent -> calculateIntervals -> this.intervals", this.intervals)
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 19:22:47 +02:00
|
|
|
}
|