trip-animation.component.ts
2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { Component, OnInit, Input, ViewChild, AfterViewInit, ChangeDetectorRef } from '@angular/core';
import { MapWidgetController } from '../lib/maps/map-widget2';
import { MapProviders } from '../lib/maps/map-models';
import { parseArray } from '@app/core/utils';
import { interpolateArray } from '../lib/maps/maps-utils';
@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;
historicalData;
intervals;
normalizationStep = 500;
interpolatedData = [];
constructor(private cd: ChangeDetectorRef) { }
ngOnInit(): void {
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();
}
}
ngAfterViewInit() {
this.mapWidget = new MapWidgetController(MapProviders.openstreet, false, this.ctx, this.mapContainer.nativeElement);
this.mapWidget.data
}
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)
});
}
}