/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.24/esri/copyright.txt for details. */ import{_ as e}from"../chunks/tslib.es6.js";import i from"../core/Collection.js";import r from"../core/Error.js";import t from"../core/Logger.js";import{isSome as o,isNone as s}from"../core/maybe.js";import{MultiOriginJSONMixin as n}from"../core/MultiOriginJSONSupport.js";import{throwIfAbortError as l}from"../core/promiseUtils.js";import{property as a}from"../core/accessorSupport/decorators/property.js";import"../core/arrayUtils.js";import"../core/has.js";import{Integer as p}from"../core/accessorSupport/ensureType.js";import{reader as m}from"../core/accessorSupport/decorators/reader.js";import{subclass as c}from"../core/accessorSupport/decorators/subclass.js";import{n as y}from"../chunks/vec3.js";import{f as u}from"../chunks/vec3f64.js";import d from"./Layer.js";import{APIKeyMixin as v}from"./mixins/APIKeyMixin.js";import{ArcGISService as h}from"./mixins/ArcGISService.js";import{OperationalLayer as b}from"./mixins/OperationalLayer.js";import{PortalLayer as f}from"./mixins/PortalLayer.js";import{ScaleRangeLayer as S}from"./mixins/ScaleRangeLayer.js";import{SceneService as g}from"./mixins/SceneService.js";import{sanitizeUrl as V}from"./support/arcgisLayerUrl.js";import{popupEnabled as j,legendEnabled as w,url as x}from"./support/commonProperties.js";import I from"./support/VoxelDynamicSection.js";import D from"./support/VoxelSection.js";import N from"./support/VoxelSimpleShading.js";import T from"./support/VoxelSlice.js";import L from"./support/VoxelVariable.js";import O from"./support/VoxelVariableStyle.js";import M from"./support/VoxelVolume.js";import P from"./support/VoxelVolumeIndex.js";import E from"./support/VoxelVolumeStyle.js";const A=t.getLogger(" esri.layers.VoxelLayer");let J=class extends(g(h(b(f(S(n(v(d)))))))){constructor(e){super(e),this.serviceRoot="",this.popupEnabled=!0,this.operationalLayerType="Voxel",this.legendEnabled=!0,this.title=null,this.sections=new i,this.currentVariableId=0,this.volumeStyles=null,this.renderMode="volume",this.variableStyles=null,this.enableSlices=!0,this.enableSections=!0,this.enableDynamicSections=!0,this.enableIsosurfaces=!0,this.shading=new N,this.opacity=1,this.variables=new i,this.volumes=new i,this.index=null,this.minScale=0,this.maxScale=0,this.type="voxel",this.version={major:Number.NaN,minor:Number.NaN,versionString:""},this.volumeStyles=new i,this.variableStyles=new i}set url(e){this._set("url",V(e,A))}load(e){const i=o(e)?e.signal:null,r=this.loadFromPortal({supportedTypes:["Scene Service"]},e).catch(l).then((()=>this._fetchService(i))).then((()=>this.serviceRoot=this.url));return this.addResolvingPromise(r),Promise.resolve(this)}readVersion(e,i){return super.parseVersionString(e)}validateLayer(e){if(e.layerType&&e.layerType!==this.operationalLayerType)throw new r("voxel-layer:layer-type-not-supported","VoxelLayer does not support this layer type",{layerType:e.layerType});if(isNaN(this.version.major)||isNaN(this.version.minor)||this.version.major<3)throw new r("layer:service-version-not-supported","Service version is not supported.",{serviceVersion:this.version.versionString,supportedVersions:"3.x"});if(this.version.major>3)throw new r("layer:service-version-too-new","Service version is too new.",{serviceVersion:this.version.versionString,supportedVersions:"3.x"})}getConfiguration(){const e={layerType:this.operationalLayerType,version:this.version.versionString,name:this.title,spatialReference:this.spatialReference,fullExtent:this.fullExtent,volumes:this.volumes.toJSON(),variables:this.variables.toJSON(),index:this.index.toJSON(),sections:this.sections.toJSON(),style:{volumeStyles:this.volumeStyles.toJSON(),currentVariableId:this.currentVariableId,renderMode:this.renderMode,variableStyles:this.variableStyles.toJSON(),enableSections:this.enableSections,enableDynamicSections:this.enableDynamicSections,enableIsosurfaces:this.enableIsosurfaces,enableSlices:this.enableSlices,shading:this.shading}};return e.index&&this.index.isValid()?JSON.stringify(e):""}getVariableStyle(e){let i=-1;i=o(e)?e:this.currentVariableId;if(!this.variableStyles||-1===i)return null;const r=this.variableStyles.findIndex((e=>e.variableId===i));return r<0?null:this.variableStyles.getItemAt(r)}getVariable(e){let i=-1;if(i=o(e)?e:this.currentVariableId,!this.variables||-1===i)return null;const r=this.variables.findIndex((e=>e.id===i));return r<0?null:this.variables.getItemAt(r)}getSections(){const e=[];for(const i of this.sections)e.push(new D({enabled:i.enabled,href:i.href,id:i.id,label:i.label,normal:i.normal,point:i.point,sizeInPixel:i.sizeInPixel,slices:i.slices,timeId:i.timeId,variableId:i.variableId}));return e}getVolume(e){const i=this.getVariable(e);return o(i)?this.volumes.find((({id:e})=>e===i.volumeId)):null}getVolumeStyle(e){const i=this.getVariable(e);return o(i)?this.volumeStyles.find((({volumeId:e})=>e===i.volumeId)):null}getSlices(){const e=[],i=this.getVolume(null);if(s(i)||!i.isVolumeValid())return e;const r=this.getVolumeStyle(null);if(s(r))return e;for(const t of r.slices)this._isPlaneValid(t,[0,1,i.getZDimension()],i.dimensions)?e.push(new T({enabled:t.enabled,label:t.label,point:t.point,normal:t.normal})):e.push(new T({enabled:!1,label:"invalid",point:t.point,normal:t.normal}));return e}getDynamicSections(){const e=[],i=this.getVolume(null);if(s(i)||!i.isVolumeValid())return e;const r=this.getVolumeStyle(null);if(s(r))return e;for(const t of r.dynamicSections)this._isPlaneValid(t,[0,1,i.getZDimension()],i.dimensions)?e.push(new I({enabled:t.enabled,label:t.label,point:t.point,normal:t.normal})):e.push(new I({enabled:!1,label:"invalid",point:t.point,normal:t.normal}));return e}getVerticalExaggeration(){const e=1,i=this.getVolumeStyle(null);return s(i)?e:i.verticalExaggeration}getVerticalOffset(){const e=1,i=this.getVolumeStyle(null);return s(i)?e:i.verticalOffset}_isPlaneValid(e,i,r){if(!e.point)return!1;if(!Array.isArray(e.point)||3!==e.point.length)return!1;if(!e.normal)return!1;if(!Array.isArray(e.normal)||3!==e.normal.length)return!1;for(let s=0;s<3;++s){const t=e.point[s];if(t<0||t>=r[i[s]].size)return!1}const t=u(e.normal[0],e.normal[1],e.normal[2]);y(t,t);const o=1e-6;return!(Math.abs(t[0])+Math.abs(t[1])+Math.abs(t[2])