@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 8.43 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../PopupTemplate.js";import r from"../request.js";import{ClonableMixin as o}from"../core/Clonable.js";import i from"../core/Error.js";import{clone as s}from"../core/lang.js";import n from"../core/Logger.js";import{MultiOriginJSONSupportMixin 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,subclass as m}from"../core/accessorSupport/decorators.js";import c from"../graphic/PointCloudGraphicOrigin.js";import y from"./Layer.js";import{APIKeyMixin as f}from"./mixins/APIKeyMixin.js";import{ArcGISService as h}from"./mixins/ArcGISService.js";import{CustomParametersMixin as g}from"./mixins/CustomParametersMixin.js";import{OperationalLayer as v}from"./mixins/OperationalLayer.js";import{PortalLayer as w}from"./mixins/PortalLayer.js";import{ScaleRangeLayer as j}from"./mixins/ScaleRangeLayer.js";import{SceneService as I,updateExtentFromPageObb as b}from"./mixins/SceneService.js";import{types as P}from"./pointCloudFilters/typeUtils.js";import{popupEnabled as x,elevationInfo as S,legendEnabled as T}from"./support/commonProperties.js";import F from"./support/Field.js";import{defineFieldProperties as _}from"./support/fieldProperties.js";import L from"../popup/ExpressionInfo.js";import{types as C}from"../renderers/support/pointCloud/typeUtils.js";import{logInvalidElevationInfoWarning as R,elevationModeRequiredMessage as E,featureExpressionUnsupportedMessage as O}from"../support/elevationInfoUtils.js";import{createPopupTemplate as N}from"../support/popupUtils.js";import{reader as A}from"../core/accessorSupport/decorators/reader.js";import{writer as U}from"../core/accessorSupport/decorators/writer.js";const K=_();let V=class extends(I(h(v(w(j(a(g(f(o(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",this.graphicOrigin=new c(this),this.rootPagePromise=null}normalizeCtorArgs(e,t){return"string"==typeof e?{url:e,...t}:e}get defaultPopupTemplate(){return this.attributeStorageInfo?this.createPopupTemplate():null}getFieldDomain(e){const t=this.fieldsIndex.get(e);return t?.domain?t.domain:null}readServiceFields(e,t,r){return Array.isArray(e)?e.map(e=>{const t=new F;return"FieldTypeInteger"===e.type&&((e=s(e)).type="esriFieldTypeInteger"),t.read(e,r),t}):Array.isArray(t.attributeStorageInfo)?t.attributeStorageInfo.map(e=>new F({name:e.name,type:"ELEVATION"===e.name?"double":"integer"})):null}set elevationInfo(e){null!=e&&"absolute-height"!==e.mode||this._set("elevationInfo",e),this._validateElevationInfo(e)}writeRenderer(e,t,r,o){p("layerDefinition.drawingInfo.renderer",e.write({},o),t)}load(e){return this.addResolvingPromise(this._load(e)),Promise.resolve(this)}async _load(e){await this.loadFromPortal({supportedTypes:["Scene Service"]},e).catch(l),await this._fetchService(e?.signal),await this._fetchRootPageAndUpdateExtent(e?.signal)}async _fetchRootPageAndUpdateExtent(e){this.rootPagePromise=this._fetchRootPage(e);const{fullExtent:t}=this;if(null!=t&&!t.hasZ){const e=await this.rootPagePromise;b(t,e?.nodes?.[0]?.obb)}}async _fetchRootPage(e){const t=`${this.parsedUrl?.path??""}/nodepages/0`;try{return(await r(t,{query:{f:"json",...this.customParameters,token:this.apiKey},responseType:"json",signal:e})).data}catch(o){throw new i("pointcloudlayer:root-page-missing","Root page missing.",{error:o,url:t})}}createPopupTemplate(e){const t=N(this,e);return t&&(this._formatPopupTemplateReturnsField(t),this._formatPopupTemplateRGBField(t)),t}_formatPopupTemplateReturnsField(e){const t=this.fieldsIndex.get("RETURNS");if(!t)return;const r=e.fieldInfos?.find(e=>e.fieldName===t.name);if(!r)return;const o=new L({name:"pcl-returns-decoded",title:t.alias||t.name,expression:`\n var returnValue = $feature.${t.name};\n return (returnValue % 16) + " / " + Floor(returnValue / 16);\n `});e.expressionInfos=[...e.expressionInfos||[],o],r.fieldName="expression/pcl-returns-decoded"}_formatPopupTemplateRGBField(e){const t=this.fieldsIndex.get("RGB");if(!t)return;const r=e.fieldInfos?.find(e=>e.fieldName===t.name);if(!r)return;const o=new L({name:"pcl-rgb-decoded",title:t.alias||t.name,expression:`\n var rgb = $feature.${t.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],r.fieldName="expression/pcl-rgb-decoded"}async queryCachedStatistics(e,t){if(await this.load(t),!this.attributeStorageInfo)throw new i("scenelayer:no-cached-statistics","Cached statistics are not available for this layer");const o=this.fieldsIndex.get(e);if(!o)throw new i("pointcloudlayer:field-unexisting",`Field '${e}' does not exist on the layer`);for(const i of this.attributeStorageInfo)if(i.name===o.name){const e=d(this.parsedUrl?.path??"",`./statistics/${i.key}`);return r(e,{query:{f:"json",...this.customParameters,token:this.apiKey},responseType:"json",signal:t?t.signal:null}).then(e=>e.data)}throw new i("pointcloudlayer:no-cached-statistics","Cached statistics for this attribute are not available")}async saveAs(e,t){return this._debouncedSaveOperations(1,{...t,getTypeKeywords:()=>this._getTypeKeywords(),portalItemLayerType:"point-cloud"},e)}async save(){const e={getTypeKeywords:()=>this._getTypeKeywords(),portalItemLayerType:"point-cloud"};return this._debouncedSaveOperations(0,e)}validateLayer(e){if(e.layerType&&"PointCloud"!==e.layerType)throw new i("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 i("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 i("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(t=>t.name===e)}_getTypeKeywords(){return["PointCloud"]}_validateElevationInfo(e){R(n.getLogger(this),E("Point cloud layers","absolute-height",e)),R(n.getLogger(this),O("Point cloud layers",e))}};e([u({type:["PointCloudLayer"]})],V.prototype,"operationalLayerType",void 0),e([u(x)],V.prototype,"popupEnabled",void 0),e([u({type:t,json:{name:"popupInfo",write:!0}})],V.prototype,"popupTemplate",void 0),e([u({readOnly:!0,json:{read:!1}})],V.prototype,"defaultPopupTemplate",null),e([u({readOnly:!0,json:{write:!1,read:!1,origins:{"web-document":{write:!1,read:!1}}}})],V.prototype,"opacity",void 0),e([u({type:["show","hide"]})],V.prototype,"listMode",void 0),e([u({types:[P],json:{origins:{service:{read:{source:"filters"}}},name:"layerDefinition.filters",write:!0}})],V.prototype,"filters",void 0),e([u({type:[F]})],V.prototype,"fields",void 0),e([u(K.fieldsIndex)],V.prototype,"fieldsIndex",void 0),e([A("service","fields",["fields","attributeStorageInfo"])],V.prototype,"readServiceFields",null),e([u(K.outFields)],V.prototype,"outFields",void 0),e([u({readOnly:!0})],V.prototype,"attributeStorageInfo",void 0),e([u(S)],V.prototype,"elevationInfo",null),e([u({type:String,json:{origins:{"web-scene":{read:!0,write:!0},"portal-item":{read:!0,write:!0}},read:!1}})],V.prototype,"path",void 0),e([u(T)],V.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}}}}})],V.prototype,"renderer",void 0),e([U("renderer")],V.prototype,"writeRenderer",null),e([u({json:{read:!1},readOnly:!0})],V.prototype,"type",void 0),e([u({readOnly:!0})],V.prototype,"graphicOrigin",void 0),V=e([m("esri.layers.PointCloudLayer")],V);const $=V;export{$ as default};