@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 3.65 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as t}from"tslib";import e from"../../core/Accessor.js";import has from"../../core/has.js";import{clone as s}from"../../core/lang.js";import i from"../../core/Logger.js";import{property as r,subclass as n}from"../../core/accessorSupport/decorators.js";import{parse as c}from"./parser.js";import{canInterpolateEffects as f,normalizeEffects as o}from"./utils.js";const l=-1;let h=class extends e{constructor(t){super(t),this._from=null,this._to=null,this._final=null,this._current=[],this._time=0,this.duration=has("mapview-transitions-duration"),this.effects=[]}set effect(t){if(this._get("effect")!==(t=t||"")){this._set("effect",t);try{this._transitionTo(a(t))}catch(e){this._transitionTo([]),i.getLogger(this).warn("Invalid Effect",{effect:t,error:e})}}}get final(){return this._final}get hasEffects(){return this.transitioning||!!this.effects.length}set scale(t){this._updateForScale(t)}get transitioning(){return null!==this._to}canTransitionTo(t){try{return this.scale>0&&u(this._current,a(t),this.scale)}catch{return!1}}transitionStep(t,e){this._applyTimeTransition(t),this._updateForScale(e)}endTransition(){this._applyTimeTransition(this.duration)}_transitionTo(t){this.scale>0&&u(this._current,t,this.scale)?(this._final=t,this._to=s(t),_(this._current,this._to,this.scale),this._from=s(this._current),this._time=0):(this._from=this._to=this._final=null,this._current=t),this._set("effects",this._current[0]?s(this._current[0].effects):[])}_applyTimeTransition(t){if(!(this._to&&this._from&&this._current&&this._final))return;this._time+=t;const e=Math.min(1,this._time/this.duration);for(let s=0;s<this._current.length;s++){const t=this._current[s],i=this._from[s],r=this._to[s];t.scale=p(i.scale,r.scale,e);for(let s=0;s<t.effects.length;s++){const n=t.effects[s],c=i.effects[s],f=r.effects[s];n.interpolate(c,f,e)}}1===e&&(this._current=this._final,this._set("effects",this._current[0]?s(this._current[0].effects):[]),this._from=this._to=this._final=null)}_updateForScale(t){if(this._set("scale",t),0===this._current.length)return;const e=this._current,s=this._current.length-1;let i,r,n=1;if(1===e.length||t>=e[0].scale)r=i=e[0].effects;else if(t<=e[s].scale)r=i=e[s].effects;else for(let c=0;c<s;c++){const s=e[c],f=e[c+1];if(s.scale>=t&&f.scale<=t){n=(t-s.scale)/(f.scale-s.scale),i=s.effects,r=f.effects;break}}for(let c=0;c<this.effects.length;c++){this.effects[c].interpolate(i[c],r[c],n)}}};function a(t){const e=c(t)||[];return m(e)?[{scale:l,effects:e}]:e}function u(t,e,s){if(!t[0]?.effects||!e[0]?.effects)return!0;return!((t[0]?.scale===l||e[0]?.scale===l)&&(t.length>1||e.length>1)&&s<=0)&&f(t[0].effects,e[0].effects)}function _(t,e,s){const i=t.length>e.length?t:e,r=t.length>e.length?e:t,n=r[r.length-1],c=n?.scale??s,f=n?.effects??[];for(let o=r.length;o<i.length;o++)r.push({scale:c,effects:[...f]});for(let h=0;h<i.length;h++)r[h].scale=r[h].scale===l?s:r[h].scale,i[h].scale=i[h].scale===l?s:i[h].scale,o(r[h].effects,i[h].effects)}function p(t,e,s){return t+(e-t)*s}function m(t){const e=t[0];return!!e&&"type"in e}t([r()],h.prototype,"_to",void 0),t([r()],h.prototype,"duration",void 0),t([r({value:""})],h.prototype,"effect",null),t([r({readOnly:!0})],h.prototype,"effects",void 0),t([r({readOnly:!0})],h.prototype,"final",null),t([r({readOnly:!0})],h.prototype,"hasEffects",null),t([r({value:0})],h.prototype,"scale",null),t([r({readOnly:!0})],h.prototype,"transitioning",null),h=t([n("esri.layers.effects.EffectView")],h);export{h as EffectView,u as canInterpolateEffectStops,a as convertEffectToStops,_ as normalizeEffectStops};