/* 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"../PopupTemplate.js";import t from"../request.js";import o from"../core/Error.js";import{clone as i}from"../core/lang.js";import s from"../core/Logger.js";import{isSome as n}from"../core/maybe.js";import{MultiOriginJSONMixin as a}from"../core/MultiOriginJSONSupport.js";import{setDeepValue as p}from"../core/object.js";import{throwIfAbortError as l}from"../core/promiseUtils.js";import{join as d}from"../core/urlUtils.js";import{property as u}from"../core/accessorSupport/decorators/property.js";import"../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{writer as f}from"../core/accessorSupport/decorators/writer.js";import y from"./Layer.js";import{APIKeyMixin as h}from"./mixins/APIKeyMixin.js";import{ArcGISService as g}from"./mixins/ArcGISService.js";import{OperationalLayer as v}from"./mixins/OperationalLayer.js";import{PortalLayer as I}from"./mixins/PortalLayer.js";import{ScaleRangeLayer as w}from"./mixins/ScaleRangeLayer.js";import{SceneService as j,SaveOperationType as S}from"./mixins/SceneService.js";import{types as b}from"./pointCloudFilters/typeUtils.js";import{popupEnabled as x,elevationInfo as T,legendEnabled as P}from"./support/commonProperties.js";import F from"./support/Field.js";import{defineFieldProperties as L}from"./support/fieldProperties.js";import E from"../popup/ExpressionInfo.js";import{types as C}from"../renderers/support/pointCloud/typeUtils.js";import{createPopupTemplate as _}from"../support/popupUtils.js";const A=L();let N=class extends(j(g(v(I(w(a(h(y)))))))){constructor(...e){super(...e),this.operationalLayerType="PointCloudLayer",this.popupEnabled=!0,this.popupTemplate=null,this.opacity=1,this.filters=[],this.fields=null,this.fieldsIndex=null,this.outFields=null,this.path=null,this.legendEnabled=!0,this.renderer=null,this.type="point-cloud"}normalizeCtorArgs(e,r){return"string"==typeof e?{url:e,...r}:e}get defaultPopupTemplate(){return this.attributeStorageInfo?this.createPopupTemplate():null}getFieldDomain(e){const r=this.fieldsIndex.get(e);return r&&r.domain?r.domain:null}readServiceFields(e,r,t){return Array.isArray(e)?e.map((e=>{const r=new F;return"FieldTypeInteger"===e.type&&((e=i(e)).type="esriFieldTypeInteger"),r.read(e,t),r})):Array.isArray(r.attributeStorageInfo)?r.attributeStorageInfo.map((e=>new F({name:e.name,type:"ELEVATION"===e.name?"double":"integer"}))):null}set elevationInfo(e){this._set("elevationInfo",e),this._validateElevationInfo()}writeRenderer(e,r,t,o){p("layerDefinition.drawingInfo.renderer",e.write({},o),r)}load(e){const r=n(e)?e.signal:null,t=this.loadFromPortal({supportedTypes:["Scene Service"]},e).catch(l).then((()=>this._fetchService(r)));return this.addResolvingPromise(t),Promise.resolve(this)}createPopupTemplate(e){const r=_(this,e);return r&&(this._formatPopupTemplateReturnsField(r),this._formatPopupTemplateRGBField(r)),r}_formatPopupTemplateReturnsField(e){const r=this.fieldsIndex.get("RETURNS");if(!r)return;const t=e.fieldInfos?.find((e=>e.fieldName===r.name));if(!t)return;const o=new E({name:"pcl-returns-decoded",title:r.alias||r.name,expression:`\n var returnValue = $feature.${r.name};\n return (returnValue % 16) + " / " + Floor(returnValue / 16);\n `});e.expressionInfos=[...e.expressionInfos||[],o],t.fieldName="expression/pcl-returns-decoded"}_formatPopupTemplateRGBField(e){const r=this.fieldsIndex.get("RGB");if(!r)return;const t=e.fieldInfos?.find((e=>e.fieldName===r.name));if(!t)return;const o=new E({name:"pcl-rgb-decoded",title:r.alias||r.name,expression:`\n var rgb = $feature.${r.name};\n var red = Floor(rgb / 65536, 0);\n var green = Floor((rgb - (red * 65536)) / 256,0);\n var blue = rgb - (red * 65536) - (green * 256);\n\n return "rgb(" + red + "," + green + "," + blue + ")";\n `});e.expressionInfos=[...e.expressionInfos||[],o],t.fieldName="expression/pcl-rgb-decoded"}async queryCachedStatistics(e,r){if(await this.load(r),!this.attributeStorageInfo)throw new o("scenelayer:no-cached-statistics","Cached statistics are not available for this layer");const i=this.fieldsIndex.get(e);if(!i)throw new o("pointcloudlayer:field-unexisting",`Field '${e}' does not exist on the layer`);for(const o of this.attributeStorageInfo)if(o.name===i.name){const e=d(this.parsedUrl.path,`./statistics/${o.key}`);return t(e,{query:{f:"json",token:this.apiKey},responseType:"json",signal:r?r.signal:null}).then((e=>e.data))}throw new o("pointcloudlayer:no-cached-statistics","Cached statistics for this attribute are not available")}async saveAs(e,r){return this._debouncedSaveOperations(S.SAVE_AS,{...r,getTypeKeywords:()=>this._getTypeKeywords(),portalItemLayerType:"point-cloud"},e)}async save(){const e={getTypeKeywords:()=>this._getTypeKeywords(),portalItemLayerType:"point-cloud"};return this._debouncedSaveOperations(S.SAVE,e)}validateLayer(e){if(e.layerType&&"PointCloud"!==e.layerType)throw new o("pointcloudlayer:layer-type-not-supported","PointCloudLayer does not support this layer type",{layerType:e.layerType});if(isNaN(this.version.major)||isNaN(this.version.minor))throw new o("layer:service-version-not-supported","Service version is not supported.",{serviceVersion:this.version.versionString,supportedVersions:"1.x-2.x"});if(this.version.major>2)throw new o("layer:service-version-too-new","Service version is too new.",{serviceVersion:this.version.versionString,supportedVersions:"1.x-2.x"})}hasCachedStatistics(e){return null!=this.attributeStorageInfo&&this.attributeStorageInfo.some((r=>r.name===e))}_getTypeKeywords(){return["PointCloud"]}_validateElevationInfo(){const e=this.elevationInfo;e&&("absolute-height"!==e.mode&&s.getLogger(this.declaredClass).warn(".elevationInfo=","Point cloud layers only support absolute-height elevation mode"),e.featureExpressionInfo&&"0"!==e.featureExpressionInfo.expression&&s.getLogger(this.declaredClass).warn(".elevationInfo=","Point cloud layers do not support featureExpressionInfo"))}};e([u({type:["PointCloudLayer"]})],N.prototype,"operationalLayerType",void 0),e([u(x)],N.prototype,"popupEnabled",void 0),e([u({type:r,json:{name:"popupInfo",write:!0}})],N.prototype,"popupTemplate",void 0),e([u({readOnly:!0,json:{read:!1}})],N.prototype,"defaultPopupTemplate",null),e([u({readOnly:!0,json:{write:!1,read:!1,origins:{"web-document":{write:!1,read:!1}}}})],N.prototype,"opacity",void 0),e([u({type:["show","hide"]})],N.prototype,"listMode",void 0),e([u({types:[b],json:{origins:{service:{read:{source:"filters"}}},name:"layerDefinition.filters",write:!0}})],N.prototype,"filters",void 0),e([u({type:[F]})],N.prototype,"fields",void 0),e([u(A.fieldsIndex)],N.prototype,"fieldsIndex",void 0),e([m("service","fields",["fields","attributeStorageInfo"])],N.prototype,"readServiceFields",null),e([u(A.outFields)],N.prototype,"outFields",void 0),e([u({readOnly:!0})],N.prototype,"attributeStorageInfo",void 0),e([u(T)],N.prototype,"elevationInfo",null),e([u({type:String,json:{origins:{"web-scene":{read:!0,write:!0},"portal-item":{read:!0,write:!0}},read:!1}})],N.prototype,"path",void 0),e([u(P)],N.prototype,"legendEnabled",void 0),e([u({types:C,json:{origins:{service:{read:{source:"drawingInfo.renderer"}}},name:"layerDefinition.drawingInfo.renderer",write:{target:{"layerDefinition.drawingInfo.renderer":{types:C},"layerDefinition.drawingInfo.transparency":{type:Number}}}}})],N.prototype,"renderer",void 0),e([f("renderer")],N.prototype,"writeRenderer",null),e([u({json:{read:!1},readOnly:!0})],N.prototype,"type",void 0),N=e([c("esri.layers.PointCloudLayer")],N);const R=N;export{R as default};