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