/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../core/Error.js";import{EventedMixin as r}from"../../core/Evented.js";import{when as n}from"../../core/reactiveUtils.js";import{property as i}from"../../core/accessorSupport/decorators/property.js";import{subclass as a}from"../../core/accessorSupport/decorators/subclass.js";import{create as s,equals as o,intersection as l}from"../../geometry/support/aaBoundingRect.js";import u from"../GroundView.js";import{ElevationRange as d}from"./support/ElevationRange.js";import{toBoundingRect as p}from"./support/extentUtils.js";import{webMercatorWorldExtent as g,geographicWorldExtent as h}from"./terrain/TerrainConst.js";import{isIntegratedMeshLayerView as c}from"../support/layerViewUtils.js";let v=class extends(r(u)){constructor(){super(...arguments),this._integratedMeshElevationUpdateHandles=new Map}initialize(){super.initialize(),this.addHandles(n(()=>this._terrainSurface,e=>e.on("elevation-change",e=>this._elevationChange(e))));const e=this._integratedMeshElevationUpdateHandles;this.addHandles(this.view.allLayerViews.on("change",t=>{t.added.forEach(t=>{c(t)&&e.set(t,t.elevationProvider.on("elevation-change",e=>this._elevationChange(e)))}),t.removed.forEach(t=>{c(t)&&(e.get(t)?.remove(),e.delete(t))})}))}destroy(){this._integratedMeshElevationUpdateHandles.forEach(e=>e.remove()),this._integratedMeshElevationUpdateHandles.clear()}_elevationChange(e){this.emit("elevation-change",e)}get _integratedMeshGroundLayerView(){const e=this.ground?.integratedMeshGround;if(e)return this.view.basemapView?.groundLayerViews.find(t=>t.layer===e)}get _terrainSurface(){return this.view.basemapTerrain}get _usingTerrain(){return this._terrainSurface?.enabled??!1}get _usingIntegratedMesh(){return this._integratedMeshGroundLayerView?.visible??!1}get spatialReference(){return this._terrainSurface?.spatialReference}get userClippingExtent(){const{spatialReference:e}=this,{clippingArea:t}=this.view;if(null==t||null==e)return null;const r=s(),n=p(t,r,e)?r:null,i=this._get("userClippingExtent");return o(n,i)?i:n}intersect(e,t,r,n){this._usingTerrain&&this._terrainSurface?.intersect(e,t,r,n);for(const i of this._integratedMeshElevationUpdateHandles.keys())i.intersect(e,t,r,n)}get updating(){return!this.suspended&&((this._source?.updating??!1)||this.layerViews.some(({updating:e})=>e))}getElevation(e,t,r,n){return this._elevationProvider?.getElevation(e,t,r,n)}getElevations(e,t,r){const{_elevationProvider:n}=this;if(n?.getElevations)return n.getElevations(e,t,r);for(let i=0;i<t;++i)r(i,null)}getSphereElevationRange(e,t,r){return this._elevationProvider?.getSphereElevationRange?.(e,t)}getRootElevationRange(){return this._elevationProvider?.getRootElevationRange?.()}get _elevationProvider(){return this._usingIntegratedMesh?this._integratedMeshGroundLayerView?.elevationProvider:this._terrainSurface}get elevationQueryCache(){return this._usingTerrain?this._terrainSurface?.elevationQueryCache:null}get groundExtent(){const{fullGroundExtent:e}=this;return e?this.userClippingExtent?l(e,this.userClippingExtent,s()):this.fullGroundExtent:null}get fullGroundExtent(){if(this._usingTerrain)return this._terrainSurface.fullGroundExtent;if(this._usingIntegratedMesh){const e=this.view.spatialReference;if(e.isWebMercator||e.isWGS84)return f(e);throw new t("GroundView:unsupportedSpatialReference","View spatial reference incompatible with groundLayer")}return null}get visibleElevationRange(){return this._source?.visibleElevationRange??y}get baseOpacity(){return this.ground?.opacity??1}get wireframe(){return!!this._usingTerrain&&(this._terrainSurface?.wireframe??!1)}get suspended(){return this._source?.suspended??!1}get ready(){return this._source?.ready??!1}updateOverlayParameters(){this._terrainSurface?.updateOverlayParameters()}get _source(){return this._usingTerrain?this._terrainSurface:this._usingIntegratedMesh?this._integratedMeshGroundLayerView:null}requestRender(e){this.view.stage.renderView?.requestRender(e)}};e([i({readOnly:!0})],v.prototype,"_integratedMeshGroundLayerView",null),e([i({readOnly:!0})],v.prototype,"_terrainSurface",null),e([i({readOnly:!0})],v.prototype,"_usingTerrain",null),e([i({readOnly:!0})],v.prototype,"_usingIntegratedMesh",null),e([i({readOnly:!0})],v.prototype,"spatialReference",null),e([i({readOnly:!0})],v.prototype,"userClippingExtent",null),e([i({type:Boolean,readOnly:!0})],v.prototype,"updating",null),e([i({readOnly:!0})],v.prototype,"elevationQueryCache",null),e([i({readOnly:!0})],v.prototype,"groundExtent",null),e([i({readOnly:!0})],v.prototype,"fullGroundExtent",null),e([i({readOnly:!0})],v.prototype,"visibleElevationRange",null),e([i({readOnly:!0})],v.prototype,"baseOpacity",null),e([i({readOnly:!0})],v.prototype,"wireframe",null),e([i({readOnly:!0})],v.prototype,"suspended",null),e([i({readOnly:!0})],v.prototype,"ready",null),v=e([a("esri.views.3d.GroundView3D")],v);const y=new d(0,0);function f(e){return e.isWebMercator?g:h}export{v as GroundView3D};
