@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 2.99 kB
JavaScript
import{Seconds as t}from"../../../core/time.js";class i{get time(){return this._time}constructor(t){t&&this.update(t)}update(t){t&&(this.definition?this.definition.copyFrom(t):this.definition=t.clone()),this._updatePrecomputedVariables(),this._updatePixelFlow()}_updatePrecomputedVariables(){const t=this.definition,i=t.compared,o=i.sourceZoom,e=i.targetZoom;this._zoomSign=o>e?1:-1,this._panPixelsAtSource=i.pan*t.source.pixelsPerPanAtZoom(o);const n=(t.source.pixelsPerRotateAtZoom(o)+t.target.pixelsPerRotateAtZoom(e))/2;this._rotatePixels=i.rotate*n}_updatePixelFlow(){const i=this.definition.compared.sourceZoom,o=this.definition.compared.targetZoom,{hasZoom:e,hasPan:n,hasRotate:s}=this.definition;let a=0,h=0;e&&(n&&(a=(o/i-1)/(-1/(this._zoomSign*this.definition.halfWindowSize)*Math.LN2*this._panPixelsAtSource)),s&&(h=this._zoomSign*(Math.log(i/o)/Math.LN2)*this.definition.halfWindowSize/this._rotatePixels)),this._zoomPixelFlow=0,this._panPixelFlow=0,this._rotatePixelFlow=0;const l=this.definition.desiredPixelFlow;if(e&&n&&s){const t=a+h+a*h;this._zoomPixelFlow=a*h/t*l,this._panPixelFlow=h/t*l,this._rotatePixelFlow=a/t*l}else if(e&&n){const t=1+a;this._zoomPixelFlow=a/t*l,this._panPixelFlow=1/t*l}else if(e&&s){const t=1+h;this._zoomPixelFlow=h/t*l,this._rotatePixelFlow=1/t*l}else if(n&&s){const t=this._panPixelsAtSource/this._rotatePixels,i=1+t;this._panPixelFlow=t/i*l,this._rotatePixelFlow=1/i*l}else n?this._panPixelFlow=l:e?this._zoomPixelFlow=l:s&&(this._rotatePixelFlow=l);this._time=s?this.rotateTime:e?this.zoomTime:n?this.panTime:t(0)}get rotateTime(){return this.definition.hasRotate?t(this._rotatePixels/this._rotatePixelFlow):t(0)}get zoomTime(){return this.definition.hasZoom?t(this._zoomSign*(Math.log(this.definition.compared.sourceZoom/this.definition.compared.targetZoom)/Math.LN2)*this.definition.halfWindowSize/this._zoomPixelFlow):t(0)}get panTime(){if(this.definition.hasPan){if(this.definition.hasZoom){const i=-1/(this._zoomSign*this.definition.halfWindowSize)*Math.LN2,o=i*this._panPixelsAtSource;return t(Math.log(o*(this._zoomPixelFlow/this._panPixelFlow)+1)/(i*this._zoomPixelFlow))}return t(this._panPixelsAtSource/this._panPixelFlow)}return t(0)}_interpolateComponentsZoom(t){if(0===t||1===t)return t;if(this.definition.hasZoom){const i=this.definition.compared.sourceZoom,o=this.definition.compared.targetZoom;return(i*(i/o)**-t-i)/(o-i)}return t}_interpolateComponentsPan(t){if(0===t||1===t)return t;if(this.definition.hasPan&&this.definition.hasZoom){const i=-1/(this._zoomSign*this.definition.halfWindowSize)*this._zoomPixelFlow;return 1/this._panPixelsAtSource*(this._panPixelFlow*(2**(i*t*this._time)-1))/(i*Math.LN2)}return t}_interpolateComponentsRotate(t){return t}interpolateComponentsAt(t,i){t=Math.min(Math.max(t,0),1);const o=this._interpolateComponentsZoom(t),e=this._interpolateComponentsPan(t),n=this._interpolateComponentsRotate(t);return i?(i.zoom=o,i.pan=e,i.rotate=n):i={zoom:o,pan:e,rotate:n},i}}export{i as Segment};