SceneLayer.js 19 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.24/esri/copyright.txt for details.
  4. */
  5. import{_ as e}from"../chunks/tslib.es6.js";import t from"../PopupTemplate.js";import"../renderers/ClassBreaksRenderer.js";import"../renderers/DictionaryRenderer.js";import"../renderers/DotDensityRenderer.js";import"../renderers/HeatmapRenderer.js";import"../renderers/PieChartRenderer.js";import"../renderers/Renderer.js";import"../renderers/SimpleRenderer.js";import"../renderers/UniqueValueRenderer.js";import"../renderers/support/jsonUtils.js";import{webSceneRendererTypes as r}from"../renderers/support/types.js";import i from"../request.js";import s from"../core/Collection.js";import o from"../core/Error.js";import a from"../core/Logger.js";import{isSome as n,isNone as p}from"../core/maybe.js";import{MultiOriginJSONMixin as l}from"../core/MultiOriginJSONSupport.js";import{throwIfAbortError as d,isAbortError as y}from"../core/promiseUtils.js";import{whenOnce as u}from"../core/reactiveUtils.js";import{join as c}from"../core/urlUtils.js";import{property as f}from"../core/accessorSupport/decorators/property.js";import"../core/arrayUtils.js";import"../core/has.js";import{getProperties as h}from"../core/accessorSupport/utils.js";import"../core/accessorSupport/ensureType.js";import{reader as m}from"../core/accessorSupport/decorators/reader.js";import{subclass as g}from"../core/accessorSupport/decorators/subclass.js";import{OriginId as v}from"../core/accessorSupport/PropertyOrigin.js";import b from"./Layer.js";import{APIKeyMixin as I}from"./mixins/APIKeyMixin.js";import{ArcGISService as j}from"./mixins/ArcGISService.js";import{OperationalLayer as w}from"./mixins/OperationalLayer.js";import{PortalLayer as L}from"./mixins/PortalLayer.js";import{ScaleRangeLayer as S}from"./mixins/ScaleRangeLayer.js";import{SceneService as F,SaveOperationType as O}from"./mixins/SceneService.js";import{zeroCapabilities as T}from"./support/capabilities.js";import{elevationInfo as E,labelsVisible as _,legendEnabled as P,popupEnabled as x,screenSizePerspectiveEnabled as A}from"./support/commonProperties.js";import{FeatureReduction as D}from"./support/FeatureReduction.js";import R from"./support/FeatureReductionSelection.js";import{FetchAssociatedFeatureLayer as U}from"./support/FetchAssociatedFeatureLayer.js";import{defineFieldProperties as q}from"./support/fieldProperties.js";import Q from"./support/FieldsIndex.js";import{fixRendererFields as N}from"./support/fieldUtils.js";import{I3SNodePageDefinition as C,I3SMaterialDefinition as k,I3STextureSetDefinition as G,I3SGeometryDefinition as V}from"./support/I3SLayerDefinitions.js";import K from"./support/LabelClass.js";import{reader as M}from"./support/labelingInfo.js";import $ from"./support/LayerFloorInfo.js";import{RangeInfo as W}from"./support/RangeInfo.js";import z from"./support/SceneFilter.js";import{loadStyleRenderer as H}from"../renderers/support/styleUtils.js";import Z from"../rest/support/Query.js";import{createPopupTemplate as B}from"../support/popupUtils.js";import{transparencyToOpacity as J}from"../webdoc/support/opacityUtils.js";const X=["3DObject","Point"],Y=a.getLogger("esri.layers.SceneLayer"),ee=q();let te=class extends(F(j(w(L(S(l(I(b)))))))){constructor(...e){super(...e),this.featureReduction=null,this.rangeInfos=null,this.operationalLayerType="ArcGISSceneServiceLayer",this.type="scene",this.fields=null,this.floorInfo=null,this.outFields=null,this.nodePages=null,this.materialDefinitions=null,this.textureSetDefinitions=null,this.geometryDefinitions=null,this.serviceUpdateTimeStamp=null,this.excludeObjectIds=new s,this.definitionExpression=null,this.filter=null,this.path=null,this.labelsVisible=!0,this.labelingInfo=null,this.legendEnabled=!0,this.priority=null,this.semantic=null,this.cachedDrawingInfo={color:!1},this.popupEnabled=!0,this.popupTemplate=null,this.objectIdField=null,this.globalIdField=null,this._fieldUsageInfo={},this.screenSizePerspectiveEnabled=!0}normalizeCtorArgs(e,t){return"string"==typeof e?{url:e,...t}:e}getField(e){return this.fieldsIndex.get(e)}getFieldDomain(e,t){const r=this.getFeatureType(t?.feature)?.domains?.[e];return r&&"inherited"!==r.type?r:this.getField(e)?.domain??null}getFeatureType(e){return e&&n(this.associatedLayer)?this.associatedLayer.getFeatureType(e):null}get types(){return n(this.associatedLayer)?this.associatedLayer.types:[]}get typeIdField(){return n(this.associatedLayer)?this.associatedLayer.typeIdField:null}get formTemplate(){return n(this.associatedLayer)?this.associatedLayer.formTemplate:null}get fieldsIndex(){return new Q(this.fields)}readNodePages(e,t,r){return"Point"===t.layerType&&(e=t.pointNodePages),null==e||"object"!=typeof e?null:C.fromJSON(e,r)}set elevationInfo(e){this._set("elevationInfo",e),this.loaded&&this._validateElevationInfo()}get geometryType(){return ie[this.profile]||"mesh"}set renderer(e){N(e,this.fieldsIndex),this._set("renderer",e)}readCachedDrawingInfo(e){return null!=e&&"object"==typeof e||(e={}),null==e.color&&(e.color=!1),e}get capabilities(){const e=n(this.associatedLayer)&&this.associatedLayer.capabilities?this.associatedLayer.capabilities:T,{query:t,editing:{supportsGlobalId:r,supportsRollbackOnFailure:i,supportsUploadWithItemId:s,supportsReturnServiceEditsInSourceSpatialReference:o},data:{supportsZ:a,supportsM:p,isVersioned:l,supportsAttachment:d},operations:{supportsEditing:y,supportsUpdate:u,supportsQuery:c,supportsQueryAttachments:f}}=e,h=e.operations.supportsChangeTracking;return{query:t,editing:{supportsGlobalId:r,supportsReturnServiceEditsInSourceSpatialReference:o,supportsRollbackOnFailure:i,supportsGeometryUpdate:!1,supportsUploadWithItemId:s},data:{supportsAttachment:d,supportsZ:a,supportsM:p,isVersioned:l},operations:{supportsQuery:c,supportsQueryAttachments:f,supportsEditing:y&&h,supportsAdd:!1,supportsDelete:!1,supportsUpdate:u&&h}}}get editingEnabled(){return this._isOverridden("editingEnabled")?this._get("editingEnabled"):this.userHasEditingPrivileges}set editingEnabled(e){null!=e?this._override("editingEnabled",e):this._clearOverride("editingEnabled")}get defaultPopupTemplate(){return n(this.associatedLayer)||this.attributeStorageInfo?this.createPopupTemplate():null}readObjectIdField(e,t){return!e&&t.fields&&t.fields.some((t=>("esriFieldTypeOID"===t.type&&(e=t.name),!!e))),e||void 0}readGlobalIdField(e,t){return!e&&t.fields&&t.fields.some((t=>("esriFieldTypeGlobalID"===t.type&&(e=t.name),!!e))),e||void 0}get displayField(){return n(this.associatedLayer)?this.associatedLayer.displayField:null}readProfile(e,t){const r=t.store.profile;return null!=r&&re[r]?re[r]:(Y.error("Unknown or missing profile",{profile:r,layer:this}),"mesh-pyramids")}load(e){const t=n(e)?e.signal:null,r=this.loadFromPortal({supportedTypes:["Scene Service"]},e).catch(d).then((()=>this._fetchService(t))).then((()=>Promise.all([this._fetchIndexAndUpdateExtent(this.nodePages,t),this._setAssociatedFeatureLayer(t),n(this.filter)?this.filter.loadGeometries(this.spatialReference):null]))).then((()=>this._validateElevationInfo())).then((()=>this._applyAssociatedLayerOverrides())).then((()=>this._populateFieldUsageInfo())).then((()=>H(this,{origin:"service"},t))).then((()=>N(this.renderer,this.fieldsIndex))).then((()=>this.finishLoadEditablePortalLayer(e)));return this.addResolvingPromise(r),Promise.resolve(this)}async beforeSave(){n(this.filter)&&await this.load()}createQuery(){const e=new Z;return"mesh"!==this.geometryType&&(e.returnGeometry=!0,e.returnZ=!0),e.where=this.definitionExpression||"1=1",e.sqlFormat="standard",e}queryExtent(e,t){return this._getAssociatedLayerForQuery().then((r=>r.queryExtent(e||this.createQuery(),t)))}queryFeatureCount(e,t){return this._getAssociatedLayerForQuery().then((r=>r.queryFeatureCount(e||this.createQuery(),t)))}queryFeatures(e,t){return this._getAssociatedLayerForQuery().then((r=>r.queryFeatures(e||this.createQuery(),t))).then((e=>{if(e?.features)for(const t of e.features)t.layer=this,t.sourceLayer=this;return e}))}queryObjectIds(e,t){return this._getAssociatedLayerForQuery().then((r=>r.queryObjectIds(e||this.createQuery(),t)))}queryAttachments(e,t){return this._getAssociatedLayerForQuery().then((r=>r.queryAttachments(e,t)))}getFieldUsageInfo(e){const t={supportsLabelingInfo:!1,supportsRenderer:!1,supportsPopupTemplate:!1,supportsLayerQuery:!1};return this.loaded?this._fieldUsageInfo[e]||t:(Y.error("#getFieldUsageInfo()","Unavailable until layer is loaded"),t)}createPopupTemplate(e){return B(this,e)}_getAssociatedLayerForQuery(){const e=this.associatedLayer;return n(e)&&e.loaded?Promise.resolve(e):this._loadAssociatedLayerForQuery()}async _loadAssociatedLayerForQuery(){if(await this.load(),p(this.associatedLayer))throw new o("scenelayer:query-not-available","SceneLayer queries are not available without an associated feature layer",{layer:this});try{await this.associatedLayer.load()}catch(e){throw new o("scenelayer:query-not-available","SceneLayer associated feature layer could not be loaded",{layer:this,error:e})}return this.associatedLayer}hasCachedStatistics(e){return null!=this.statisticsInfo&&this.statisticsInfo.some((t=>t.name===e))}async queryCachedStatistics(e,t){if(await this.load(t),!this.statisticsInfo)throw new o("scenelayer:no-cached-statistics","Cached statistics are not available for this layer");const r=this.fieldsIndex.get(e);if(!r)throw new o("scenelayer:field-unexisting",`Field '${e}' does not exist on the layer`);for(const s of this.statisticsInfo)if(s.name===r.name){const e=c(this.parsedUrl.path,s.href);return i(e,{query:{f:"json",token:this.apiKey},responseType:"json",signal:t?t.signal:null}).then((e=>e.data))}throw new o("scenelayer:no-cached-statistics","Cached statistics for this attribute are not available")}async saveAs(e,t){return this._debouncedSaveOperations(O.SAVE_AS,{...t,getTypeKeywords:()=>this._getTypeKeywords(),portalItemLayerType:"scene"},e)}async save(){const e={getTypeKeywords:()=>this._getTypeKeywords(),portalItemLayerType:"scene"};return this._debouncedSaveOperations(O.SAVE,e)}async applyEdits(e,t){const r=await import("./graphics/editingSupport.js");if(await this.load(),p(this.associatedLayer))throw new o(`${this.type}-layer:not-editable`,"Service is not editable");return await this.associatedLayer.load(),r.applyEdits(this,this.associatedLayer.source,e,t)}on(e,t){return super.on(e,t)}validateLayer(e){if(e.layerType&&!X.includes(e.layerType))throw new o("scenelayer:layer-type-not-supported","SceneLayer 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"});function t(e,t){let r=!1,i=!1;if(null==e)r=!0,i=!0;else{const s=t&&t.isGeographic;switch(e){case"east-north-up":case"earth-centered":r=!0,i=s;break;case"vertex-reference-frame":r=!0,i=!s;break;default:r=!1}}if(!r)throw new o("scenelayer:unsupported-normal-reference-frame","Normal reference frame is invalid.");if(!i)throw new o("scenelayer:incompatible-normal-reference-frame","Normal reference frame is incompatible with layer spatial reference.")}t(this.normalReferenceFrame,this.spatialReference)}_getTypeKeywords(){const e=[];if("points"===this.profile)e.push("Point");else{if("mesh-pyramids"!==this.profile)throw new o("scenelayer:unknown-profile","SceneLayer:save() encountered an unknown SceneLayer profile: "+this.profile);e.push("3DObject")}return e}_populateFieldUsageInfo(){if(this._fieldUsageInfo={},this.fields)for(const e of this.fields){const t=!(!this.attributeStorageInfo||!this.attributeStorageInfo.some((t=>t.name===e.name))),r=!!(n(this.associatedLayer)&&this.associatedLayer.fields&&this.associatedLayer.fields.some((t=>t&&e.name===t.name))),i={supportsLabelingInfo:t,supportsRenderer:t,supportsPopupTemplate:t||r,supportsLayerQuery:r};this._fieldUsageInfo[e.name]=i}}_applyAssociatedLayerOverrides(){this._applyAssociatedLayerFieldsOverrides(),this._applyAssociatedLayerPopupOverrides()}_applyAssociatedLayerFieldsOverrides(){if(p(this.associatedLayer)||!this.associatedLayer.fields)return;let e=null;for(const t of this.associatedLayer.fields){const r=this.getField(t.name);r?(!r.domain&&t.domain&&(r.domain=t.domain.clone()),r.editable=t.editable,r.nullable=t.nullable,r.length=t.length):(e||(e=this.fields?this.fields.slice():[]),e.push(t.clone()))}e&&this._set("fields",e)}_applyAssociatedLayerPopupOverrides(){if(p(this.associatedLayer))return;const e=["popupTemplate","popupEnabled"],t=h(this);for(let r=0;r<e.length;r++){const i=e[r],s=this.originIdOf(i),o=this.associatedLayer.originIdOf(i);s<o&&(o===v.SERVICE||o===v.PORTAL_ITEM)&&t.setAtOrigin(i,this.associatedLayer[i],o)}}async _setAssociatedFeatureLayer(e){if(!["mesh-pyramids","points"].includes(this.profile))return;const t=new U(this.parsedUrl,this.portalItem,this.apiKey,e);try{this.associatedLayer=await t.fetch()}catch(r){y(r)||this._logWarningOnPopupEnabled()}}async _logWarningOnPopupEnabled(){await u((()=>this.popupEnabled&&null!=this.popupTemplate));const e=`this SceneLayer: ${this.title}`;null==this.attributeStorageInfo?Y.warn(`Associated FeatureLayer could not be loaded and no binary attributes found. Popups will not work on ${e}`):Y.info(`Associated FeatureLayer could not be loaded. Falling back to binary attributes for Popups on ${e}`)}_validateElevationInfo(){const e=this.elevationInfo;e&&("mesh-pyramids"===this.profile&&"relative-to-scene"===e.mode&&Y.warn(".elevationInfo=","Mesh scene layers don't support relative-to-scene elevation mode"),e.featureExpressionInfo&&"0"!==e.featureExpressionInfo.expression&&Y.warn(".elevationInfo=","Scene layers do not support featureExpressionInfo"))}};e([f({types:{key:"type",base:D,typeMap:{selection:R}},json:{origins:{"web-scene":{name:"layerDefinition.featureReduction",write:!0},"portal-item":{name:"layerDefinition.featureReduction",write:!0}}}})],te.prototype,"featureReduction",void 0),e([f({type:[W],json:{read:!1,origins:{"web-scene":{name:"layerDefinition.rangeInfos",write:!0},"portal-item":{name:"layerDefinition.rangeInfos",write:!0}}}})],te.prototype,"rangeInfos",void 0),e([f({json:{read:!1}})],te.prototype,"associatedLayer",void 0),e([f({type:["show","hide"]})],te.prototype,"listMode",void 0),e([f({type:["ArcGISSceneServiceLayer"]})],te.prototype,"operationalLayerType",void 0),e([f({json:{read:!1},readOnly:!0})],te.prototype,"type",void 0),e([f({...ee.fields,readOnly:!0,json:{read:!1,origins:{service:{read:!0}}}})],te.prototype,"fields",void 0),e([f()],te.prototype,"types",null),e([f()],te.prototype,"typeIdField",null),e([f()],te.prototype,"formTemplate",null),e([f({readOnly:!0})],te.prototype,"fieldsIndex",null),e([f({type:$,json:{read:{source:"layerDefinition.floorInfo"},write:{target:"layerDefinition.floorInfo"}}})],te.prototype,"floorInfo",void 0),e([f(ee.outFields)],te.prototype,"outFields",void 0),e([f({type:C,readOnly:!0,json:{read:!1}})],te.prototype,"nodePages",void 0),e([m("service","nodePages",["nodePages","pointNodePages"])],te.prototype,"readNodePages",null),e([f({type:[k],readOnly:!0})],te.prototype,"materialDefinitions",void 0),e([f({type:[G],readOnly:!0})],te.prototype,"textureSetDefinitions",void 0),e([f({type:[V],readOnly:!0})],te.prototype,"geometryDefinitions",void 0),e([f({readOnly:!0})],te.prototype,"serviceUpdateTimeStamp",void 0),e([f({readOnly:!0})],te.prototype,"attributeStorageInfo",void 0),e([f({readOnly:!0})],te.prototype,"statisticsInfo",void 0),e([f({type:s.ofType(Number),nonNullable:!0,json:{origins:{service:{read:!1,write:!1}},name:"layerDefinition.excludeObjectIds",write:{enabled:!0}}})],te.prototype,"excludeObjectIds",void 0),e([f({type:String,json:{origins:{service:{read:!1,write:!1}},name:"layerDefinition.definitionExpression",write:{enabled:!0,allowNull:!0}}})],te.prototype,"definitionExpression",void 0),e([f({type:z,json:{name:"layerDefinition.polygonFilter",write:!0}})],te.prototype,"filter",void 0),e([f({type:String,json:{origins:{"web-scene":{read:!0,write:!0}},read:!1}})],te.prototype,"path",void 0),e([f(E)],te.prototype,"elevationInfo",null),e([f({type:String})],te.prototype,"geometryType",null),e([f(_)],te.prototype,"labelsVisible",void 0),e([f({type:[K],json:{origins:{service:{name:"drawingInfo.labelingInfo",read:{reader:M},write:!1}},name:"layerDefinition.drawingInfo.labelingInfo",read:{reader:M},write:!0}})],te.prototype,"labelingInfo",void 0),e([f(P)],te.prototype,"legendEnabled",void 0),e([f({type:Number,json:{origins:{"web-document":{default:1,write:{enabled:!0,target:{opacity:{type:Number},"layerDefinition.drawingInfo.transparency":{type:Number}}},read:{source:["opacity","layerDefinition.drawingInfo.transparency"],reader(e,t){if("number"==typeof e&&e>=0&&e<=1)return e;const r=t.layerDefinition?.drawingInfo?.transparency;return void 0!==r?J(r):void 0}}},"portal-item":{write:!0},service:{read:!1}}}})],te.prototype,"opacity",void 0),e([f({type:["Low","High"],readOnly:!0,json:{read:!1,origins:{service:{read:!0}}}})],te.prototype,"priority",void 0),e([f({type:["Labels"],readOnly:!0,json:{read:!1,origins:{service:{read:!0}}}})],te.prototype,"semantic",void 0),e([f({types:r,json:{origins:{service:{read:{source:"drawingInfo.renderer"}}},name:"layerDefinition.drawingInfo.renderer",write:!0},value:null})],te.prototype,"renderer",null),e([f({json:{read:!1}})],te.prototype,"cachedDrawingInfo",void 0),e([m("service","cachedDrawingInfo")],te.prototype,"readCachedDrawingInfo",null),e([f({readOnly:!0,json:{read:!1}})],te.prototype,"capabilities",null),e([f({type:Boolean,json:{read:!1}})],te.prototype,"editingEnabled",null),e([f(x)],te.prototype,"popupEnabled",void 0),e([f({type:t,json:{name:"popupInfo",write:!0}})],te.prototype,"popupTemplate",void 0),e([f({readOnly:!0,json:{read:!1}})],te.prototype,"defaultPopupTemplate",null),e([f({type:String,json:{read:!1}})],te.prototype,"objectIdField",void 0),e([m("service","objectIdField",["objectIdField","fields"])],te.prototype,"readObjectIdField",null),e([f({type:String,json:{read:!1}})],te.prototype,"globalIdField",void 0),e([m("service","globalIdField",["globalIdField","fields"])],te.prototype,"readGlobalIdField",null),e([f({readOnly:!0,type:String,json:{read:!1}})],te.prototype,"displayField",null),e([f({type:String,json:{read:!1}})],te.prototype,"profile",void 0),e([m("service","profile",["store.profile"])],te.prototype,"readProfile",null),e([f({readOnly:!0,type:String,json:{origins:{service:{read:{source:"store.normalReferenceFrame"}}},read:!1}})],te.prototype,"normalReferenceFrame",void 0),e([f(A)],te.prototype,"screenSizePerspectiveEnabled",void 0),te=e([g("esri.layers.SceneLayer")],te);const re={"mesh-pyramids":"mesh-pyramids",meshpyramids:"mesh-pyramids","features-meshes":"mesh-pyramids",points:"points","features-points":"points",lines:"lines","features-lines":"lines",polygons:"polygons","features-polygons":"polygons"},ie={"mesh-pyramids":"mesh",points:"point",lines:"polyline",polygons:"polygon"},se=te;export{se as default};