Commit c24b46996ae5faee8b70af824d453cac60892975
1 parent
096b2944
Fix not correct use coordinate key
Showing
2 changed files
with
20 additions
and
18 deletions
... | ... | @@ -56,10 +56,10 @@ export function getRatio(firsMoment: number, secondMoment: number, intermediateM |
56 | 56 | return (intermediateMoment - firsMoment) / (secondMoment - firsMoment); |
57 | 57 | } |
58 | 58 | |
59 | -export function findAngle(startPoint, endPoint) { | |
60 | - let angle = -Math.atan2(endPoint.latitude - startPoint.latitude, endPoint.longitude - startPoint.longitude); | |
61 | - angle = angle * 180 / Math.PI; | |
62 | - return parseInt(angle.toFixed(2), 10); | |
59 | +export function findAngle(startPoint: FormattedData, endPoint: FormattedData, latKeyName: string, lngKeyName: string): number { | |
60 | + let angle = -Math.atan2(endPoint[latKeyName] - startPoint[latKeyName], endPoint[lngKeyName] - startPoint[lngKeyName]); | |
61 | + angle = angle * 180 / Math.PI; | |
62 | + return parseInt(angle.toFixed(2), 10); | |
63 | 63 | } |
64 | 64 | |
65 | 65 | ... | ... |
... | ... | @@ -21,9 +21,9 @@ import { interpolateOnPointSegment } from 'leaflet-geometryutil'; |
21 | 21 | |
22 | 22 | import { AfterViewInit, ChangeDetectorRef, Component, Input, OnInit, SecurityContext, ViewChild } from '@angular/core'; |
23 | 23 | import { MapWidgetController, TbMapWidgetV2 } from '../lib/maps/map-widget2'; |
24 | -import { MapProviders, FormattedData } from '../lib/maps/map-models'; | |
25 | -import { initSchema, addToSchema, addGroupInfo, addCondition } from '@app/core/schema-utils'; | |
26 | -import { tripAnimationSchema, mapPolygonSchema, pathSchema, pointSchema } from '../lib/maps/schemes'; | |
24 | +import { FormattedData, MapProviders } from '../lib/maps/map-models'; | |
25 | +import { addCondition, addGroupInfo, addToSchema, initSchema } from '@app/core/schema-utils'; | |
26 | +import { mapPolygonSchema, pathSchema, pointSchema, tripAnimationSchema } from '../lib/maps/schemes'; | |
27 | 27 | import { DomSanitizer } from '@angular/platform-browser'; |
28 | 28 | import { WidgetContext } from '@app/modules/home/models/widget-component.models'; |
29 | 29 | import { findAngle, getRatio, parseArray, parseWithTranslation, safeExecute } from '../lib/maps/maps-utils'; |
... | ... | @@ -86,17 +86,19 @@ export class TripAnimationComponent implements OnInit, AfterViewInit { |
86 | 86 | rotationAngle: 0 |
87 | 87 | } |
88 | 88 | this.settings = { ...settings, ...this.ctx.settings }; |
89 | - this.useAnchors = this.settings.usePointAsAnchor && this.settings.showPoints; | |
89 | + this.useAnchors = this.settings.showPoints && this.settings.usePointAsAnchor; | |
90 | 90 | this.settings.fitMapBounds = true; |
91 | 91 | this.normalizationStep = this.settings.normalizationStep; |
92 | 92 | const subscription = this.ctx.subscriptions[Object.keys(this.ctx.subscriptions)[0]]; |
93 | - if (subscription) subscription.callbacks.onDataUpdated = () => { | |
94 | - this.historicalData = parseArray(this.ctx.data); | |
95 | - this.activeTrip = this.historicalData[0][0]; | |
96 | - this.calculateIntervals(); | |
97 | - this.timeUpdated(this.intervals[0]); | |
98 | - this.mapWidget.map.map?.invalidateSize(); | |
99 | - this.cd.detectChanges(); | |
93 | + if (subscription) { | |
94 | + subscription.callbacks.onDataUpdated = () => { | |
95 | + this.historicalData = parseArray(this.ctx.data); | |
96 | + this.activeTrip = this.historicalData[0][0]; | |
97 | + this.calculateIntervals(); | |
98 | + this.timeUpdated(this.intervals[0]); | |
99 | + this.mapWidget.map.map?.invalidateSize(); | |
100 | + this.cd.detectChanges(); | |
101 | + } | |
100 | 102 | } |
101 | 103 | } |
102 | 104 | |
... | ... | @@ -174,12 +176,12 @@ export class TripAnimationComponent implements OnInit, AfterViewInit { |
174 | 176 | const before = originData[i - 1]; |
175 | 177 | const after = originData[i]; |
176 | 178 | const interpolation = interpolateOnPointSegment( |
177 | - new L.Point(before.latitude, before.longitude), | |
178 | - new L.Point(after.latitude, after.longitude), | |
179 | + new L.Point(before[this.settings.latKeyName], before[this.settings.lngKeyName]), | |
180 | + new L.Point(after[this.settings.latKeyName], after[this.settings.lngKeyName]), | |
179 | 181 | getRatio(before.time, after.time, currentTime)); |
180 | 182 | result[currentTime] = ({ |
181 | 183 | ...originData[i], |
182 | - rotationAngle: findAngle(before, after) + this.settings.rotationAngle, | |
184 | + rotationAngle: findAngle(before, after, this.settings.latKeyName, this.settings.lngKeyName) + this.settings.rotationAngle, | |
183 | 185 | latitude: interpolation.x, |
184 | 186 | longitude: interpolation.y |
185 | 187 | }); | ... | ... |