@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 6.49 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import r from"../../../core/Accessor.js";import i from"../../../core/Collection.js";import t from"../../../core/Error.js";import{handlesGroup as s}from"../../../core/handleUtils.js";import o from"../../../core/Logger.js";import{getOrCreateMapValue as n}from"../../../core/MapUtils.js";import{abortMaybe as l}from"../../../core/maybe.js";import{isAbortError as a,allSettledValues as u,throwIfAborted as p,createResolver as h}from"../../../core/promiseUtils.js";import{watch as c,syncAndInitial as y}from"../../../core/reactiveUtils.js";import{property as g,subclass as d}from"../../../core/accessorSupport/decorators.js";import{runUntracked as f}from"../../../core/accessorSupport/tracking.js";import{isBuildingGraphicOrigin as m}from"../../../graphic/isBuildingGraphicOrigin.js";import"../../../layers/buildingSublayers/BuildingGroupSublayer.js";import{isGraphic as w}from"../../../support/graphicInstanceUtils.js";import b from"./BuildingComponentSublayerView3D.js";import{BuildingSublayerView3DMixin as V}from"./BuildingSublayerView3D.js";import{LayerView3D as j}from"./LayerView3D.js";import{parseFilterMode as S}from"./i3s/BuildingFilterUtil.js";import{checkSpatialReference as _}from"./i3s/I3SUtil.js";import{normalizeHighlightTarget as v,emptyHighlightHandle as C}from"./support/highlightUtils.js";import{LayerViewPerformanceInfo as B}from"./support/LayerViewPerformanceInfo.js";import{updatingProgress as M}from"../support/updatingProperties.js";import E from"../../layers/BuildingSceneLayerView.js";import{isInEffectiveScaleRange as F}from"../../support/layerViewUtils.js";const I=V(r);let P=class extends(j(E)){constructor(e){super(e),this.type="building-scene-3d",this.sublayerViews=new i,this._rejectedSublayerViews=new Map,this._abortController=new AbortController,this._loadingComponents=0,this._pendingWhenSublayerViews=new Map,this.ignoresMemoryFactor=!1}get filterExpression(){const e=this.layer.activeFilterId,r=null!=e?this.layer.filters.find(r=>r.id===e):null,i=null!=r?r.filterBlocks?.find(e=>"solid"===e.filterMode.type):null;return i?i.filterExpression:null}get filterExpressions(){const e=this.layer.activeFilterId,r=null!=e?this.layer.filters.find(r=>r.id===e):null;return r?.filterBlocks?r.filterBlocks.toArray().map(e=>[e.filterExpression??"",S(e)]):[]}get updatingProgressValue(){return f(()=>{const e=this.sublayerViews,r=this._loadingComponents+(e?e.length:0);return e.reduce((e,r)=>e+r.updatingProgress,0)/r})}get visibleAtCurrentScale(){return F(this.layer.effectiveScaleRange,this.view.scale)}isUpdating(){return this._loadingComponents>0||this.sublayerViews&&this.sublayerViews.some(e=>e.updating)}initialize(){_(this.layer.spatialReference,this.view.spatialReference,this.view.viewingMode),this._initializeSublayerViews(this.layer.sublayers,this)}destroy(){this.sublayerViews&&(this.sublayerViews.forEach(e=>e.destroy()),this.sublayerViews=null),this._rejectedSublayerViews=null,this._abortController=l(this._abortController)}_initializeSublayerViews(e,r){const i=this,s=this.view;e.forEach(e=>{if(!e.isEmpty)if("building-group"===e.type){const i=new I({sublayer:e,view:s,parent:r});this._initializeSublayerViews(e.sublayers,i)}else"mesh"===e.geometryType?(this._loadingComponents++,e.load({signal:this._abortController.signal}).then(()=>{const t=new b({sublayer:e,layerView:i,view:s,parent:r});this.sublayerViews.push(t);const o=this._pendingWhenSublayerViews.get(e);if(o){for(const e of o)e.resolve(t);this._pendingWhenSublayerViews.delete(e)}this.addHandles([c(()=>t.updating,()=>this.notifyChange("updating"),y),c(()=>t.updatingProgress,()=>this.notifyChange("updatingProgressValue"),y)])}).catch(r=>{a(r)||o.getLogger(this).error(`Error while creating view for sublayer ${e.id}\nLayer: ${this.layer.url}\n`,r),this._rejectWhenSublayerView(e,r)}).then(()=>{this._loadingComponents--,this.notifyChange("updating"),this.notifyChange("updatingProgressValue")})):this._rejectWhenSublayerView(e,new t("view:no-layerview-for-sublayer",`No layerview created for sublayer ${e.id}`))})}getGraphicFromIntersectorTarget(e,r){for(const i of this.sublayerViews.items)if(i.sublayer.id===e.sublayerId)return i.getGraphicFromIntersectorTarget(e,r);return null}async fetchPopupFeaturesFromGraphics(e,r){if(0===e.length)return[];const i=L(e,e=>m(e.origin)?e.origin.sublayer:e.sourceLayer),t=[];for(const[o,n]of i){const e=this._findComponent(o);null!=e&&t.push(e.fetchPopupFeaturesFromGraphics(n,r))}const s=await u(t);return p(r),s.flat()}whenGraphicBounds(e){const r=this._findComponent(m(e.origin)?e.origin.sublayer:e.sourceLayer);return null==r?Promise.reject():r.whenGraphicBounds(e)}getAABBFromIntersectorTarget(e){for(const r of this.sublayerViews.items)if(r.sublayer.id===e.sublayerId)return r.getAABBFromIntersectorTarget(e);return null}async whenSublayerView(e){const r=this._findComponent(e);if(null!=r)return r;const i=this._rejectedSublayerViews.get(e);if(null!=i)throw i;const t=this._pendingWhenSublayerViews.get(e),s=h();return t?t.push(s):this._pendingWhenSublayerViews.set(e,[s]),s.promise}_rejectWhenSublayerView(e,r){this._rejectedSublayerViews.set(e,r);const i=this._pendingWhenSublayerViews.get(e);if(i){for(const e of i)e.reject(r);this._pendingWhenSublayerViews.delete(e)}}_findComponent(e){return this.sublayerViews.find(r=>e===r.sublayer)}highlight(e,r){const i=v(e);if(0===i.length)return C;if(w(i[0])){const e=i,t=new Map;for(const r of e)n(t,m(r.origin)?r.origin.sublayer:r.sourceLayer,()=>[]).push(r);const o=[];return this.sublayerViews.forEach(e=>{const i=t.get(e.sublayer);i&&o.push(e.highlight(i,r))}),s(o)}return C}get usedMemory(){return this.sublayerViews.reduce((e,r)=>e+r.usedMemory,0)}get unloadedMemory(){return this.sublayerViews.reduce((e,r)=>e+r.unloadedMemory,0)}get performanceInfo(){return new B(this.usedMemory)}};function L(e,r){const i=new Map,t=e.length;for(let s=0;s<t;s++){const t=e[s],o=r(t,s,e),n=i.get(o);n?n.push(t):i.set(o,[t])}return i}e([g()],P.prototype,"sublayerViews",void 0),e([g()],P.prototype,"_rejectedSublayerViews",void 0),e([g({readOnly:!0})],P.prototype,"filterExpression",null),e([g({readOnly:!0})],P.prototype,"filterExpressions",null),e([g(M)],P.prototype,"updatingProgress",void 0),e([g({readOnly:!0})],P.prototype,"updatingProgressValue",null),e([g({readOnly:!0})],P.prototype,"visibleAtCurrentScale",null),P=e([d("esri.views.3d.layers.BuildingSceneLayerView3D")],P);const U=P;export{U as default};