@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 5.75 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import{_ as e}from"../../../../chunks/tslib.es6.js";import i from"../../../../analysis/SlicePlane.js";import a from"../../../../core/Accessor.js";import t from"../../../../core/Logger.js";import{watch as l}from"../../../../core/reactiveUtils.js";import{property as s}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/has.js";import"../../../../core/RandomLCG.js";import{subclass as n}from"../../../../core/accessorSupport/decorators/subclass.js";import{d as r}from"../../../../chunks/boundedPlane.js";import o from"../../../../layers/Layer.js";import c from"../../../../layers/buildingSublayers/BuildingComponentSublayer.js";import{isIBuildingSceneLayerView3D as h,projectAndElevationAlignShape as u,projectedShapeToPlane as d,planeToShape as p}from"./sliceToolUtils.js";import{logFailedGeometryProjectionError as y}from"../support/projectionUtils.js";import{isTerrainSurfaceLayer as w}from"../../terrain/isTerrainSurfaceLayer.js";let v=class extends a{constructor(e){super(e),this._internalChange=!1,this._currentSlicePlane=null}initialize(){this.addHandles(this.analysis.excludedLayers.on("before-add",(e=>{const i=e.item;null!=i&&(i instanceof o||i instanceof c)?i instanceof o&&w(i)?(t.getLogger(this).error("excludedLayers",`Layer '${i.title}, id:${i.id}' of type '${i.type}' can not be individually excluded from slicing. Use 'excludeGroundSurface' instead.`),e.preventDefault()):this.analysis.excludedLayers.includes(i)&&e.preventDefault():(t.getLogger(this).error("excludedLayers","Invalid layer type, layer must derive from Layer or BuildingComponentSublayer"),e.preventDefault())}))),V(this.view,this),this.addHandles([l((()=>this.analysisViewData.plane),(()=>{this._internalChange||this._updateSlicePlaneFromBoundedPlane(),this._updateLayerViews()}),{sync:!0}),l((()=>this.analysis.excludeGroundSurface),(()=>this._updateLayerViews()),{sync:!0}),this.analysis.excludedLayers.on("change",(()=>this._updateLayerViews())),l((()=>[this.analysisViewData.active,this.analysisViewData.visible]),(()=>{this._updateActiveController(),this._updateViewSlicePlane()}),{sync:!0}),l((()=>this._allLayerAndSubLayerViews),(()=>this._updateLayerViews()))]),this.addHandles([l((()=>this.analysis.shape),(()=>{this._internalChange||(this._updateBoundedPlaneFromSlicePlane(),this._updateViewSlicePlane())}),{sync:!0})],"analysis"),this._updateActiveController(),this._updateBoundedPlaneFromSlicePlane(),this._updateViewSlicePlane()}destroy(){this.analysisViewData.active&&(this.analysisViewData.active=!1,this.view.slicePlane=null,this._updateActiveController(),this._updateViewSlicePlane()),L(this.view,this),this.set("view",null)}get _allLayerAndSubLayerViews(){const e=this.view.allLayerViews.items;return e.concat(e.filter(h).flatMap((({sublayerViews:e})=>e.items)))}_updateBoundedPlaneFromSlicePlane(){const e=this.analysis.shape,i=this._currentSlicePlane;if(null==i&&null==e||null!=i&&null!=e&&e.equals(i))return;let a=null,l=null;if(null!=e?.position){const i=e.position.spatialReference,s=u(e,this.view);null==s&&y(this.analysis,i,t.getLogger(this)),a=d(s,this.view,{tiltEnabled:this.analysis.tiltEnabled},r()),null!=a&&(l={heading:e.heading,tilt:e.tilt,position:e.position,width:e.width,height:e.height})}this._currentSlicePlane=l,this._internalChange=!0,this.analysisViewData.plane=a,this._internalChange=!1}_updateSlicePlaneFromBoundedPlane(){const e=this.analysisViewData.plane,a=p(e,this.view,this.view.spatialReference,new i);let t=null;null!=a&&(t={heading:a.heading,tilt:a.tilt,position:a.position,width:a.width,height:a.height}),this._currentSlicePlane=t,this._internalChange=!0,this.analysis.shape=a,this._internalChange=!1,this._updateViewSlicePlane()}_updateActiveController(){if(m)return;const e=_(this.view);if(!e)return;if(this.analysisViewData.active)null!=e.activeController&&e.activeController!==this?(m=!0,e.activeController.analysisViewData.active=!1,m=!1):null!=e.activeController&&e.activeController,this._updateLayerViews(),e.activeController=this;else{if(null!=e.activeController&&e.activeController!==this)return;null!=e.activeController&&e.activeController===this&&(e.activeController=null,this._updateLayerViews())}}_updateViewSlicePlane(){g(this.view)}_updateLayerViews(){const e=null!=this.analysisViewData.plane&&this.analysisViewData.visible&&this.analysisViewData.active,i=[],a=e=>{"layers"in e?e.layers.forEach(a):i.push(e)};this.analysis.excludedLayers.forEach(a),this.view.allLayerViews.forEach((a=>{a.destroyed||("slicePlaneEnabled"in a&&(a.slicePlaneEnabled=e&&!i.includes(a.layer)),"sublayerViews"in a&&a.sublayerViews.forEach((a=>{a.slicePlaneEnabled=e&&!i.includes(a.sublayer)})))})),null!=this.view.basemapTerrain&&(this.view.basemapTerrain.slicePlaneEnabled=e&&!this.analysis.excludeGroundSurface)}};e([s()],v.prototype,"view",void 0),e([s()],v.prototype,"analysis",void 0),e([s()],v.prototype,"analysisViewData",void 0),e([s()],v.prototype,"_allLayerAndSubLayerViews",null),v=e([n("esri.views.3d.analysis.Slice.SliceController")],v);const f=new Map;let m=!1;function g(e){const i=_(e),a=i?.activeController;null!=a?.analysisViewData.plane&&a.analysisViewData.visible?e.slicePlane=a.analysisViewData.plane:e.slicePlane=null}function V(e,i){f.has(e)||f.set(e,{all:[],activeController:null}),f.get(e)?.all.push(i)}function _(e){return f.get(e)}function L(e,i){if(!f.has(e))throw new Error("view expected in global slice register");const a=f.get(e),t=a?.all.lastIndexOf(i)??-1;if(!a||-1===t)throw new Error("controller expected in global slice register");a.all.splice(t,1),0===a.all.length&&f.delete(e)}export{v as SliceController};