UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) 5.13 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */ import{__decorate as e}from"tslib";import t from"../../../core/Error.js";import has from"../../../core/has.js";import{Loadable as r}from"../../../core/Loadable.js";import a from"../../../core/Logger.js";import{debounce as o,eachAlways as s}from"../../../core/promiseUtils.js";import{open as i}from"../../../core/workers.js";import{property as n,subclass as l}from"../../../core/accessorSupport/decorators.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=o(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:a,name:o,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:a,...e}));const g=["fields","geometryType","name","namespaceUri","swapXY"].some(e=>null==this.layer[e]),S=g?await y(this.wfsCapabilities,o,s,{spatialReference:w,customParameters:a,signal:e?.signal}):{...f(i??[]),geometryType:n,name:o,namespaceUri:s,spatialReference:w,swapXY:m},F=h(this.wfsCapabilities.readFeatureTypes(),S.name,S.namespaceUri),x=c.toJSON(S.geometryType),{operations:O}=this.wfsCapabilities,C=O.GetFeature.url,_=O.GetFeature.outputFormat;return{customParameters:a,featureType:F,fields:S.fields?.map(e=>e.toJSON())??[],geometryField:S.geometryField,geometryType:x,getFeatureUrl:C,getFeatureOutputFormat:_,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})]),o=t.error||r.error||null,n=r.value||null;if(o)throw n&&n.close(),o;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)a.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};