@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 2.06 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{watch as e,initial as s}from"../../../../core/reactiveUtils.js";import{Object3D as r}from"../../webgl-engine/lib/Object3D.js";import{WebGLLayer as t}from"../../webgl-engine/lib/WebGLLayer.js";class c{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 c=this._resourceFactory,i=c.view,o=i.stage;if(!o)return;const a=new t(o,{pickable:!1,updatePolicy:1}),h=new r({castShadow:!1}),u=c.createResources(h,a);a.add(h);const l=c.cameraChanged,_=l?e(()=>i.state.camera,e=>l(e),s):null;this._resources={layer:a,object:h,external:u,cameraHandle:_},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{c as VisualElementResources};