@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 2.85 kB
JavaScript
import{isNone as e,isSome as i}from"../../../../core/maybe.js";import o from"../../../../core/PooledArray.js";import{NodeState as s}from"./I3SNode.js";import{FadeDirection as d}from"../support/I3SLayerView.js";class t{constructor(e){this._layerView=e,this._lodGlobalDirty=!1}startNodeLoading(e,i,o,s){this._maxLodLevel=s.maxLodLevel,this._index=o,this._isNodeInScaleBounds=e,this._removeNodes=i}shouldLoadNode(i){if(e(i))return!1;const o=this._index.nodeTraversalState(i);return!!this._isChosenMaxLOD(o)||!!o.isChosen&&this._childrenRequireLoading(i)}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,o=Math.max(0,Math.floor(10*(i-1)));r.clear(),this._lodGlobalHandling(this._index.rootNode,o,!1,!!this._layerView.nodeCrossfadingEnabled);const s=r.length;this._removeNodes(r,e);const d=r.length<s;return 0!==r.length&&(this._lodGlobalDirty=!0),r.clear(),d}_lodGlobalHandling(o,t,l,n){if(e(o))return!1;const a=o.index,h=this._index,_=this._layerView,u=h.nodeTraversalState(o),c=this._isChosenMaxLOD(u),x=!o.resources.hasFeatureData;if(c&&x)return o.childrenLoaded>0&&this._removeChildrenRecursive(o),!0;const L=_.isNodeLoaded(a);if(n&&L&&c){const e=!l&&this.hasNoVisibleChildren(o);_.fadeNode(a,d.FadeIn,!e)}const N=L&&(!_.isNodeFullyFadedIn||_.isNodeFullyFadedIn(a));if(L&&(_.updateNodeState(a,c?s.Leaf:s.Hole),c))return N&&this._removeChildrenRecursive(o),N;const m=o.childCount>0;let y=m;if(m)for(let e=0;e<o.childCount;e++){const o=h.getChildIndex(a,e),s=h.getNode(o);if(i(s)){!(!h.isGeometryVisible(o)||this._lodGlobalHandling(s,t,l||N,n))&&this._isNodeInScaleBounds(s)&&(y=!1)}else h.isNodeVisible(o)&&(y=!1)}const b=L&&!c&&(y||r.length<t);b&&r.push(a),!n||b||!L||l||y||_.fadeNode(a,d.FadeIn,!1);const f=!o.resources.hasFeatureData;return y||N&&!b||f}_removeChildrenRecursive(e){this._index.traverseChildren(e,(e=>((this._layerView.isNodeLoaded(e.index)||this._layerView.isNodeReloading(e.index))&&r.push(e.index),e.childrenLoaded>0)))}hasNoVisibleChildren(e){let i=!0;return this._index.traverseChildren(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,o=!0;return this._index.traverseChildren(e,(e=>{if(!o||!this._index.isNodeVisible(e.index))return!1;const s=this._index.nodeTraversalState(e);return this._isChosenMaxLOD(s)&&this._index.isGeometryVisible(e.index)&&(i=!0),this._layerView.isNodeLoaded(e.index)?(o=!1,!1):e.childrenLoaded>0})),o&&i}_isChosenMaxLOD(e){return e.isChosen&&(!e.nodeHasLOD||e.lodLevel===this._maxLodLevel)}}const r=new o({deallocator:null});export{t as default};