@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 2.78 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{removeMaybe as e}from"../../../../core/maybe.js";import{addFrameTask as s}from"../../../../core/scheduling.js";import{FadeDirection as d}from"../support/I3SLayerView.js";class o{constructor(){this.lodCrossfadeSignedDuration=0}}class i{constructor(e){this._view=e,this._preRenderFrameTaskHandle=null,this._currentFrameStartTime=null,this._numFadingNodes=0}destroy(){this._preRenderFrameTaskHandle?.remove(),this._preRenderFrameTaskHandle=null,this._view=null}get updating(){return this._numFadingNodes>0}stopNodeFading(s){null!=s.lodCrossfadeProgress&&(this._numFadingNodes--,s.lodCrossfadeProgress=null,0===this._numFadingNodes&&(null!=this._preRenderFrameTaskHandle&&(this._preRenderFrameTaskHandle=e(this._preRenderFrameTaskHandle)),this._view.notifyLODUpdate(),this._view.notifyUpdate()))}_startNodeFading(e,d,o){0===this._numFadingNodes&&(this._preRenderFrameTaskHandle=s({preRender:e=>this._updateAllNodeFading(e)}),this._view.notifyLODUpdate()),null==e.lodCrossfadeProgress&&(this._numFadingNodes++,this._view.notifyUpdate()),e.lodCrossfadeSignedDuration=o,e.lodCrossfadeProgress=d}_updateAllNodeFading(e){const s=this._view.nodeCrossfadingEnabled;this._view.foreachCrossfadeNode(((d,o)=>{if(null!=d?.lodCrossfadeProgress){const i=d.lodCrossfadeSignedDuration,t=i>0?this._view.fullOpacity:0,r=e.deltaTime/i,a=d.lodCrossfadeProgress+Math.abs(r),n=!s||a>=1||0===i,l=t-(n?0:i>0?1:-1)*(1-a);n?(this.stopNodeFading(d),i<0&&this._view.markNodeToRemove(o)):d.lodCrossfadeProgress=a,this._view.setNodeOpacityByIndex(o,l)}})),this._view.removeMarkedNodes()}stopAllNodeFading(){this._view.foreachCrossfadeNode(((e,s)=>{if(null!=e?.lodCrossfadeProgress){this.stopNodeFading(e);const d=e.lodCrossfadeSignedDuration;d<0&&this._view.markNodeToRemove(s);const o=d>0?this._view.fullOpacity:0;this._view.setNodeOpacityByIndex(s,o)}})),this._view.removeMarkedNodes()}fadeNode(e,s,o,i){null==this._currentFrameStartTime&&(this._currentFrameStartTime=Date.now());const r=this._view,a=r.nodeCrossfadingEnabled,n=o===d.FadeIn?r.fullOpacity:0,l=a?i?o===d.FadeIn?r.lodCrossfadeinDuration:r.lodCrossfadeoutDuration:r.lodCrossfadeUncoveredDuration:0,h=this._view.getNodeOpacityByIndex(e);if(a&&h!==n&&l>0){const e=1-Math.abs(n-h);this._startNodeFading(s,e,t(o)*l)}else this.stopNodeFading(s),this._view.setNodeOpacityByIndex(e,n),o===d.FadeOut&&this._view.removeNode(e)}isNodeFullyFadedIn(e){const s=this._view.getNodeCrossfadeMetaData(e);return null==s||null==s.lodCrossfadeProgress&&this._view.getNodeOpacityByIndex(e)===this._view.fullOpacity}}function t(e){return e===d.FadeIn?1:-1}export{i as I3SCrossfadeHelper,o as NodeCrossfadeMetaData};