FeatureLayer.js 39 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 r from"../renderers/SimpleRenderer.js";import i from"../renderers/UniqueValueRenderer.js";import{read as o}from"../renderers/support/jsonUtils.js";import{rendererTypes as s,webSceneRendererTypes as a}from"../renderers/support/types.js";import n from"../request.js";import{symbolTypes as p,symbolTypesRenderer as l}from"../symbols.js";import{ClonableMixin as u}from"../core/Clonable.js";import d from"../core/Collection.js";import c from"../core/Error.js";import y from"../core/Handles.js";import h from"../core/has.js";import{JSONMap as m}from"../core/jsonMap.js";import{clone as f}from"../core/lang.js";import b from"../core/Logger.js";import{destroyMaybe as g,isSome as w}from"../core/maybe.js";import{MultiOriginJSONMixin as v}from"../core/MultiOriginJSONSupport.js";import{setDeepValue as S}from"../core/object.js";import{throwIfAbortError as F,whenOrAbort as I}from"../core/promiseUtils.js";import{sqlAnd as j,parseWhereClause as T}from"../core/sql.js";import{urlToObject as E,join as x}from"../core/urlUtils.js";import{property as D}from"../core/accessorSupport/decorators/property.js";import{cast as C}from"../core/accessorSupport/decorators/cast.js";import{reader as A}from"../core/accessorSupport/decorators/reader.js";import{subclass as M}from"../core/accessorSupport/decorators/subclass.js";import{writer as L}from"../core/accessorSupport/decorators/writer.js";import{createTypeReader as R}from"../core/accessorSupport/extensions/serializableProperty/reader.js";import _ from"../form/FormTemplate.js";import O from"../geometry/Extent.js";import P from"../geometry/HeightModelInfo.js";import q from"../geometry/SpatialReference.js";import Q from"./Layer.js";import{MemorySource as U}from"./graphics/sources/MemorySource.js";import{APIKeyMixin as G}from"./mixins/APIKeyMixin.js";import{ArcGISService as V}from"./mixins/ArcGISService.js";import{BlendLayer as z}from"./mixins/BlendLayer.js";import{CustomParametersMixin as B}from"./mixins/CustomParametersMixin.js";import{FeatureEffectLayer as k}from"./mixins/FeatureEffectLayer.js";import{OperationalLayer as N}from"./mixins/OperationalLayer.js";import{OrderedLayer as W}from"./mixins/OrderedLayer.js";import{PortalLayer as H}from"./mixins/PortalLayer.js";import{RefreshableLayer as J}from"./mixins/RefreshableLayer.js";import{ScaleRangeLayer as Z}from"./mixins/ScaleRangeLayer.js";import{TemporalLayer as $}from"./mixins/TemporalLayer.js";import{titleFromUrlAndName as K,parse as X,cleanTitle as Y,sanitizeUrlWithLayerId as ee,writeUrlWithLayerId as te,isHostedAgolService as re}from"./support/arcgisLayerUrl.js";import{id as ie,labelsVisible as oe,legendEnabled as se,minScale as ae,maxScale as ne,popupEnabled as pe,url as le,elevationInfo as ue,opacityDrawingInfo as de,listMode as ce,screenSizePerspectiveEnabled as ye}from"./support/commonProperties.js";import{FeatureIndex as he}from"./support/FeatureIndex.js";import{featureReductionProperty as me}from"./support/featureReductionUtils.js";import fe from"./support/FeatureTemplate.js";import be from"./support/FeatureType.js";import{defineFieldProperties as ge}from"./support/fieldProperties.js";import{fixRendererFields as we,fixTimeInfoFields as ve}from"./support/fieldUtils.js";import Se from"./support/GeometryFieldsInfo.js";import Fe from"./support/LabelClass.js";import{reader as Ie}from"./support/labelingInfo.js";import je from"./support/LayerFloorInfo.js";import Te from"./support/Relationship.js";import Ee from"./support/TimeInfo.js";import{serviceSupportsSpatialReference as xe}from"./support/versionUtils.js";import{DataLayerSource as De}from"./support/source/DataLayerSource.js";import{loadStyleRenderer as Ce}from"../renderers/support/styleUtils.js";import Ae from"../rest/support/AttachmentQuery.js";import Me from"../rest/support/FeatureSet.js";import Le from"../rest/support/Query.js";import Re from"../rest/support/RelationshipQuery.js";import _e from"../rest/support/TopFeaturesQuery.js";import{createPopupTemplate as Oe}from"../support/popupUtils.js";import{opacityToTransparency as Pe}from"../webdoc/support/opacityUtils.js";const qe=new m({esriGeometryPoint:"point",esriGeometryMultipoint:"multipoint",esriGeometryPolyline:"polyline",esriGeometryPolygon:"polygon",esriGeometryMultiPatch:"multipatch"}),Qe={name:"supportsName",size:"supportsSize",contentType:"supportsContentType",keywords:"supportsKeywords",exifInfo:"supportsExifInfo"},Ue="FeatureLayer",Ge=b.getLogger("esri.layers.FeatureLayer");function Ve(e,t){return new c("layer:unsupported",`Layer (${e.title}, ${e.id}) of type '${e.declaredClass}' ${t}`,{layer:e})}function ze(e){return e&&e instanceof d}function Be(e,t,r){return!!(e&&e.hasOwnProperty(t)?e[t]:r)}function ke(e,t,r){return e&&e.hasOwnProperty(t)?e[t]:r}function Ne(e){const t=e?.supportedSpatialAggregationStatistics?.map((e=>e.toLowerCase()));return{envelope:!!t?.includes("envelopeaggregate"),centroid:!!t?.includes("centroidaggregate"),convexHull:!!t?.includes("convexhullaggregate")}}function We(e,t){const r=e?.supportedOperationsWithCacheHint?.map((e=>e.toLowerCase()));return!!r?.includes(t.toLowerCase())}const He=ge();function Je(e,t,r){const i=!!r?.writeLayerSchema;return{enabled:i,ignoreOrigin:i}}let Ze=class extends(k(z(W($(Z(J(V(N(H(v(B(G(u(Q)))))))))))))){constructor(...e){super(...e),this._handles=new y,this.capabilities=null,this.charts=null,this.copyright=null,this.datesInUnknownTimezone=!1,this.displayField=null,this.definitionExpression=null,this.dynamicDataSource=null,this.editFieldsInfo=null,this.editingInfo=null,this.elevationInfo=null,this.featureReduction=null,this.fields=null,this.fieldsIndex=null,this.floorInfo=null,this.formTemplate=null,this.fullExtent=null,this.gdbVersion=null,this.geometryFieldsInfo=null,this.geometryType=null,this.hasM=void 0,this.hasZ=void 0,this.heightModelInfo=null,this.historicMoment=null,this.infoFor3D=null,this.isTable=!1,this.labelsVisible=!0,this.labelingInfo=null,this.layerId=void 0,this.legendEnabled=!0,this.minScale=0,this.maxScale=0,this.globalIdField=null,this.objectIdField=null,this.outFields=null,this.path=null,this.popupEnabled=!0,this.popupTemplate=null,this.relationships=null,this.sourceJSON=null,this.returnM=void 0,this.returnZ=void 0,this.screenSizePerspectiveEnabled=!0,this.serviceDefinitionExpression=null,this.spatialReference=q.WGS84,this.subtypeCode=null,this.subtypeField=null,this.templates=null,this.timeInfo=null,this.title=null,this.sublayerTitleMode="item-title",this.trackIdField=null,this.type="feature",this.typeIdField=null,this.types=null,this.indexes=new(d.ofType(he)),this.userIsAdmin=!1,this.version=void 0,this.visible=!0}destroy(){this.source?.destroy(),this._handles=g(this._handles)}normalizeCtorArgs(e,t){return"string"==typeof e?{url:e,...t}:e}load(e){const t=w(e)?e.signal:null;if(this.portalItem&&this.portalItem.loaded&&this.source)return void this.addResolvingPromise(this.createGraphicsSource(t).then((e=>this._initLayerProperties(e))));const r=this.loadFromPortal({supportedTypes:["Feature Service","Feature Collection"]},e).catch(F).then((async()=>{if(this.url&&null==this.layerId&&/FeatureServer|MapServer\/*$/i.test(this.url)){const e=await this._fetchFirstLayerId(t);null!=e&&(this.layerId=e)}if(!this.url&&!this._hasMemorySource())throw new c("feature-layer:missing-url-or-source","Feature layer must be created with either a url or a source");return this._initLayerProperties(await this.createGraphicsSource(t))})).then((()=>this.finishLoadEditablePortalLayer(e)));return this.addResolvingPromise(r),Promise.resolve(this)}readCapabilities(e,t){return t=t.layerDefinition||t,{analytics:this._readAnalyticsCapabilities(t),attachment:this._readAttachmentCapabilities(t),data:this._readDataCapabilities(t),metadata:this._readMetadataCapabilities(t),operations:this._readOperationsCapabilities(t.capabilities||e,t),query:this._readQueryCapabilities(t),queryRelated:this._readQueryRelatedCapabilities(t),queryTopFeatures:this._readQueryTopFeaturesCapabilities(t),editing:this._readEditingCapabilities(t)}}get createQueryVersion(){return this.commitProperty("definitionExpression"),this.commitProperty("dynamicDataSource"),this.commitProperty("timeExtent"),this.commitProperty("timeOffset"),this.commitProperty("geometryType"),this.commitProperty("gdbVersion"),this.commitProperty("historicMoment"),this.commitProperty("returnZ"),this.commitProperty("capabilities"),this.commitProperty("returnM"),(this._get("createQueryVersion")||0)+1}get editingEnabled(){return!(this.loaded&&!this.capabilities.operations.supportsEditing)&&(this._isOverridden("editingEnabled")?this._get("editingEnabled"):this._hasMemorySource()||this.userHasEditingPrivileges)}set editingEnabled(e){null!=e?this._override("editingEnabled",e):this._clearOverride("editingEnabled")}readEditingEnabled(e,t){return this._readEditingEnabled(t,!1)}readEditingEnabledFromWebMap(e,t,r){return this._readEditingEnabled(t,!0,r)}writeEditingEnabled(e,t){this._writeEditingEnabled(e,t,!1)}writeEditingEnabledToWebMap(e,t,r,i){this._writeEditingEnabled(e,t,!0,i)}readEditingInfo(e,t){const{editingInfo:r}=t;return r?{lastEditDate:null!=r.lastEditDate?new Date(r.lastEditDate):null}:null}readIsTable(e,t){return"Table"===(t=t&&t.layerDefinition||t).type||!t.geometryType}writeIsTable(e,t,r,i){i?.writeLayerSchema&&S(r,e?"Table":"Feature Layer",t)}readMinScale(e,t){return t.effectiveMinScale||e||0}readMaxScale(e,t){return t.effectiveMaxScale||e||0}readGlobalIdFieldFromService(e,t){if((t=t.layerDefinition||t).globalIdField)return t.globalIdField;if(t.fields)for(const r of t.fields)if("esriFieldTypeGlobalID"===r.type)return r.name}readObjectIdFieldFromService(e,t){if((t=t.layerDefinition||t).objectIdField)return t.objectIdField;if(t.fields)for(const r of t.fields)if("esriFieldTypeOID"===r.type)return r.name}get parsedUrl(){const e=this.url?E(this.url):null;return null!=e&&(null!=this.dynamicDataSource?e.path=x(e.path,"dynamicLayer"):null!=this.layerId&&(e.path=x(e.path,this.layerId.toString()))),e}get defaultPopupTemplate(){return this.createPopupTemplate()}set renderer(e){we(e,this.fieldsIndex),this._set("renderer",e)}readRenderer(e,t,s){const a=(t=t.layerDefinition||t).drawingInfo&&t.drawingInfo.renderer||void 0;if(a){const e=o(a,t,s)||void 0;return e||Ge.error("Failed to create renderer",{rendererDefinition:t.drawingInfo.renderer,layer:this,context:s}),e}if(t.defaultSymbol)return t.types&&t.types.length?new i({defaultSymbol:$e(t.defaultSymbol,t,s),field:t.typeIdField,uniqueValueInfos:t.types.map((e=>({id:e.id,symbol:$e(e.symbol,e,s)})))}):new r({symbol:$e(t.defaultSymbol,t,s)})}set source(e){const t=this._get("source");t!==e&&(ze(t)&&this._resetMemorySource(t),ze(e)&&this._initMemorySource(e),this._set("source",e))}castSource(e){return e?Array.isArray(e)||e instanceof d?new U({layer:this,items:e}):e:null}readSource(e,t){const r=Me.fromJSON(t.featureSet);return new U({layer:this,items:r&&r.features||[]})}readServiceDefinitionExpression(e,t){return t.definitionQuery||t.definitionExpression}readTemplates(e,t){const r=t.editFieldsInfo,i=r&&r.creatorField,o=r&&r.editorField;return e=e&&e.map((e=>fe.fromJSON(e))),this._fixTemplates(e,i),this._fixTemplates(e,o),e}readTitle(e,t){const r=t.layerDefinition&&t.layerDefinition.name||t.name,i=t.title||t.layerDefinition&&t.layerDefinition.title;if(r){const e=this.portalItem&&this.portalItem.title;if("item-title"===this.sublayerTitleMode)return this.url?K(this.url,r):r;let t=r;if(!t&&this.url){const e=X(this.url);w(e)&&(t=e.title)}if(!t)return;return"item-title-and-service-name"===this.sublayerTitleMode&&e&&e!==t&&(t=e+" - "+t),Y(t)}if("item-title"===this.sublayerTitleMode&&i)return i}readTitleFromWebMap(e,t){return t.title||t.layerDefinition&&t.layerDefinition.name}readTypeIdField(e,t){let r=(t=t.layerDefinition||t).typeIdField;if(r&&t.fields){r=r.toLowerCase();const e=t.fields.find((e=>e.name.toLowerCase()===r));e&&(r=e.name)}return r}readTypes(e,t){e=(t=t.layerDefinition||t).types;const r=t.editFieldsInfo,i=r&&r.creatorField,o=r&&r.editorField;return e&&e.map((e=>(e=be.fromJSON(e),this._fixTemplates(e.templates,i),this._fixTemplates(e.templates,o),e)))}set url(e){const t=ee({layer:this,url:e,nonStandardUrlAllowed:!0,logger:Ge});this._set("url",t.url),null!=t.layerId&&this._set("layerId",t.layerId)}writeUrl(e,t,r,i){te(this,e,null,t,i)}readVersion(e,t){return t.currentVersion?t.currentVersion:t.hasOwnProperty("capabilities")||t.hasOwnProperty("drawingInfo")||t.hasOwnProperty("hasAttachments")||t.hasOwnProperty("htmlPopupType")||t.hasOwnProperty("relationships")||t.hasOwnProperty("timeInfo")||t.hasOwnProperty("typeIdField")||t.hasOwnProperty("types")?10:9.3}readVisible(e,t){return t.layerDefinition&&null!=t.layerDefinition.defaultVisibility?!!t.layerDefinition.defaultVisibility:null!=t.visibility?!!t.visibility:void 0}addAttachment(e,t){return this.load().then((()=>this._checkAttachmentSupport(e))).then((()=>{if(!("addAttachment"in this.source))throw new c(Ue,"Layer source does not support addAttachment capability");return this.source.addAttachment(e,t)}))}updateAttachment(e,t,r){return this.load().then((()=>this._checkAttachmentSupport(e))).then((()=>{if(!("updateAttachment"in this.source))throw new c(Ue,"Layer source does not support updateAttachment capability");return this.source.updateAttachment(e,t,r)}))}async applyEdits(e,t){const r=await import("./graphics/editingSupport.js");return await this.load(),r.applyEdits(this,this.source,e,t)}on(e,t){return super.on(e,t)}createPopupTemplate(e){return Oe(this,e)}async createGraphicsSource(e){if(this._hasMemorySource())return this.source.load({signal:e});const{default:t}=await I(import("./graphics/sources/FeatureLayerSource.js"),e);return new t({layer:this}).load({signal:e})}createQuery(){const e=new Le,t=this.get("capabilities.data"),r=this.get("capabilities.query");e.dynamicDataSource=this.dynamicDataSource,e.historicMoment=this.historicMoment,e.gdbVersion=this.gdbVersion,e.returnGeometry=!0,r&&(e.compactGeometryEnabled=r.supportsCompactGeometry,e.defaultSpatialReferenceEnabled=r.supportsDefaultSpatialReference),t&&(t.supportsZ&&null!=this.returnZ&&(e.returnZ=this.returnZ),t.supportsM&&null!=this.returnM&&(e.returnM=this.returnM)),e.outFields=["*"];const i=w(this.subtypeCode)?`${this.subtypeField} = ${this.subtypeCode}`:null,o=j(this.definitionExpression,i);e.where=o||"1=1";const{timeOffset:s,timeExtent:a}=this;return e.timeExtent=null!=s&&null!=a?a.offset(-s.value,s.unit):a||null,e.multipatchOption="multipatch"===this.geometryType?"xyFootprint":null,e}deleteAttachments(e,t){return this.load().then((()=>this._checkAttachmentSupport(e))).then((()=>{if(!("deleteAttachments"in this.source))throw new c(Ue,"Layer source does not support deleteAttachments capability");return this.source.deleteAttachments(e,t)}))}fetchRecomputedExtents(e){return this.load({signal:e?.signal}).then((()=>{if(this.source.fetchRecomputedExtents)return this.source.fetchRecomputedExtents(e);throw new c(Ue,"Layer source does not support fetchUpdates capability")}))}getFeatureType(e){const{typeIdField:t,types:r}=this;if(!t||!e)return null;const i=e.attributes?e.attributes[t]:void 0;if(null==i)return null;let o=null;return r.some((e=>{const{id:t}=e;return null!=t&&(t.toString()===i.toString()&&(o=e),!!o)})),o}getFieldDomain(e,t){const r=t&&t.feature,i=this.getFeatureType(r);if(i){const t=i.domains&&i.domains[e];if(t&&"inherited"!==t.type)return t}return this._getLayerDomain(e)}getField(e){return this.fieldsIndex.get(e)}queryAttachments(e,t){return e=Ae.from(e),this.load().then((()=>{if(!this.get("capabilities.data.supportsAttachment"))throw new c(Ue,"this layer doesn't support attachments");const{attachmentTypes:t,objectIds:r,globalIds:i,num:o,size:s,start:a,where:n}=e;if(!this.get("capabilities.operations.supportsQueryAttachments")){const p=r&&r.length>1,l=t&&t.length,u=i&&i.length,d=s&&s.length;if(p||l||u||d||o||a||n)throw new c(Ue,"when 'supportsQueryAttachments' is false, only objectIds of length 1 are supported",e)}if(!(r&&r.length||n))throw new c(Ue,"'objectIds' or 'where' are required to perform attachment query",e);if(!("queryAttachments"in this.source))throw new c(Ue,"Layer source does not support queryAttachments capability",e);return this.source.queryAttachments(e)}))}queryFeatures(e,t){return this.load().then((()=>this.source.queryFeatures(Le.from(e)||this.createQuery(),t))).then((e=>{if(e?.features)for(const t of e.features)t.layer=t.sourceLayer=this;return e}))}queryObjectIds(e,t){return this.load().then((()=>{if(this.source.queryObjectIds)return this.source.queryObjectIds(Le.from(e)||this.createQuery(),t);throw new c(Ue,"Layer source does not support queryObjectIds capability")}))}queryFeatureCount(e,t){return this.load().then((()=>{if(this.source.queryFeatureCount)return this.source.queryFeatureCount(Le.from(e)||this.createQuery(),t);throw new c(Ue,"Layer source does not support queryFeatureCount capability")}))}queryExtent(e,t){return this.load().then((()=>{if(this.source.queryExtent)return this.source.queryExtent(Le.from(e)||this.createQuery(),t);throw new c(Ue,"Layer source does not support queryExtent capability")}))}queryRelatedFeatures(e,t){return this.load().then((()=>{if("queryRelatedFeatures"in this.source)return this.source.queryRelatedFeatures(Re.from(e),t);throw new c(Ue,"Layer source does not support queryRelatedFeatures capability")}))}queryRelatedFeaturesCount(e,t){return this.load().then((()=>{if("queryRelatedFeaturesCount"in this.source)return this.source.queryRelatedFeaturesCount(Re.from(e),t);throw new c(Ue,"Layer source does not support queryRelatedFeaturesCount capability")}))}queryTopFeatures(e,t){return this.load().then((()=>{if("queryTopFeatures"in this.source&&this.get("capabilities.query.supportsTopFeaturesQuery"))return this.source.queryTopFeatures(_e.from(e),t).then((e=>{if(e?.features)for(const t of e.features)t.layer=t.sourceLayer=this;return e}));throw new c(Ue,"Layer source does not support queryTopFeatures capability")}))}queryTopObjectIds(e,t){return this.load().then((()=>{if("queryTopObjectIds"in this.source&&this.get("capabilities.query.supportsTopFeaturesQuery"))return this.source.queryTopObjectIds(_e.from(e),t);throw new c(Ue,"Layer source does not support queryTopObjectIds capability")}))}queryTopFeaturesExtent(e,t){return this.load().then((()=>{if("queryTopExtents"in this.source&&this.get("capabilities.query.supportsTopFeaturesQuery"))return this.source.queryTopExtents(_e.from(e),t);throw new c(Ue,"Layer source does not support queryTopExtents capability")}))}queryTopFeatureCount(e,t){return this.load().then((()=>{if("queryTopCount"in this.source&&this.get("capabilities.query.supportsTopFeaturesQuery"))return this.source.queryTopCount(_e.from(e),t);throw new c(Ue,"Layer source does not support queryFeatureCount capability")}))}read(e,t){const r=e.featureCollection;if(r){const e=r.layers;e&&1===e.length&&(super.read(e[0],t),null!=r.showLegend&&super.read({showLegend:r.showLegend},t))}super.read(e,t),t&&"service"===t.origin&&this.revert(["objectIdField","fields","timeInfo","spatialReference"],"service")}write(e,t){t={...t,writeLayerSchema:t?.writeLayerSchema??this._hasMemorySource()};const{origin:r,layerContainerType:i,messages:o}=t;if(this.dynamicDataSource)return o?.push(Ve(this,"using a dynamic data source cannot be written to web scenes, web maps and feature service items")),null;if(this.isTable){if("web-scene"===r||"web-map"===r&&"tables"!==i)return o?.push(Ve(this,"using a table source cannot be written to web scenes and web maps")),null;if(this._hasMemorySource())return o?.push(Ve(this,"using an in-memory table source cannot be written to web scenes and web maps")),null}else if(this.loaded&&"web-map"===r&&"tables"===i)return o?.push(Ve(this,"using a non-table source cannot be written to tables in web maps")),null;return super.write(e,t)}clone(){if(this._hasMemorySource())throw new c(Ue,`FeatureLayer (title: ${this.title}, id: ${this.id}) created using in-memory source cannot be cloned`);return super.clone()}serviceSupportsSpatialReference(e){return!!this.loaded&&("memory"===this.source.type||xe(this,e))}async save(e){return(await import("./save/featureLayerUtils.js")).save(this,e)}async saveAs(e,t){return(await import("./save/featureLayerUtils.js")).saveAs(this,e,t)}_readEditingEnabled(e,t,r){let i=e.layerDefinition?.capabilities;return i?this._hasEditingCapability(i):(i=e.capabilities,t&&"web-map"===r?.origin&&!this._hasMemorySource()&&i?this._hasEditingCapability(i):void 0)}_hasEditingCapability(e){return e.toLowerCase().split(",").map((e=>e.trim())).includes("editing")}_writeEditingEnabled(e,t,r,i){if(!e){const e=this.capabilities?.operations?.supportsSync?"Query,Sync":"Query";S("layerDefinition.capabilities",e,t),r&&!i?.writeLayerSchema&&(t.capabilities=e)}}_checkAttachmentSupport(e){const{attributes:t}=e,{objectIdField:r}=this;return this.get("capabilities.data.supportsAttachment")?e?t?t[r]?void 0:Promise.reject(new c(Ue,`feature is missing the identifying attribute ${r}`)):Promise.reject(new c(Ue,"'attributes' are required on a feature to query attachments")):Promise.reject(new c(Ue,"A feature is required to add/delete/update attachments")):Promise.reject(new c(Ue,"this layer doesn't support attachments"))}_getLayerDomain(e){const t=this.fieldsIndex.get(e);return t?t.domain:null}_fetchFirstLayerId(e){return n(this.url,{query:{f:"json",...this.customParameters,token:this.apiKey},responseType:"json",signal:e}).then((e=>{const t=e.data;if(t)return Array.isArray(t.layers)&&t.layers.length>0?t.layers[0].id:Array.isArray(t.tables)&&t.tables.length>0?t.tables[0].id:void 0}))}async _initLayerProperties(e){return this._set("source",e),e.sourceJSON&&(this.sourceJSON=e.sourceJSON,this.read(e.sourceJSON,{origin:"service",url:this.parsedUrl})),this._verifySource(),this._verifyFields(),we(this.renderer,this.fieldsIndex),ve(this.timeInfo,this.fieldsIndex),Ce(this,{origin:"service"})}async hasDataChanged(){if(this.source?.refresh)try{const{dataChanged:e,updates:t}=await(this.source?.refresh());if(w(t)&&(this.sourceJSON={...this.sourceJSON,...t},this.read(t,{origin:"service",url:this.parsedUrl})),e)return!0}catch{}if(this.definitionExpression)try{return(await T(this.definitionExpression,this.fieldsIndex)).hasDateFunctions}catch{}return!1}_verifyFields(){const e=this.parsedUrl&&this.parsedUrl.path||"undefined";this.objectIdField||console.log("FeatureLayer: 'objectIdField' property is not defined (url: "+e+")"),this.isTable||this._hasMemorySource()||-1!==e.search(/\/FeatureServer\//i)||this.fields?.some((e=>"geometry"===e.type))||console.log("FeatureLayer: unable to find field of type 'geometry' in the layer 'fields' list. If you are using a map service layer, features will not have geometry (url: "+e+")")}_fixTemplates(e,t){e&&e.forEach((e=>{const r=e.prototype&&e.prototype.attributes;r&&t&&delete r[t]}))}_verifySource(){if(this._hasMemorySource()){if(this.url)throw new c("feature-layer:mixed-source-and-url","FeatureLayer cannot be created with both an in-memory source and a url")}else if(!this.url)throw new c("feature-layer:source-or-url-required","FeatureLayer requires either a url, a valid portal item or a source")}_initMemorySource(e){e.forEach((e=>{e.layer=this,e.sourceLayer=this})),this._handles.add([e.on("after-add",(e=>{e.item.layer=this,e.item.sourceLayer=this})),e.on("after-remove",(e=>{e.item.layer=null,e.item.sourceLayer=null}))],"fl-source")}_resetMemorySource(e){e.forEach((e=>{e.layer=null,e.sourceLayer=null})),this._handles.remove("fl-source")}_hasMemorySource(){return!(this.url||!this.source)}_readAnalyticsCapabilities(e){return{supportsCacheHint:We(e.advancedQueryCapabilities,"queryAnalytics")}}_readAttachmentCapabilities(e){const t=e.attachmentProperties,r={supportsName:!1,supportsSize:!1,supportsContentType:!1,supportsKeywords:!1,supportsExifInfo:!1,supportsCacheHint:We(e.advancedQueryCapabilities,"queryAttachments"),supportsResize:Be(e,"supportsAttachmentsResizing",!1)};return t&&Array.isArray(t)&&t.forEach((e=>{const t=Qe[e.name];t&&(r[t]=!!e.isEnabled)})),r}_readDataCapabilities(e){return{isVersioned:Be(e,"isDataVersioned",!1),supportsAttachment:Be(e,"hasAttachments",!1),supportsM:Be(e,"hasM",!1),supportsZ:Be(e,"hasZ",!1)}}_readMetadataCapabilities(e){return{supportsAdvancedFieldProperties:Be(e,"supportsFieldDescriptionProperty",!1)}}_readOperationsCapabilities(e,t){const r=e?e.toLowerCase().split(",").map((e=>e.trim())):[],i=this.url?X(this.url):null,o=r.includes(w(i)&&"MapServer"===i.serverType?"data":"query"),s=r.includes("editing")&&!t.datesInUnknownTimezone;let a=s&&r.includes("create"),n=s&&r.includes("delete"),p=s&&r.includes("update");const l=r.includes("changetracking"),u=t.advancedQueryCapabilities;return s&&!(a||n||p)&&(a=n=p=!0),{supportsCalculate:Be(t,"supportsCalculate",!1),supportsTruncate:Be(t,"supportsTruncate",!1),supportsValidateSql:Be(t,"supportsValidateSql",!1),supportsAdd:a,supportsDelete:n,supportsEditing:s,supportsChangeTracking:l,supportsQuery:o,supportsQueryAnalytics:Be(u,"supportsQueryAnalytic",!1),supportsQueryAttachments:Be(u,"supportsQueryAttachments",!1),supportsQueryTopFeatures:Be(u,"supportsTopFeaturesQuery",!1),supportsResizeAttachments:Be(t,"supportsAttachmentsResizing",!1),supportsSync:r.includes("sync"),supportsUpdate:p,supportsExceedsLimitStatistics:Be(t,"supportsExceedsLimitStatistics",!1)}}_readQueryCapabilities(e){const t=e.advancedQueryCapabilities,r=e.ownershipBasedAccessControlForFeatures,i=e.archivingInfo,o=this.url?.includes("MapServer"),s=!h("mapserver-pbf-enabled")&&o&&this.version<10.81,a=re(this.url),n=(e.supportedQueryFormats||"").split(",").reduce(((e,t)=>{const r=t.toLowerCase().trim();return r&&e.add(r),e}),new Set);return{supportsStatistics:Be(t,"supportsStatistics",e.supportsStatistics),supportsPercentileStatistics:Be(t,"supportsPercentileStatistics",!1),supportsSpatialAggregationStatistics:Be(t,"supportsSpatialAggregationStatistics",!1),supportedSpatialAggregationStatistics:Ne(t),supportsCentroid:Be(t,"supportsReturningGeometryCentroid",!1),supportsDistance:Be(t,"supportsQueryWithDistance",!1),supportsDistinct:Be(t,"supportsDistinct",e.supportsAdvancedQueries),supportsExtent:Be(t,"supportsReturningQueryExtent",!1),supportsGeometryProperties:Be(t,"supportsReturningGeometryProperties",!1),supportsHavingClause:Be(t,"supportsHavingClause",!1),supportsOrderBy:Be(t,"supportsOrderBy",e.supportsAdvancedQueries),supportsPagination:Be(t,"supportsPagination",!1),supportsQuantization:Be(e,"supportsCoordinatesQuantization",!1),supportsQuantizationEditMode:Be(e,"supportsQuantizationEditMode",!1),supportsQueryGeometry:Be(e,"supportsReturningQueryGeometry",!1),supportsResultType:Be(t,"supportsQueryWithResultType",!1),supportsMaxRecordCountFactor:Be(t,"supportsMaxRecordCountFactor",!1),supportsSqlExpression:Be(t,"supportsSqlExpression",!1),supportsStandardizedQueriesOnly:Be(e,"useStandardizedQueries",!1),supportsTopFeaturesQuery:Be(t,"supportsTopFeaturesQuery",!1),supportsQueryByOthers:Be(r,"allowOthersToQuery",!0),supportsHistoricMoment:Be(i,"supportsQueryWithHistoricMoment",!1),supportsFormatPBF:!s&&n.has("pbf"),supportsDisjointSpatialRelationship:Be(t,"supportsDisjointSpatialRel",!1),supportsCacheHint:Be(t,"supportsQueryWithCacheHint",!1)||We(t,"query"),supportsDefaultSpatialReference:Be(t,"supportsDefaultSR",!1),supportsCompactGeometry:a,maxRecordCountFactor:ke(e,"maxRecordCountFactor",void 0),maxRecordCount:ke(e,"maxRecordCount",void 0),standardMaxRecordCount:ke(e,"standardMaxRecordCount",void 0),tileMaxRecordCount:ke(e,"tileMaxRecordCount",void 0)}}_readQueryRelatedCapabilities(e){const t=e.advancedQueryCapabilities,r=Be(t,"supportsAdvancedQueryRelated",!1);return{supportsPagination:Be(t,"supportsQueryRelatedPagination",!1),supportsCount:r,supportsOrderBy:r,supportsCacheHint:We(t,"queryRelated")}}_readQueryTopFeaturesCapabilities(e){return{supportsCacheHint:We(e.advancedQueryCapabilities,"queryTopFilter")}}_readEditingCapabilities(e){const t=e.ownershipBasedAccessControlForFeatures;return{supportsGeometryUpdate:Be(e,"allowGeometryUpdates",!0),supportsGlobalId:Be(e,"supportsApplyEditsWithGlobalIds",!1),supportsReturnServiceEditsInSourceSpatialReference:Be(e,"supportsReturnServiceEditsInSourceSR",!1),supportsRollbackOnFailure:Be(e,"supportsRollbackOnFailureParameter",!1),supportsUpdateWithoutM:Be(e,"allowUpdateWithoutMValues",!1),supportsUploadWithItemId:Be(e,"supportsAttachmentsByUploadId",!1),supportsDeleteByAnonymous:Be(t,"allowAnonymousToDelete",!0),supportsDeleteByOthers:Be(t,"allowOthersToDelete",!0),supportsUpdateByAnonymous:Be(t,"allowAnonymousToUpdate",!0),supportsUpdateByOthers:Be(t,"allowOthersToUpdate",!0)}}};e([D({readOnly:!0,json:{read:!1}})],Ze.prototype,"capabilities",void 0),e([A("service","capabilities",["advancedQueryCapabilities","allowGeometryUpdates","allowUpdateWithoutMValues","archivingInfo","capabilities","datesInUnknownTimezone","hasAttachments","hasM","hasZ","maxRecordCount","maxRecordCountFactor","ownershipBasedAccessControlForFeatures","standardMaxRecordCount","supportedQueryFormats","supportsAdvancedQueries","supportsApplyEditsWithGlobalIds","supportsAttachmentsByUploadId","supportsAttachmentsResizing","supportsCalculate","supportsCoordinatesQuantization","supportsExceedsLimitStatistics","supportsFieldDescriptionProperty","supportsQuantizationEditMode","supportsRollbackOnFailureParameter","supportsStatistics","supportsTruncate","supportsValidateSql","tileMaxRecordCount","useStandardizedQueries"])],Ze.prototype,"readCapabilities",null),e([D({json:{origins:{"portal-item":{write:!0},"web-map":{write:!0}}}})],Ze.prototype,"charts",void 0),e([D({readOnly:!0})],Ze.prototype,"createQueryVersion",null),e([D({type:String,json:{read:{source:"layerDefinition.copyrightText"},origins:{service:{read:{source:"copyrightText"}}}}})],Ze.prototype,"copyright",void 0),e([D({type:Boolean})],Ze.prototype,"datesInUnknownTimezone",void 0),e([D({type:String,json:{read:{source:"layerDefinition.displayField"},origins:{service:{read:{source:"displayField"}}}}})],Ze.prototype,"displayField",void 0),e([D({type:String,json:{origins:{service:{read:!1,write:!1}},name:"layerDefinition.definitionExpression",write:{enabled:!0,allowNull:!0}}})],Ze.prototype,"definitionExpression",void 0),e([D({types:p,readOnly:!0})],Ze.prototype,"defaultSymbol",void 0),e([D({type:De})],Ze.prototype,"dynamicDataSource",void 0),e([D({readOnly:!0})],Ze.prototype,"editFieldsInfo",void 0),e([D({type:Boolean})],Ze.prototype,"editingEnabled",null),e([A(["portal-item","web-scene"],"editingEnabled",["layerDefinition.capabilities"])],Ze.prototype,"readEditingEnabled",null),e([A("web-map","editingEnabled",["capabilities","layerDefinition.capabilities"])],Ze.prototype,"readEditingEnabledFromWebMap",null),e([L(["portal-item","web-scene"],"editingEnabled",{"layerDefinition.capabilities":{type:String}})],Ze.prototype,"writeEditingEnabled",null),e([L("web-map","editingEnabled",{capabilities:{type:String},"layerDefinition.capabilities":{type:String}})],Ze.prototype,"writeEditingEnabledToWebMap",null),e([D({readOnly:!0})],Ze.prototype,"editingInfo",void 0),e([A("editingInfo")],Ze.prototype,"readEditingInfo",null),e([D((()=>{const e=f(ue),t=e.json.origins;return t["web-map"]={read:!1,write:!1},t["portal-item"]={read:!1,write:!1},e})())],Ze.prototype,"elevationInfo",void 0),e([D(me)],Ze.prototype,"featureReduction",void 0),e([D({...He.fields,json:{read:{source:"layerDefinition.fields"},origins:{service:{name:"fields"},"web-map":{write:{target:"layerDefinition.fields",overridePolicy:Je}}}}})],Ze.prototype,"fields",void 0),e([D(He.fieldsIndex)],Ze.prototype,"fieldsIndex",void 0),e([D({type:je,json:{read:{source:"layerDefinition.floorInfo"},write:{target:"layerDefinition.floorInfo"}}})],Ze.prototype,"floorInfo",void 0),e([D({type:_,json:{name:"formInfo",write:!0,origins:{"web-scene":{read:!1,write:!1}}}})],Ze.prototype,"formTemplate",void 0),e([D({type:O,json:{origins:{service:{read:{source:"extent"}}},read:{source:"layerDefinition.extent"}}})],Ze.prototype,"fullExtent",void 0),e([D()],Ze.prototype,"gdbVersion",void 0),e([D({readOnly:!0,type:Se,json:{read:{source:"geometryProperties"}}})],Ze.prototype,"geometryFieldsInfo",void 0),e([D({type:["point","polygon","polyline","multipoint","multipatch","mesh"],json:{origins:{service:{read:qe.read},"web-map":{write:{target:"layerDefinition.geometryType",overridePolicy:Je,writer(e,t,r){const i=e?qe.toJSON(e):null;i&&S(r,i,t)}}}},read:{source:"layerDefinition.geometryType",reader:qe.read}}})],Ze.prototype,"geometryType",void 0),e([D({type:Boolean,json:{origins:{service:{read:!0}},read:{source:"layerDefinition.hasM"}}})],Ze.prototype,"hasM",void 0),e([D({type:Boolean,json:{origins:{service:{read:!0}},read:{source:"layerDefinition.hasZ"}}})],Ze.prototype,"hasZ",void 0),e([D({readOnly:!0,type:P})],Ze.prototype,"heightModelInfo",void 0),e([D({type:Date})],Ze.prototype,"historicMoment",void 0),e([D(ie)],Ze.prototype,"id",void 0),e([D({readOnly:!0,json:{origins:{service:{read:!0}},read:!1}})],Ze.prototype,"infoFor3D",void 0),e([D({readOnly:!0,json:{origins:{"web-map":{write:{target:"layerDefinition.type"}}}}})],Ze.prototype,"isTable",void 0),e([A("service","isTable",["type","geometryType"]),A("isTable",["layerDefinition.type","layerDefinition.geometryType"])],Ze.prototype,"readIsTable",null),e([L("web-map","isTable")],Ze.prototype,"writeIsTable",null),e([D(oe)],Ze.prototype,"labelsVisible",void 0),e([D({type:[Fe],json:{origins:{service:{read:{source:"drawingInfo.labelingInfo",reader:Ie},write:{target:"drawingInfo.labelingInfo",enabled:!1}}},read:{source:"layerDefinition.drawingInfo.labelingInfo",reader:Ie},write:{target:"layerDefinition.drawingInfo.labelingInfo"}}})],Ze.prototype,"labelingInfo",void 0),e([D((()=>{const e=f(de);return e.json.origins["portal-item"]={write:{target:"layerDefinition.drawingInfo.transparency",writer(e,t,r){S(r,Pe(e),t)}}},e})())],Ze.prototype,"opacity",void 0),e([D({type:Number,json:{origins:{service:{read:{source:"id"}},"portal-item":{read:!1,write:{target:"id"}}},read:!1}})],Ze.prototype,"layerId",void 0),e([D(se)],Ze.prototype,"legendEnabled",void 0),e([D({type:["show","hide"],json:(()=>{const e=f(ce.json);return e.origins["portal-item"]={read:!1,write:!1},e})()})],Ze.prototype,"listMode",void 0),e([D(ae)],Ze.prototype,"minScale",void 0),e([A("service","minScale",["minScale","effectiveMinScale"])],Ze.prototype,"readMinScale",null),e([D(ne)],Ze.prototype,"maxScale",void 0),e([A("service","maxScale",["maxScale","effectiveMaxScale"])],Ze.prototype,"readMaxScale",null),e([D({type:String})],Ze.prototype,"globalIdField",void 0),e([A("globalIdField",["layerDefinition.globalIdField","layerDefinition.fields"]),A("service","globalIdField",["globalIdField","fields"])],Ze.prototype,"readGlobalIdFieldFromService",null),e([D({type:String,json:{origins:{"web-map":{write:{target:"layerDefinition.objectIdField",overridePolicy:Je}}}}})],Ze.prototype,"objectIdField",void 0),e([A("objectIdField",["layerDefinition.objectIdField","layerDefinition.fields"]),A("service","objectIdField",["objectIdField","fields"])],Ze.prototype,"readObjectIdFieldFromService",null),e([D({value:"ArcGISFeatureLayer",type:["ArcGISFeatureLayer"]})],Ze.prototype,"operationalLayerType",void 0),e([D(He.outFields)],Ze.prototype,"outFields",void 0),e([D({readOnly:!0})],Ze.prototype,"parsedUrl",null),e([D({type:String,json:{origins:{"web-scene":{read:!0,write:!0}},read:!1}})],Ze.prototype,"path",void 0),e([D(pe)],Ze.prototype,"popupEnabled",void 0),e([D({type:t,json:{name:"popupInfo",write:!0}})],Ze.prototype,"popupTemplate",void 0),e([D({readOnly:!0})],Ze.prototype,"defaultPopupTemplate",null),e([D({type:[Te],readOnly:!0})],Ze.prototype,"relationships",void 0),e([D({types:s,json:{origins:{service:{write:{target:"drawingInfo.renderer",enabled:!1}},"web-scene":{types:a,name:"layerDefinition.drawingInfo.renderer",write:{overridePolicy:(e,t,r)=>({ignoreOrigin:r?.writeLayerSchema})}}},write:{target:"layerDefinition.drawingInfo.renderer",overridePolicy:(e,t,r)=>({ignoreOrigin:r?.writeLayerSchema})}}})],Ze.prototype,"renderer",null),e([A("service","renderer",["drawingInfo.renderer","defaultSymbol"]),A("renderer",["layerDefinition.drawingInfo.renderer","layerDefinition.defaultSymbol"])],Ze.prototype,"readRenderer",null),e([D()],Ze.prototype,"sourceJSON",void 0),e([D({type:Boolean})],Ze.prototype,"returnM",void 0),e([D({type:Boolean})],Ze.prototype,"returnZ",void 0),e([D((()=>{const e=f(ye);return e.json.origins["portal-item"]={read:!1,write:!1},e})())],Ze.prototype,"screenSizePerspectiveEnabled",void 0),e([D({clonable:!1})],Ze.prototype,"source",null),e([C("source")],Ze.prototype,"castSource",null),e([A("portal-item","source",["featureSet"]),A("web-map","source",["featureSet"])],Ze.prototype,"readSource",null),e([D({readOnly:!0})],Ze.prototype,"serviceDefinitionExpression",void 0),e([A("service","serviceDefinitionExpression",["definitionQuery","definitionExpression"])],Ze.prototype,"readServiceDefinitionExpression",null),e([D({type:q,json:{origins:{service:{read:{source:"extent.spatialReference"}}},read:{source:"layerDefinition.extent.spatialReference"}}})],Ze.prototype,"spatialReference",void 0),e([D({type:Number})],Ze.prototype,"subtypeCode",void 0),e([D({type:String,json:{origins:{service:{read:!0}}}})],Ze.prototype,"subtypeField",void 0),e([D({type:[fe]})],Ze.prototype,"templates",void 0),e([A("templates",["editFieldsInfo","creatorField","editorField","templates"])],Ze.prototype,"readTemplates",null),e([D({type:Ee})],Ze.prototype,"timeInfo",void 0),e([D()],Ze.prototype,"title",void 0),e([A("service","title",["name"]),A("portal-item","title",["layerDefinition.title","layerDefinition.name","title"])],Ze.prototype,"readTitle",null),e([A("web-map","title",["layerDefinition.name","title"])],Ze.prototype,"readTitleFromWebMap",null),e([D({type:String})],Ze.prototype,"sublayerTitleMode",void 0),e([D({type:String,json:{read:{source:"timeInfo.trackIdField"}}})],Ze.prototype,"trackIdField",void 0),e([D({json:{read:!1}})],Ze.prototype,"type",void 0),e([D({type:String})],Ze.prototype,"typeIdField",void 0),e([A("service","typeIdField"),A("typeIdField",["layerDefinition.typeIdField"])],Ze.prototype,"readTypeIdField",null),e([D({type:[be]})],Ze.prototype,"types",void 0),e([A("service","types",["types"]),A("types",["layerDefinition.types"])],Ze.prototype,"readTypes",null),e([D({readOnly:!0,json:{write:!1}})],Ze.prototype,"serverGens",void 0),e([D({type:d.ofType(he),readOnly:!0})],Ze.prototype,"indexes",void 0),e([D(le)],Ze.prototype,"url",null),e([L("url")],Ze.prototype,"writeUrl",null),e([D({readOnly:!0})],Ze.prototype,"userIsAdmin",void 0),e([D({json:{origins:{service:{read:!0}},read:!1}})],Ze.prototype,"version",void 0),e([A("service","version",["currentVersion","capabilities","drawingInfo","hasAttachments","htmlPopupType","relationships","timeInfo","typeIdField","types"])],Ze.prototype,"readVersion",null),e([D({type:Boolean,json:{origins:{"portal-item":{write:{target:"layerDefinition.defaultVisibility"}}}}})],Ze.prototype,"visible",void 0),e([A("portal-item","visible",["visibility","layerDefinition.defaultVisibility"])],Ze.prototype,"readVisible",null),Ze=e([M("esri.layers.FeatureLayer")],Ze);const $e=R({types:l}),Ke=Ze;export{Ke as default};