@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 4.53 kB
JavaScript
import{forEach as e}from"../../../../core/asyncUtils.js";import{isSome as t,get as s,isNone as r}from"../../../../core/maybe.js";import{onAbortOrThrow as o,throwIfAborted as a}from"../../../../core/promiseUtils.js";import i from"./Graphics3DGraphic.js";import{Graphics3DObject3DGraphicLayer as n}from"./Graphics3DObject3DGraphicLayer.js";import{make as y}from"./Graphics3DSymbolLayerFactory.js";import{ApplyRendererDiffResult as l}from"./interfaces.js";import{Loadable as h,LoadStatus as c}from"./Loadable.js";import{totalSymbolComplexities as m}from"./symbolComplexity.js";class p extends h{set symbol(e){this._symbol=e,e.symbolLayers.forEach(((s,r)=>{const o=this.symbolLayers[r];t(o)&&(o.symbol=e,o.symbolLayer=s)}))}get symbol(){return this._symbol}constructor(e,t,s){super(t.schedule),this._symbol=e,this._context=t,this._backgroundLayers=s,this._destroyed=!1,this.symbolLayers=new Array,this.referenced=0,this._extentPadding=0}async doLoad(s){let r=this._symbol.symbolLayers;this._extentPadding=0,this._backgroundLayers&&(r=this._backgroundLayers.concat(r));const i=r.length;for(;this.symbolLayers.length<r.length;)this.symbolLayers.push(null);this.symbolLayers.length=r.length;const n=[];for(let e=0;e<i;e++){const t=r.getItemAt(e);if(!1===t.enabled)continue;d.renderPriority=1-(1+e)/i,d.renderPriorityStep=1/i,d.ignoreDrivers=t._ignoreDrivers;const a=y(this.symbol,t,this._context,d),l=o(s,(()=>{this.symbolLayers[e]=null,a.destroy()}));l&&n.push(l),this.symbolLayers[e]=a}if(await e(this.symbolLayers,(async(e,s)=>{if(t(e))try{await e.load(),this._extentPadding+=Math.max(this._extentPadding,e.extentPadding)}catch{this.symbolLayers[s]=null}})),n.forEach((e=>e.remove())),a(s),this.symbolLayers.length&&!this.symbolLayers.some((e=>!!e)))throw new Error}getSymbolLayerSize(e){const s=this.symbolLayers[e];return t(s)?s.getCachedSize():null}get extentPadding(){return this._extentPadding}get symbologySnappingSupported(){return this.symbolLayers.some((e=>t(e)&&e.queryForSnapping))}createGraphics3DGraphic(e,s){const r=e.graphic,o=new Array(this.symbolLayers.length);for(let i=0;i<this.symbolLayers.length;i++){const s=this.symbolLayers[i];o[i]=t(s)?s.createGraphics3DGraphic(e):null}const a=this._context.arcade||this._context.featureExpressionInfoContext&&this._context.featureExpressionInfoContext.arcade&&this._context.featureExpressionInfoContext.arcade.modules||null;return new i(r,s||this,o,e.layer,a)}get complexity(){return m(this.symbolLayers.map((e=>s(e,"complexity"))))}globalPropertyChanged(e,s){const r=this.symbolLayers.length;for(let o=0;o<r;o++){const r=this.symbolLayers[o],a=e=>{const t=e.layers[o];return t instanceof n?t:null};if(t(r)&&!r.globalPropertyChanged(e,s,a))return!1}return!0}applyRendererDiff(e,s){return this.loadStatus!==c.LOADED?l.Recreate_Symbol:this.symbolLayers.reduce(((r,o)=>r!==l.Recreate_Symbol&&t(o)?Math.min(r,o.applyRendererDiff(e,s)):r),l.Fast_Update)}prepareSymbolPatch(e){if(this.loadStatus===c.FAILED)return;if("partial"!==e.diff.type)return;const s=e.diff.diff;if(!s.symbolLayers||"partial"!==s.symbolLayers.type)return;const o=s.symbolLayers.diff;this.symbolLayers.forEach(((s,a)=>{if(r(s))return;const i=o[a];if(i){const r={diff:i,graphics3DGraphicPatches:[],symbolLayerStatePatches:[]};s.prepareSymbolLayerPatch(r),e.symbolStatePatches.push(...r.symbolLayerStatePatches),r.graphics3DGraphicPatches.length&&e.graphics3DGraphicPatches.push(((e,s)=>{const o=e.layers[a];t(o)&&r.graphics3DGraphicPatches.forEach((e=>e(o,s)))}))}}))}updateGeometry(e,t){for(let s=0;s<this.symbolLayers.length;s++){const o=this.symbolLayers[s];if(r(o))continue;const a=e.layers[s];if(r(a)||!o.updateGeometry(a,t))return!1}return!0}onRemoveGraphic(e){for(let s=0;s<this.symbolLayers.length;s++){const o=this.symbolLayers[s];if(r(o))continue;const a=e.layers[s];t(a)&&o.onRemoveGraphic(a)}}getFastUpdateStatus(){let e=0,t=0,s=0;return this.symbolLayers.forEach((o=>{r(o)||(o.loadStatus===c.LOADING?e++:o.isFastUpdatesEnabled()?s++:t++)})),{loading:e,slow:t,fast:s}}async queryForSnapping(e,s,r,o){const i=this.symbolLayers.filter(t).filter((e=>t(e.queryForSnapping))).map((t=>t.queryForSnapping(e,s,r,o))),n=await Promise.all(i);return a(o),n.flat()}destroy(){if(this.destroyed)console.error("Graphics3DSymbol.destroy called when already destroyed!");else{super.destroy();for(const e of this.symbolLayers)t(e)&&e.destroy();this.symbolLayers.length=0,this._destroyed=!0}}get destroyed(){return this._destroyed}}const d={renderPriority:0,renderPriorityStep:1,ignoreDrivers:!1};export{p as default};