UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) 2.23 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{watch as e,initial as s}from"../../../../core/reactiveUtils.js";import{Object3D as r}from"../../webgl-engine/lib/Object3D.js";import{UpdatePolicy as t}from"../../webgl-engine/lib/UpdatePolicy.js";import{WebGLLayer as c}from"../../webgl-engine/lib/WebGLLayer.js";class i{constructor(e){this._resourceFactory=e,this._resources=null,this._visible=!0,this._attached=!1}destroy(){this._destroyResources()}get object(){return null!=this._resources?this._resources.object:null}get resources(){return null!=this._resources?this._resources.external:null}get visible(){return this._visible}set visible(e){e!==this._visible&&(this._visible=e,this._syncVisible())}get attached(){return this._attached}set attached(e){e!==this._attached&&(this._attached=e,this._createOrDestroyResources())}recreate(){this.attached&&this._createResources()}recreateGeometry(){if(!this._resourceFactory.recreateGeometry)return void this.recreate();const e=this._resourceFactory.view.stage;if(null==this._resources||!e)return;const s=this._resources.object;s.removeAllGeometries(),this._resourceFactory.recreateGeometry(this._resources.external,s,this._resources.layer)}forEachMaterial(e){this._resources&&this._resourceFactory.forEachMaterial(this._resources.external,e)}_createOrDestroyResources(){this._attached?this._resources||this._createResources():this._destroyResources()}_createResources(){this._destroyResources();const i=this._resourceFactory,o=i.view,a=o.stage;if(!a)return;const h=new c(a,{pickable:!1,updatePolicy:t.SYNC}),u=new r({castShadow:!1}),l=i.createResources(u,h);h.add(u);const _=i.cameraChanged,n=_?e((()=>o.state.camera),(e=>_(e)),s):null;this._resources={layer:h,object:u,external:l,cameraHandle:n},this._syncVisible()}_destroyResources(){null!=this._resources&&(this._resources.layer.destroy(),this._resources.object.dispose(),this._resources.cameraHandle?.remove(),this._resourceFactory.destroyResources(this._resources.external),this._resources=null)}_syncVisible(){null!=this._resources&&(this._resources.object.visible=this._visible)}}export{i as VisualElementResources};