UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 2.87 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import e from"../../../../core/PooledArray.js";import{NodeState as i}from"./I3SNode.js";import{FadeDirection as s}from"../support/I3SLayerView.js";class o{constructor(e){this._layerView=e,this._lodGlobalDirty=!1}startNodeLoading(e,i,s){this._maxLodLevel=s.maxLodLevel,this._index=i,this._removeNodes=e}shouldLoadNode(e){if(null==e)return!1;const i=this._index.nodeTraversalState(e);return!!this._isChosenMaxLOD(i)||!!i.isChosen&&this._childrenRequireLoading(e)}setLodGlobalDirty(){this._lodGlobalDirty=!0}get requiresLODGlobalHandling(){return null!=this._index&&!0===this._lodGlobalDirty}lodGlobalHandling(e){if(!this.requiresLODGlobalHandling)return!1;this._lodGlobalDirty=!1;const i=this._layerView.view.resourceController.memoryController.usedMemory,s=Math.max(0,Math.floor(10*(i-1)));t.clear(),this._lodGlobalHandling(this._index.rootNode,s,!1,!!this._layerView.nodeCrossfadingEnabled);const o=t.length;this._removeNodes(t,e);const d=t.length<o;return 0!==t.length&&(this._lodGlobalDirty=!0),t.clear(),d}_lodGlobalHandling(e,o,d,l){if(null==e)return!1;const n=e.index,r=this._index,a=this._layerView,h=r.nodeTraversalState(e),u=this._isChosenMaxLOD(h),_=e.resources.isEmpty;if(u&&_)return e.childrenLoaded>0&&this._removeChildrenRecursive(e),!0;const c=a.isNodeLoaded(n);if(l&&c&&u){const i=!d&&this.hasNoVisibleChildren(e);a.fadeNode(n,s.FadeIn,!i)}const x=c&&(!a.isNodeFullyFadedIn||a.isNodeFullyFadedIn(n));if(c&&(a.updateNodeState(n,u?i.Leaf:i.Hole),u))return x&&this._removeChildrenRecursive(e),x;const L=e.childCount>0;let y=L;if(L)for(let i=0;i<e.childCount;i++){const e=r.getChildIndex(n,i),s=r.getNode(e);if(null!=s){!r.isGeometryVisible(e)||this._lodGlobalHandling(s,o,d||x,l)||(y=!1)}else r.isNodeVisible(e)&&(y=!1)}const m=c&&!u&&(y||t.length<o);m&&t.push(n),!l||m||!c||d||y||a.fadeNode(n,s.FadeIn,!1);const N=e.resources.isEmpty;return y||x&&!m||N}_removeChildrenRecursive(e){this._index.traverseDescendants(e,(e=>((this._layerView.isNodeLoaded(e.index)||this._layerView.isNodeReloading(e.index))&&t.push(e.index),e.childrenLoaded>0)))}hasNoVisibleChildren(e){let i=!0;return this._index.traverseDescendants(e,(e=>!(!i||!this._index.isNodeVisible(e.index))&&(this._layerView.isNodeLoaded(e.index)?(i=!1,!1):e.childrenLoaded>0))),i}_childrenRequireLoading(e){let i=!1,s=!0;return this._index.traverseDescendants(e,(e=>{if(!s||!this._index.isNodeVisible(e.index))return!1;const o=this._index.nodeTraversalState(e);return this._isChosenMaxLOD(o)&&this._index.isGeometryVisible(e.index)&&(i=!0),this._layerView.isNodeLoaded(e.index)?(s=!1,!1):e.childrenLoaded>0})),s&&i}_isChosenMaxLOD(e){return e.isChosen&&(!e.nodeHasLOD||e.lodLevel===this._maxLodLevel)}}const t=new e({deallocator:null});export{o as default};