@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 5.34 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../core/Error.js";import has from"../../../core/has.js";import r from"../../../core/Loadable.js";import o from"../../../core/Logger.js";import{debounce as a,eachAlways as s}from"../../../core/promiseUtils.js";import{open as i}from"../../../core/workers/workers.js";import{property as n}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/RandomLCG.js";import{subclass as l}from"../../../core/accessorSupport/decorators/subclass.js";import u from"../../../geometry/Extent.js";import{featureGeometryTypeKebabDictionary as c}from"../../../geometry/support/typeUtils.js";import{createCapabilities as p,createDrawingInfo as m}from"./support/clientSideDefaults.js";import{getCapabilities as d,getWFSLayerInfo as y,prepareWFSLayerFields as f,findFeatureType as h}from"../../ogc/wfsUtils.js";import w from"../../../rest/support/AttributeBinsFeatureSet.js";import g from"../../../rest/support/FeatureSet.js";import{utc as S}from"../../../time/constants.js";let F=class extends r{constructor(){super(...arguments),this._connection=null,this._workerHandler=null,this.capabilities=p(!1,!1),this.type="wfs",this.refresh=a((async()=>{await this.load();const e={customParameters:this.layer.customParameters,maxRecordCount:this.layer.maxRecordCount,maxTotalRecordCount:this.layer.maxTotalRecordCount,maxPageCount:this.layer.maxPageCount},{extent:t}=await this._workerHandler.refresh(e);return t&&(this.sourceJSON.extent=t),{dataChanged:!0,updates:{extent:this.sourceJSON.extent}}}))}load(e){const t=null!=e?e.signal:null;return this.addResolvingPromise(this._startWorker({signal:t})),Promise.resolve(this)}destroy(){this._connection?.close(),this._connection=null,this._workerHandler=null}async openPorts(){return await this.load(),this._connection.openPorts()}async queryFeatures(e,t={}){const r=await this.queryFeaturesJSON(e,t);return g.fromJSON(r)}async queryFeaturesJSON(e,t={}){return await this.load(t),this._workerHandler.queryFeatures(e?e.toJSON():void 0,t)}async queryFeatureCount(e,t={}){return await this.load(t),this._workerHandler.queryFeatureCount(e?e.toJSON():void 0,t)}async queryObjectIds(e,t={}){return await this.load(t),this._workerHandler.queryObjectIds(e?e.toJSON():void 0,t)}async queryExtent(e,t={}){await this.load(t);const r=await this._workerHandler.queryExtent(e?e.toJSON():void 0,t);return{count:r.count,extent:u.fromJSON(r.extent)}}async querySnapping(e,t={}){return await this.load(t),this._workerHandler.querySnapping(e,t)}async queryAttributeBins(e,t={}){await this.load(t);const r=await this._workerHandler.queryAttributeBins(e?.toJSON(),t);return w.fromJSON(r)}async _createLoadOptions(e){const{url:r,customParameters:o,name:a,namespaceUri:s,fields:i,geometryType:n,maxRecordCount:l,maxPageCount:u,maxTotalRecordCount:p,swapXY:m}=this.layer,w="defaults"===this.layer.originOf("spatialReference")?void 0:this.layer.spatialReference;if(!r)throw new t("wfs-layer:missing-url","WFSLayer must be created with a url");this.wfsCapabilities||(this.wfsCapabilities=await d(r,{customParameters:o,...e}));const g=["fields","geometryType","name","namespaceUri","swapXY"].some((e=>null==this.layer[e])),S=g?await y(this.wfsCapabilities,a,s,{spatialReference:w,customParameters:o,signal:e?.signal}):{...f(i??[]),geometryType:n,name:a,namespaceUri:s,spatialReference:w,swapXY:m},F=h(this.wfsCapabilities.readFeatureTypes(),S.name,S.namespaceUri),x=c.toJSON(S.geometryType),{operations:O}=this.wfsCapabilities,j=O.GetFeature.url,C=O.GetFeature.outputFormat;return{customParameters:o,featureType:F,fields:S.fields?.map((e=>e.toJSON()))??[],geometryField:S.geometryField,geometryType:x,getFeatureUrl:j,getFeatureOutputFormat:C,maxRecordCount:l,maxPageCount:u,maxTotalRecordCount:p,objectIdField:S.objectIdField,spatialReference:S.spatialReference?.toJSON(),swapXY:!!S.swapXY}}async _startWorker(e){const[t,r]=await s([this._createLoadOptions(e),i("WFSSourceWorker",{...e,strategy:has("feature-layers-workers")?"dedicated":"local",registryTarget:this})]),a=t.error||r.error||null,n=r.value||null;if(a)throw n&&n.close(),a;const l=t.value;this._connection=r.value,this._workerHandler=this._connection.createInvokeProxy();const u=await this._workerHandler.load(l,e);for(const s of u.warnings)o.getLogger(this.layer).warn("#load()",`${s.message} (title: '${this.layer.title||"no title"}', id: '${this.layer.id??"no id"}')`,{warning:s});this.sourceJSON={dateFieldsTimeReference:{timeZoneIANA:S},extent:u.extent,fields:l.fields,geometryType:l.geometryType,objectIdField:l.objectIdField,geometryField:l.geometryField,drawingInfo:m(l.geometryType),name:l.featureType.title,wfsInfo:{name:l.featureType.name,featureUrl:l.getFeatureUrl,maxFeatures:l.maxRecordCount,swapXY:l.swapXY,supportedSpatialReferences:l.featureType.supportedSpatialReferences,version:"2.0.0",wfsNamespace:l.featureType.namespaceUri}}}};e([n()],F.prototype,"capabilities",void 0),e([n({constructOnly:!0})],F.prototype,"layer",void 0),e([n()],F.prototype,"sourceJSON",void 0),e([n()],F.prototype,"type",void 0),e([n()],F.prototype,"wfsCapabilities",void 0),F=e([l("esri.layers.graphics.sources.WFSSource")],F);export{F as WFSSource};