/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.25/esri/copyright.txt for details. */ import{_ as e}from"../chunks/tslib.es6.js";import r from"../core/Collection.js";import i from"../core/Error.js";import o from"../core/Logger.js";import{isSome as t}from"../core/maybe.js";import{MultiOriginJSONMixin as s}from"../core/MultiOriginJSONSupport.js";import{throwIfAbortError as n}from"../core/promiseUtils.js";import{property as l}from"../core/accessorSupport/decorators/property.js";import"../core/arrayUtils.js";import{Integer as a}from"../core/accessorSupport/ensureType.js";import{reader as c}from"../core/accessorSupport/decorators/reader.js";import{subclass as u}from"../core/accessorSupport/decorators/subclass.js";import{n as m}from"../chunks/vec3.js";import{f as p}from"../chunks/vec3f64.js";import y from"../geometry/Extent.js";import d from"./Layer.js";import{APIKeyMixin as f}from"./mixins/APIKeyMixin.js";import{ArcGISService as v}from"./mixins/ArcGISService.js";import{OperationalLayer as h}from"./mixins/OperationalLayer.js";import{PortalLayer as b}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 x,legendEnabled as j,url as w}from"./support/commonProperties.js";import I from"./voxel/VoxelSection.js";import D from"./voxel/VoxelSimpleShading.js";import F from"./voxel/VoxelVariable.js";import N from"./voxel/VoxelVariableStyle.js";import T from"./voxel/VoxelVolume.js";import L from"./voxel/VoxelVolumeIndex.js";import A from"./voxel/VoxelVolumeStyle.js";const E="esri.layers.VoxelLayer",R=o.getLogger(E);let M=class extends(g(v(h(b(S(s(f(d)))))))){constructor(e){super(e),this.serviceRoot="",this.popupEnabled=!0,this.operationalLayerType="Voxel",this.legendEnabled=!0,this.title=null,this.sections=null,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 D,this.opacity=1,this.variables=new r,this.volumes=new r,this.index=null,this.minScale=0,this.maxScale=0,this.type="voxel",this.version={major:Number.NaN,minor:Number.NaN,versionString:""},this.fullExtent=null,this.volumeStyles=new(r.ofType(A)),this.variableStyles=new(r.ofType(N)),this.sections=new(r.ofType(I))}set url(e){this._set("url",V(e,R))}load(e){const r=t(e)?e.signal:null,i=this.loadFromPortal({supportedTypes:["Scene Service"]},e).catch(n).then((()=>this._fetchService(r))).then((()=>this.serviceRoot=this.url));return this.addResolvingPromise(i),Promise.resolve(this)}read(e,r){super.read(e,r);for(const i of this.volumes)i.spatialReference=this.spatialReference}readVersion(e,r){return super.parseVersionString(e)}validateLayer(e){if(e.layerType&&e.layerType!==this.operationalLayerType)throw new i("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 i("layer:service-version-not-supported","Service version is not supported.",{serviceVersion:this.version.versionString,supportedVersions:"3.x"});if(this.version.major>3)throw new i("layer:service-version-too-new","Service version is too new.",{serviceVersion:this.version.versionString,supportedVersions:"3.x"})}readFullExtent(e,r,i){if(null!=e&&"object"==typeof e){const o=y.fromJSON(e,i);if(0===o.zmin&&0===o.zmax&&Array.isArray(r.volumes)){const e=T.fromJSON(r.volumes[0]);if(e.isValid&&"xyt"!==e.volumeType){const r=e.dimensions[2];if(r.isRegular){let e=r.regularSpacing.offset,i=r.regularSpacing.offset+r.regularSpacing.scale*(r.size-1);if(e>i){const r=e;e=i,i=r}o.zmin=e,o.zmax=i}}}return o}return null}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.getSections(),style:{volumeStyles:this.getVolumeStyles(),currentVariableId:this.currentVariableId,renderMode:this.renderMode,variableStyles:this.getVariableStyles(),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 r=-1;r=t(e)?e:this.currentVariableId;if(!this.variableStyles||-1===r)return null;const i=this.variableStyles.findIndex((e=>e.variableId===r));return i<0?null:this.variableStyles.getItemAt(i)}getVariable(e){let r=-1;if(r=t(e)?e:this.currentVariableId,!this.variables||-1===r)return null;const i=this.variables.findIndex((e=>e.id===r));return i<0?null:this.variables.getItemAt(i)}getVolume(e){const r=this.getVariable(e);return t(r)?this.volumes.find((({id:e})=>e===r.volumeId)):null}getVolumeStyle(e){const r=this.getVariable(e);return t(r)?this.volumeStyles.find((({volumeId:e})=>e===r.volumeId)):null}getColorForContinuousDataValue(e,r,i){const o=this.getVariable(e);if(!t(o)||"continuous"!==o.renderingFormat.continuity)return null;if(!this.variableStyles)return null;const s=this.variableStyles.findIndex((r=>r.variableId===e));if(s<0)return null;const n=this.variableStyles.getItemAt(s);return n.transferFunction?n.transferFunction.getColorForContinuousDataValue(r,i):null}getSections(){const e=[];for(const r of this.sections)e.push(new I({enabled:r.enabled,href:r.href,id:r.id,label:r.label,normal:r.normal,point:r.point,sizeInPixel:r.sizeInPixel,slices:r.slices,timeId:r.timeId,variableId:r.variableId}));return e}getVariableStyles(){const e=[];for(const r of this.variableStyles){const i=this._getVariable(r);if(t(i)){const o=r.clone();o.isosurfaces.length>4&&(o.isosurfaces=o.isosurfaces.slice(0,3),R.error("A maximum of 4 isosurfaces are supported for Voxel Layers."));for(const e of o.isosurfaces)if(e.colorLocked){const r=this.getColorForContinuousDataValue(o.variableId,e.value,!1);null===r||r.equals(e.color)||(e.color=r)}if("continuous"===i.renderingFormat.continuity)(null===o.transferFunction||o.transferFunction.colorStops.length<2)&&R.error(`VoxelVariableStyle for variable ${i.id} is invalid. At least 2 color stops are required in the transferFunction for continuous Voxel Layer variables.`),null!==o.transferFunction&&(Array.isArray(o.transferFunction.stretchRange)&&2===o.transferFunction.stretchRange.length||(R.error(`VoxelVariableStyle for variable ${i.id} is invalid. The stretchRange of the transferFunction for continuous Voxel Layer variables must be of the form [minimumDataValue, maximumDataValue].`),o.transferFunction.stretchRange=[0,1],o.transferFunction.colorStops.removeAll()));else if("discrete"===i.renderingFormat.continuity)if(0===r.uniqueValues.length)R.error(`VoxelVariableStyle for variable ${i.id} is invalid. Unique values are required for discrete Voxel Layer variables.`);else for(const e of r.uniqueValues)null!==e.label&&void 0!==e.label||null===e.value||void 0===e.value||(e.label=e.value.toString());e.push(o)}else R.error(`VoxelVariable ID=${r.variableId} doesn't exist, VoxelVariableStyle for this VoxelVariable will be ignored.`)}return e}getVolumeStyles(){const e=[];for(const r of this.volumeStyles){const i=this._getVolumeFromVolumeId(r.volumeId);if(t(i)){const o=r.clone();for(const e of o.slices)this._isPlaneValid(e,[0,1,i.zDimension],i.dimensions)||(e.enabled=!1,e.label="invalid");for(const e of o.dynamicSections)this._isPlaneValid(e,[0,1,i.zDimension],i.dimensions)||(e.enabled=!1,e.label="invalid");e.push(o)}else R.error(`VoxelVolume ID=${r.volumeId} doesn't exist, VoxelVolumeStyle for this VoxelVolume will be ignored.`)}return e}_getVariable(e){const r=e.variableId;for(const i of this.variables)if(i.id===r)return i;return null}_getVolumeFromVolumeId(e){for(const r of this.volumes)if(r.id===e)return r;return null}_isPlaneValid(e,r,i){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 o=e.point[s];if(o<0||o>=i[r[s]].size)return!1}const o=p(e.normal[0],e.normal[1],e.normal[2]);m(o,o);const t=1e-6;return!(Math.abs(o[0])+Math.abs(o[1])+Math.abs(o[2])