Commit 9346b7fdeed9a3dc3aff0a488c3332a8fcfaa236
Committed by
GitHub
Merge pull request #3972 from vvlladd28/improvement/trip-animation/change-speed
UI: Fixed bug trip animation widget after change speed or change time to the time slider
Showing
2 changed files
with
30 additions
and
32 deletions
... | ... | @@ -24,7 +24,7 @@ |
24 | 24 | <mat-icon class="material-icons" [ngStyle]="{'color': settings.buttonColor}">skip_previous</mat-icon> |
25 | 25 | </button> |
26 | 26 | <div fxLayout="column" fxFlex="100"> |
27 | - <mat-slider [(ngModel)]="index" [min]="minTimeIndex" [max]="maxTimeIndex" (change)="changeIndex()"> | |
27 | + <mat-slider [(ngModel)]="index" [min]="minTimeIndex" [max]="maxTimeIndex" (input)="changeIndex($event.value)"> | |
28 | 28 | </mat-slider> |
29 | 29 | <div class="panel-timer"> |
30 | 30 | <span *ngIf="this.currentTime">{{ this.currentTime | date:'medium'}}</span> |
... | ... | @@ -47,8 +47,8 @@ |
47 | 47 | pause_circle_outline |
48 | 48 | </mat-icon> |
49 | 49 | </button> |
50 | - <mat-select [(ngModel)]="speed" (selectionChange)="reeneble()" class="speed-select" aria-label="Speed selector"> | |
50 | + <mat-select [(ngModel)]="speed" (selectionChange)="reInit()" class="speed-select" aria-label="Speed selector"> | |
51 | 51 | <mat-option [value]="speedValue" *ngFor="let speedValue of speeds">{{speedValue}} </mat-option> |
52 | 52 | </mat-select> |
53 | 53 | </div> |
54 | -</div> | |
\ No newline at end of file | ||
54 | +</div> | ... | ... |
... | ... | @@ -14,7 +14,7 @@ |
14 | 14 | /// limitations under the License. |
15 | 15 | /// |
16 | 16 | |
17 | -import { ChangeDetectorRef, Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core'; | |
17 | +import { ChangeDetectorRef, Component, EventEmitter, Input, OnChanges, Output } from '@angular/core'; | |
18 | 18 | import { interval } from 'rxjs'; |
19 | 19 | import { filter } from 'rxjs/operators'; |
20 | 20 | import { HistorySelectSettings } from '@app/modules/home/components/widget/lib/maps/map-models'; |
... | ... | @@ -24,9 +24,9 @@ import { HistorySelectSettings } from '@app/modules/home/components/widget/lib/m |
24 | 24 | templateUrl: './history-selector.component.html', |
25 | 25 | styleUrls: ['./history-selector.component.scss'] |
26 | 26 | }) |
27 | -export class HistorySelectorComponent implements OnInit, OnChanges { | |
27 | +export class HistorySelectorComponent implements OnChanges { | |
28 | 28 | |
29 | - @Input() settings: HistorySelectSettings | |
29 | + @Input() settings: HistorySelectSettings; | |
30 | 30 | @Input() minTime: number; |
31 | 31 | @Input() maxTime: number; |
32 | 32 | @Input() step = 1000; |
... | ... | @@ -47,9 +47,6 @@ export class HistorySelectorComponent implements OnInit, OnChanges { |
47 | 47 | |
48 | 48 | constructor(private cd: ChangeDetectorRef) { } |
49 | 49 | |
50 | - ngOnInit(): void { | |
51 | - } | |
52 | - | |
53 | 50 | ngOnChanges() { |
54 | 51 | this.maxTimeIndex = Math.ceil((this.maxTime - this.minTime) / this.step); |
55 | 52 | this.currentTime = this.minTime === Infinity ? null : this.minTime; |
... | ... | @@ -57,34 +54,34 @@ export class HistorySelectorComponent implements OnInit, OnChanges { |
57 | 54 | |
58 | 55 | play() { |
59 | 56 | this.playing = true; |
60 | - if (!this.interval) | |
57 | + if (!this.interval) { | |
61 | 58 | this.interval = interval(1000 / this.speed) |
62 | 59 | .pipe( |
63 | - filter(() => this.playing)).subscribe(() => { | |
64 | - this.index++; | |
65 | - this.currentTime = this.minTime + this.index * this.step; | |
66 | - if (this.index <= this.maxTimeIndex) { | |
67 | - this.cd.detectChanges(); | |
68 | - this.timeUpdated.emit(this.currentTime); | |
69 | - } | |
70 | - else { | |
71 | - this.interval.complete(); | |
72 | - } | |
73 | - }, err => { | |
74 | - console.error(err); | |
75 | - }, () => { | |
76 | - this.currentTime = this.index = this.minTimeIndex; | |
60 | + filter(() => this.playing) | |
61 | + ).subscribe(() => { | |
62 | + this.index++; | |
63 | + this.currentTime = this.minTime + this.index * this.step; | |
64 | + if (this.index <= this.maxTimeIndex) { | |
65 | + this.cd.detectChanges(); | |
66 | + this.timeUpdated.emit(this.currentTime); | |
67 | + } else { | |
77 | 68 | this.playing = false; |
78 | - this.interval = null; | |
69 | + this.interval.complete(); | |
79 | 70 | this.cd.detectChanges(); |
80 | - }); | |
71 | + } | |
72 | + }, err => { | |
73 | + console.error(err); | |
74 | + }, () => { | |
75 | + this.interval = null; | |
76 | + }); | |
77 | + } | |
81 | 78 | } |
82 | 79 | |
83 | - reeneble() { | |
84 | - if (this.playing) { | |
85 | - const position = this.index; | |
80 | + reInit() { | |
81 | + if (this.interval) { | |
86 | 82 | this.interval.complete(); |
87 | - this.index = position; | |
83 | + } | |
84 | + if (this.playing) { | |
88 | 85 | this.play(); |
89 | 86 | } |
90 | 87 | } |
... | ... | @@ -138,8 +135,9 @@ export class HistorySelectorComponent implements OnInit, OnChanges { |
138 | 135 | this.pause(); |
139 | 136 | } |
140 | 137 | |
141 | - changeIndex() { | |
142 | - this.currentTime = this.minTime + this.index * this.step; | |
138 | + changeIndex(index: number) { | |
139 | + this.index = index; | |
140 | + this.currentTime = this.minTime + index * this.step; | |
143 | 141 | this.timeUpdated.emit(this.currentTime); |
144 | 142 | } |
145 | 143 | } | ... | ... |