UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 3.48 kB
import{_ as t}from"../../chunks/tslib.es6.js";import"../../geometry.js";import i from"../../Viewpoint.js";import s from"../../core/Accessor.js";import{removeMaybe as e}from"../../core/maybe.js";import{addFrameTask as o}from"../../core/scheduling.js";import{property as n}from"../../core/accessorSupport/decorators/property.js";import"../../core/accessorSupport/ensureType.js";import"../../core/arrayUtils.js";import{subclass as a}from"../../core/accessorSupport/decorators/subclass.js";import r from"../ViewAnimation.js";import{easingFunctions as h,parse as p}from"./unitBezier.js";import{copy as c}from"./viewpointUtils.js";import m from"../../geometry/Point.js";class u{constructor(t,i,s,e){const o=t.targetGeometry,n=i.targetGeometry;e?"string"==typeof e&&(e=p(e)||h.ease):e=h.ease,this.easing=e,this.duration=s,this.sCenterX=o.x,this.sCenterY=o.y,this.sScale=t.scale,this.sRotation=t.rotation,this.tCenterX=n.x,this.tCenterY=n.y,this.tScale=i.scale,this.tRotation=i.rotation,this.dCenterX=this.tCenterX-this.sCenterX,this.dCenterY=this.tCenterY-this.sCenterY,this.dScale=this.tScale-this.sScale,this.dRotation=this.tRotation-this.sRotation,this.dRotation>180?this.dRotation-=360:this.dRotation<-180&&(this.dRotation+=360)}applyRatio(t,i){const s=this.easing(i);let e,o,n,a;i>=1?(e=this.tCenterX,o=this.tCenterY,n=this.tRotation,a=this.tScale):(e=this.sCenterX+s*this.dCenterX,o=this.sCenterY+s*this.dCenterY,n=this.sRotation+s*this.dRotation,a=this.sScale+s*this.dScale),t.targetGeometry.x=e,t.targetGeometry.y=o,t.scale=a,t.rotation=n}}let d=class extends s{constructor(t){super(t),this.updateFunction=null,this.animation=null,this.duration=200,this.transition=null,this.easing=h.ease,this.view=null,this.viewpoint=new i({targetGeometry:new m,scale:0,rotation:0}),this._updateTask=o({postRender:this._postRender.bind(this)}),this._updateTask.pause()}destroy(){this._updateTask=e(this._updateTask)}animate(t,i,s){this.stop();const e=this.viewpoint;c(e,i),this.transition=new u(this.viewpoint,t.target,s&&s.duration||this.duration,s&&s.easing||this.easing);const o=()=>{this.animation===t&&this._updateTask&&("finished"===t.state&&(this.transition?.applyRatio(this.viewpoint,1),this.view?.state&&(this.view.state.viewpoint=this.viewpoint.clone())),this.animation=null,this.updateFunction=null)};return t.when(o,o),this._startTime=performance.now(),this._updateTask.resume(),this.animation=t,t}animateContinous(t,i){this.stop(),this.updateFunction=i,this.viewpoint=t;const s=new r({target:t.clone()}),e=()=>{this.animation===s&&this._updateTask&&(this.animation=null,this.updateFunction=null)};return s.when(e,e),this._startTime=performance.now(),this._updateTask.resume(),this.animation=s,s}stop(){this.animation&&(this.animation.stop(),this.animation=null,this.updateFunction=null)}_postRender(t){const i=this.animation;if(i&&i.state!==r.State.STOPPED){if(this.updateFunction)this.updateFunction(this.viewpoint,t.deltaTime);else{const t=this.transition,i=(performance.now()-this._startTime)/t.duration,s=i>=1;t.applyRatio(this.viewpoint,i),s&&this.animation?.finish()}this.view?.state&&(this.view.state.viewpoint=this.viewpoint.clone())}else this._updateTask.pause()}};t([n()],d.prototype,"animation",void 0),t([n()],d.prototype,"duration",void 0),t([n()],d.prototype,"transition",void 0),t([n()],d.prototype,"easing",void 0),t([n()],d.prototype,"view",void 0),t([n()],d.prototype,"viewpoint",void 0),d=t([a("esri.views.2d.AnimationManager")],d);const l=d;export{l as default};