|
|
@ -14,15 +14,19 @@ |
|
|
/// limitations under the License.
|
|
|
/// limitations under the License.
|
|
|
///
|
|
|
///
|
|
|
|
|
|
|
|
|
|
|
|
import L from 'leaflet'; |
|
|
|
|
|
import _ from 'lodash'; |
|
|
|
|
|
import tinycolor from "tinycolor2"; |
|
|
|
|
|
import { interpolateOnPointSegment } from 'leaflet-geometryutil'; |
|
|
|
|
|
|
|
|
import { Component, OnInit, Input, ViewChild, AfterViewInit, ChangeDetectorRef } from '@angular/core'; |
|
|
import { Component, OnInit, Input, ViewChild, AfterViewInit, ChangeDetectorRef } from '@angular/core'; |
|
|
import { MapWidgetController, TbMapWidgetV2 } from '../lib/maps/map-widget2'; |
|
|
import { MapWidgetController, TbMapWidgetV2 } from '../lib/maps/map-widget2'; |
|
|
import { MapProviders } from '../lib/maps/map-models'; |
|
|
import { MapProviders } from '../lib/maps/map-models'; |
|
|
import { parseArray } from '@app/core/utils'; |
|
|
import { parseArray } from '@app/core/utils'; |
|
|
import { interpolateArray } from '../lib/maps/maps-utils'; |
|
|
|
|
|
import tinycolor from "tinycolor2"; |
|
|
|
|
|
import { initSchema, addToSchema, addGroupInfo } from '@app/core/schema-utils'; |
|
|
import { initSchema, addToSchema, addGroupInfo } from '@app/core/schema-utils'; |
|
|
import { tripAnimationSchema } from '../lib/maps/schemes'; |
|
|
import { tripAnimationSchema } from '../lib/maps/schemes'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Component({ |
|
|
@Component({ |
|
|
selector: 'trip-animation', |
|
|
selector: 'trip-animation', |
|
|
templateUrl: './trip-animation.component.html', |
|
|
templateUrl: './trip-animation.component.html', |
|
|
@ -41,6 +45,8 @@ export class TripAnimationComponent implements OnInit, AfterViewInit { |
|
|
interpolatedData = []; |
|
|
interpolatedData = []; |
|
|
widgetConfig; |
|
|
widgetConfig; |
|
|
settings; |
|
|
settings; |
|
|
|
|
|
mainTooltip; |
|
|
|
|
|
activeTrip; |
|
|
|
|
|
|
|
|
constructor(private cd: ChangeDetectorRef) { } |
|
|
constructor(private cd: ChangeDetectorRef) { } |
|
|
|
|
|
|
|
|
@ -57,19 +63,27 @@ export class TripAnimationComponent implements OnInit, AfterViewInit { |
|
|
let subscription = this.ctx.subscriptions[Object.keys(this.ctx.subscriptions)[0]]; |
|
|
let subscription = this.ctx.subscriptions[Object.keys(this.ctx.subscriptions)[0]]; |
|
|
if (subscription) subscription.callbacks.onDataUpdated = (updated) => { |
|
|
if (subscription) subscription.callbacks.onDataUpdated = (updated) => { |
|
|
this.historicalData = parseArray(this.ctx.data); |
|
|
this.historicalData = parseArray(this.ctx.data); |
|
|
|
|
|
this.activeTrip = this.historicalData[0][0]; |
|
|
this.calculateIntervals(); |
|
|
this.calculateIntervals(); |
|
|
this.timeUpdated(this.intervals[0]); |
|
|
this.timeUpdated(this.intervals[0]); |
|
|
this.mapWidget.map.map.invalidateSize(); |
|
|
this.mapWidget.map.map?.invalidateSize(); |
|
|
this.cd.detectChanges(); |
|
|
this.cd.detectChanges(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ngAfterViewInit() { |
|
|
ngAfterViewInit() { |
|
|
this.mapWidget = new MapWidgetController(MapProviders.openstreet, false, this.ctx, this.mapContainer.nativeElement); |
|
|
let ctxCopy = _.cloneDeep(this.ctx); |
|
|
|
|
|
ctxCopy.settings.showLabel = false; |
|
|
|
|
|
this.mapWidget = new MapWidgetController(MapProviders.openstreet, false, ctxCopy, this.mapContainer.nativeElement); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
timeUpdated(time) { |
|
|
timeUpdated(time) { |
|
|
const currentPosition = this.interpolatedData.map(dataSource => dataSource[time]); |
|
|
const currentPosition = this.interpolatedData.map(dataSource => dataSource[time]); |
|
|
|
|
|
this.activeTrip = currentPosition[0]; |
|
|
|
|
|
this.mapWidget.map.updatePolylines(this.interpolatedData); |
|
|
|
|
|
if (this.settings.showPolygon) { |
|
|
|
|
|
this.mapWidget.map.updatePolygons(this.interpolatedData); |
|
|
|
|
|
} |
|
|
this.mapWidget.map.updateMarkers(currentPosition); |
|
|
this.mapWidget.map.updateMarkers(currentPosition); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -80,10 +94,47 @@ export class TripAnimationComponent implements OnInit, AfterViewInit { |
|
|
this.intervals.push(time); |
|
|
this.intervals.push(time); |
|
|
} |
|
|
} |
|
|
this.intervals.push(dataSource[dataSource.length - 1]?.time); |
|
|
this.intervals.push(dataSource[dataSource.length - 1]?.time); |
|
|
this.interpolatedData[index] = interpolateArray(dataSource, this.intervals); |
|
|
this.interpolatedData[index] = this.interpolateArray(dataSource, this.intervals); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
showHideTooltip() { |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
interpolateArray(originData, interpolatedIntervals) { |
|
|
|
|
|
|
|
|
|
|
|
const getRatio = (firsMoment, secondMoment, intermediateMoment) => { |
|
|
|
|
|
return (intermediateMoment - firsMoment) / (secondMoment - firsMoment); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
function findAngle(startPoint, endPoint) { |
|
|
|
|
|
let angle = -Math.atan2(endPoint.latitude - startPoint.latitude, endPoint.longitude - startPoint.longitude); |
|
|
|
|
|
angle = angle * 180 / Math.PI; |
|
|
|
|
|
return parseInt(angle.toFixed(2)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const result = {}; |
|
|
|
|
|
|
|
|
|
|
|
for (let i = 1, j = 0; i < originData.length, j < interpolatedIntervals.length;) { |
|
|
|
|
|
const currentTime = interpolatedIntervals[j]; |
|
|
|
|
|
while (originData[i].time < currentTime) i++; |
|
|
|
|
|
const before = originData[i - 1]; |
|
|
|
|
|
const after = originData[i]; |
|
|
|
|
|
const interpolation = interpolateOnPointSegment( |
|
|
|
|
|
new L.Point(before.latitude, before.longitude), |
|
|
|
|
|
new L.Point(after.latitude, after.longitude), |
|
|
|
|
|
getRatio(before.time, after.time, currentTime)); |
|
|
|
|
|
result[currentTime] = ({ |
|
|
|
|
|
...originData[i], |
|
|
|
|
|
rotationAngle: findAngle(before, after) + this.settings.rotationAngle, |
|
|
|
|
|
latitude: interpolation.x, |
|
|
|
|
|
longitude: interpolation.y |
|
|
|
|
|
}); |
|
|
|
|
|
j++; |
|
|
|
|
|
} |
|
|
|
|
|
return result; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
static getSettingsSchema() { |
|
|
static getSettingsSchema() { |
|
|
let schema = initSchema(); |
|
|
let schema = initSchema(); |
|
|
addToSchema(schema, TbMapWidgetV2.getProvidersSchema()); |
|
|
addToSchema(schema, TbMapWidgetV2.getProvidersSchema()); |
|
|
|