Merge pull request #2792 from vvlladd28/improvement/map/anchor-point

Improvment anchor function and fix show point [trip-animation]
This commit is contained in:
Igor Kulikov 2020-05-19 10:33:02 +03:00 committed by GitHub
commit 6f065804a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 60 additions and 38 deletions

View File

@ -345,8 +345,8 @@ export default abstract class LeafletMap {
updatePolylines(polyData: FormattedData[][], data?: FormattedData) { updatePolylines(polyData: FormattedData[][], data?: FormattedData) {
polyData.forEach((dataSource) => { polyData.forEach((dataSource) => {
data = data || dataSource[0];
if (dataSource.length) { if (dataSource.length) {
data = data || dataSource[0];
if (this.polylines.get(data.$datasource.entityName)) { if (this.polylines.get(data.$datasource.entityName)) {
this.updatePolyline(data, dataSource, this.options); this.updatePolyline(data, dataSource, this.options);
} }

View File

@ -860,15 +860,15 @@ export const pointSchema =
type: 'number', type: 'number',
default: 10 default: 10
}, },
// usePointAsAnchor: { usePointAsAnchor: {
// title: 'Use point as anchor', title: 'Use point as anchor',
// type: 'boolean', type: 'boolean',
// default: false default: false
// }, },
// pointAsAnchorFunction: { pointAsAnchorFunction: {
// title: 'Point as anchor function: f(data, dsData, dsIndex)', title: 'Point as anchor function: f(data, dsData, dsIndex)',
// type: 'string' type: 'string'
// }, },
pointTooltipOnRightPanel: { pointTooltipOnRightPanel: {
title: 'Independant point tooltip', title: 'Independant point tooltip',
type: 'boolean', type: 'boolean',
@ -884,11 +884,11 @@ export const pointSchema =
type: 'color' type: 'color'
}, },
'pointSize', 'pointSize',
// 'usePointAsAnchor', 'usePointAsAnchor',
// { {
// key: 'pointAsAnchorFunction', key: 'pointAsAnchorFunction',
// type: 'javascript' type: 'javascript'
// }, },
'pointTooltipOnRightPanel', 'pointTooltipOnRightPanel',
] ]
}; };

View File

@ -37,5 +37,7 @@
[minTime]="minTime" [minTime]="minTime"
[maxTime]="maxTime" [maxTime]="maxTime"
[step]="normalizationStep" [step]="normalizationStep"
[anchors]="anchors"
[useAnchors]="useAnchors"
(timeUpdated)="timeUpdated($event)"></tb-history-selector> (timeUpdated)="timeUpdated($event)"></tb-history-selector>
</div> </div>

View File

@ -29,6 +29,7 @@ import {
getRatio, getRatio,
interpolateOnLineSegment, interpolateOnLineSegment,
parseArray, parseArray,
parseFunction,
parseWithTranslation, parseWithTranslation,
safeExecute safeExecute
} from '../lib/maps/maps-utils'; } from '../lib/maps/maps-utils';
@ -65,7 +66,7 @@ export class TripAnimationComponent implements OnInit, AfterViewInit {
minTimeFormat: string; minTimeFormat: string;
maxTime: number; maxTime: number;
maxTimeFormat: string; maxTimeFormat: string;
anchors = []; anchors: number[] = [];
useAnchors: boolean; useAnchors: boolean;
static getSettingsSchema(): JsonSettingsSchema { static getSettingsSchema(): JsonSettingsSchema {
@ -94,6 +95,7 @@ export class TripAnimationComponent implements OnInit, AfterViewInit {
} }
this.settings = { ...settings, ...this.ctx.settings }; this.settings = { ...settings, ...this.ctx.settings };
this.useAnchors = this.settings.showPoints && this.settings.usePointAsAnchor; this.useAnchors = this.settings.showPoints && this.settings.usePointAsAnchor;
this.settings.pointAsAnchorFunction = parseFunction(this.settings.pointAsAnchorFunction, ['data', 'dsData', 'dsIndex']);
this.settings.fitMapBounds = true; this.settings.fitMapBounds = true;
this.normalizationStep = this.settings.normalizationStep; this.normalizationStep = this.settings.normalizationStep;
const subscription = this.ctx.subscriptions[Object.keys(this.ctx.subscriptions)[0]]; const subscription = this.ctx.subscriptions[Object.keys(this.ctx.subscriptions)[0]];
@ -141,11 +143,7 @@ export class TripAnimationComponent implements OnInit, AfterViewInit {
this.mapWidget.map.updatePolygons(this.interpolatedTimeData); this.mapWidget.map.updatePolygons(this.interpolatedTimeData);
} }
if (this.settings.showPoints) { if (this.settings.showPoints) {
this.mapWidget.map.updatePoints(this.interpolatedTimeData, this.calcTooltip); this.mapWidget.map.updatePoints(_.values(_.union(this.interpolatedTimeData)[0]), this.calcTooltip);
// this.anchors = this.interpolatedTimeData
// .filter(data =>
// this.settings.usePointAsAnchor ||
// safeExecute(this.settings.pointAsAnchorFunction, [this.interpolatedTimeData, data, data.dsIndex])).map(data => data.time);
} }
this.mapWidget.map.updateMarkers(currentPosition); this.mapWidget.map.updateMarkers(currentPosition);
} }
@ -162,7 +160,12 @@ export class TripAnimationComponent implements OnInit, AfterViewInit {
this.maxTimeFormat = this.maxTime !== -Infinity ? moment(this.maxTime).format('YYYY-MM-DD HH:mm:ss') : ''; this.maxTimeFormat = this.maxTime !== -Infinity ? moment(this.maxTime).format('YYYY-MM-DD HH:mm:ss') : '';
this.interpolatedTimeData[index] = this.interpolateArray(dataSource); this.interpolatedTimeData[index] = this.interpolateArray(dataSource);
}); });
if (this.useAnchors) {
const anchorDate = Object.entries(_.union(this.interpolatedTimeData)[0]);
this.anchors = anchorDate
.filter((data: [string, FormattedData]) => safeExecute(this.settings.pointAsAnchorFunction, [data[1], anchorDate, data[1].dsIndex]))
.map(data => parseInt(data[0], 10));
}
} }
calcTooltip = (point?: FormattedData, setTooltip = true) => { calcTooltip = (point?: FormattedData, setTooltip = true) => {
@ -200,20 +203,17 @@ export class TripAnimationComponent implements OnInit, AfterViewInit {
const result = {}; const result = {};
const latKeyName = this.settings.latKeyName; const latKeyName = this.settings.latKeyName;
const lngKeyName = this.settings.lngKeyName; const lngKeyName = this.settings.lngKeyName;
for (let i = 0; i < originData.length; i++) { for (const data of originData) {
const currentTime = originData[i].time; const currentTime = data.time;
const normalizeTime = this.minTime + Math.ceil((currentTime - this.minTime) / this.normalizationStep) * this.normalizationStep; const normalizeTime = this.minTime + Math.ceil((currentTime - this.minTime) / this.normalizationStep) * this.normalizationStep;
if (i !== originData.length - 1) { result[normalizeTime] = {
result[normalizeTime] = { ...data,
...originData[i], rotationAngle: this.settings.rotationAngle
rotationAngle: this.settings.rotationAngle + findAngle(originData[i], originData[i + 1], latKeyName, lngKeyName) };
}; }
} else { const timeStamp = Object.keys(result);
result[normalizeTime] = { for(let i = 0; i < timeStamp.length - 1; i++){
...originData[i], result[timeStamp[i]].rotationAngle += findAngle(result[timeStamp[i]], result[timeStamp[i + 1]], latKeyName, lngKeyName)
rotationAngle: this.settings.rotationAngle + findAngle(originData[i - 1], originData[i], latKeyName, lngKeyName)
};
}
} }
return result; return result;
} }

View File

@ -30,6 +30,8 @@ export class HistorySelectorComponent implements OnInit, OnChanges {
@Input() minTime: number; @Input() minTime: number;
@Input() maxTime: number; @Input() maxTime: number;
@Input() step = 1000; @Input() step = 1000;
@Input() anchors = [];
@Input() useAnchors = false;
@Output() timeUpdated: EventEmitter<number> = new EventEmitter(); @Output() timeUpdated: EventEmitter<number> = new EventEmitter();
@ -95,19 +97,37 @@ export class HistorySelectorComponent implements OnInit, OnChanges {
} }
moveNext() { moveNext() {
if (this.index <= this.maxTimeIndex) { if (this.index < this.maxTimeIndex) {
this.index++; if (this.useAnchors) {
const anchorIndex = this.findIndex(this.currentTime, this.anchors) + 1;
this.index = Math.floor((this.anchors[anchorIndex] - this.minTime) / this.step);
} else {
this.index++;
}
} }
this.pause(); this.pause();
} }
movePrev() { movePrev() {
if (this.index > this.minTimeIndex) { if (this.index > this.minTimeIndex) {
this.index--; if (this.useAnchors) {
const anchorIndex = this.findIndex(this.currentTime, this.anchors) - 1;
this.index = Math.floor((this.anchors[anchorIndex] - this.minTime) / this.step);
} else {
this.index--;
}
} }
this.pause(); this.pause();
} }
findIndex(value: number, array: number[]): number {
let i = 0;
while (array[i] < value) {
i++;
}
return i;
}
moveStart() { moveStart() {
this.index = this.minTimeIndex; this.index = this.minTimeIndex;
this.pause(); this.pause();