1 | import ZoomHistory from './zoom_history';
|
2 | import {isStringInSupportedScript} from '../util/script_detection';
|
3 | import {plugin as rtlTextPlugin} from '../source/rtl_text_plugin';
|
4 |
|
5 | import type {TransitionSpecification} from '../style-spec/types.g';
|
6 |
|
7 | export type CrossfadeParameters = {
|
8 | fromScale: number;
|
9 | toScale: number;
|
10 | t: number;
|
11 | };
|
12 |
|
13 | class EvaluationParameters {
|
14 | zoom: number;
|
15 | now: number;
|
16 | fadeDuration: number;
|
17 | zoomHistory: ZoomHistory;
|
18 | transition: TransitionSpecification;
|
19 |
|
20 |
|
21 | constructor(zoom: number, options?: any) {
|
22 | this.zoom = zoom;
|
23 |
|
24 | if (options) {
|
25 | this.now = options.now;
|
26 | this.fadeDuration = options.fadeDuration;
|
27 | this.zoomHistory = options.zoomHistory;
|
28 | this.transition = options.transition;
|
29 | } else {
|
30 | this.now = 0;
|
31 | this.fadeDuration = 0;
|
32 | this.zoomHistory = new ZoomHistory();
|
33 | this.transition = {};
|
34 | }
|
35 | }
|
36 |
|
37 | isSupportedScript(str: string): boolean {
|
38 | return isStringInSupportedScript(str, rtlTextPlugin.isLoaded());
|
39 | }
|
40 |
|
41 | crossFadingFactor() {
|
42 | if (this.fadeDuration === 0) {
|
43 | return 1;
|
44 | } else {
|
45 | return Math.min((this.now - this.zoomHistory.lastIntegerZoomTime) / this.fadeDuration, 1);
|
46 | }
|
47 | }
|
48 |
|
49 | getCrossfadeParameters(): CrossfadeParameters {
|
50 | const z = this.zoom;
|
51 | const fraction = z - Math.floor(z);
|
52 | const t = this.crossFadingFactor();
|
53 |
|
54 | return z > this.zoomHistory.lastIntegerZoom ?
|
55 | {fromScale: 2, toScale: 1, t: fraction + (1 - fraction) * t} :
|
56 | {fromScale: 0.5, toScale: 1, t: 1 - (1 - t) * fraction};
|
57 | }
|
58 | }
|
59 |
|
60 | export default EvaluationParameters;
|