|
|
|
@ -14,7 +14,7 @@ |
|
|
|
/// limitations under the License.
|
|
|
|
///
|
|
|
|
|
|
|
|
import { ChangeDetectorRef, Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core'; |
|
|
|
import { ChangeDetectorRef, Component, EventEmitter, Input, OnChanges, Output } from '@angular/core'; |
|
|
|
import { interval } from 'rxjs'; |
|
|
|
import { filter } from 'rxjs/operators'; |
|
|
|
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 |
|
|
|
templateUrl: './history-selector.component.html', |
|
|
|
styleUrls: ['./history-selector.component.scss'] |
|
|
|
}) |
|
|
|
export class HistorySelectorComponent implements OnInit, OnChanges { |
|
|
|
export class HistorySelectorComponent implements OnChanges { |
|
|
|
|
|
|
|
@Input() settings: HistorySelectSettings |
|
|
|
@Input() settings: HistorySelectSettings; |
|
|
|
@Input() minTime: number; |
|
|
|
@Input() maxTime: number; |
|
|
|
@Input() step = 1000; |
|
|
|
@ -47,9 +47,6 @@ export class HistorySelectorComponent implements OnInit, OnChanges { |
|
|
|
|
|
|
|
constructor(private cd: ChangeDetectorRef) { } |
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
|
} |
|
|
|
|
|
|
|
ngOnChanges() { |
|
|
|
this.maxTimeIndex = Math.ceil((this.maxTime - this.minTime) / this.step); |
|
|
|
this.currentTime = this.minTime === Infinity ? null : this.minTime; |
|
|
|
@ -57,34 +54,34 @@ export class HistorySelectorComponent implements OnInit, OnChanges { |
|
|
|
|
|
|
|
play() { |
|
|
|
this.playing = true; |
|
|
|
if (!this.interval) |
|
|
|
if (!this.interval) { |
|
|
|
this.interval = interval(1000 / this.speed) |
|
|
|
.pipe( |
|
|
|
filter(() => this.playing)).subscribe(() => { |
|
|
|
this.index++; |
|
|
|
this.currentTime = this.minTime + this.index * this.step; |
|
|
|
if (this.index <= this.maxTimeIndex) { |
|
|
|
this.cd.detectChanges(); |
|
|
|
this.timeUpdated.emit(this.currentTime); |
|
|
|
} |
|
|
|
else { |
|
|
|
this.interval.complete(); |
|
|
|
} |
|
|
|
}, err => { |
|
|
|
console.error(err); |
|
|
|
}, () => { |
|
|
|
this.currentTime = this.index = this.minTimeIndex; |
|
|
|
filter(() => this.playing) |
|
|
|
).subscribe(() => { |
|
|
|
this.index++; |
|
|
|
this.currentTime = this.minTime + this.index * this.step; |
|
|
|
if (this.index <= this.maxTimeIndex) { |
|
|
|
this.cd.detectChanges(); |
|
|
|
this.timeUpdated.emit(this.currentTime); |
|
|
|
} else { |
|
|
|
this.playing = false; |
|
|
|
this.interval = null; |
|
|
|
this.interval.complete(); |
|
|
|
this.cd.detectChanges(); |
|
|
|
}); |
|
|
|
} |
|
|
|
}, err => { |
|
|
|
console.error(err); |
|
|
|
}, () => { |
|
|
|
this.interval = null; |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
reeneble() { |
|
|
|
if (this.playing) { |
|
|
|
const position = this.index; |
|
|
|
reInit() { |
|
|
|
if (this.interval) { |
|
|
|
this.interval.complete(); |
|
|
|
this.index = position; |
|
|
|
} |
|
|
|
if (this.playing) { |
|
|
|
this.play(); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -138,8 +135,9 @@ export class HistorySelectorComponent implements OnInit, OnChanges { |
|
|
|
this.pause(); |
|
|
|
} |
|
|
|
|
|
|
|
changeIndex() { |
|
|
|
this.currentTime = this.minTime + this.index * this.step; |
|
|
|
changeIndex(index: number) { |
|
|
|
this.index = index; |
|
|
|
this.currentTime = this.minTime + index * this.step; |
|
|
|
this.timeUpdated.emit(this.currentTime); |
|
|
|
} |
|
|
|
} |
|
|
|
|