UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 4.61 kB
import e from"../../../../../request.js";import t from"../../../../../core/Error.js";import has from"../../../../../core/has.js";import r from"../../../../../core/Logger.js";import{isSome as s,unwrapOr as i,isNone as a}from"../../../../../core/maybe.js";import{throwIfAborted as o,isAbortError as n}from"../../../../../core/promiseUtils.js";import{createSourceAdapter as u}from"../controllers/support/sourceAdapters.js";import{DataTileSource as c}from"./DataTileSource.js";import{QueueProcessor as l}from"../../../../support/QueueProcessor.js";const p=4;class d extends c{constructor(e){super(e),this.type="feature",this.mode="on-demand",this._adapter=u(e.serviceInfo),this._queue=new l({concurrency:8,process:async e=>{if(o(e),s(e.tile)){const t=e.tile.key.id,{signal:r}=e,s=has("esri-tiles-debug")?{tile:t.replace(/\//g,"."),depth:e.depth}:void 0,i=await this._adapter.executeQuery(e.query,{signal:r,query:{...s,...this._schema?.customParameters}});return i.level=e.tile.key.level,i}return this._adapter.executeQuery(e.query,{...e,query:this._schema?.customParameters})}}),this._patchQueue=new l({concurrency:8,process:async e=>{if(o(e),s(e.tile)){const t=e.tile.key.id,{signal:r}=e,s=has("esri-tiles-debug")?{tile:t.replace(/\//g,"."),depth:e.depth}:void 0,i=await this._adapter.executeQuery(e.query,{signal:r,query:{...s,...this._schema?.customParameters}});return i.level=e.tile.key.level,i}return this._adapter.executeQuery(e.query,{...e,query:this._schema?.customParameters})}})}destroy(){super.destroy(),this._adapter.destroy(),this._queue.destroy(),this._patchQueue.destroy()}get updating(){return!!this._queue.length||Array.from(this._subscriptions.values()).some((e=>!e.done))}get maxRecordCountFactor(){const{query:e}=this._serviceInfo.capabilities;return e.supportsMaxRecordCountFactor?p:null}get maxPageSize(){const{query:e}=this._serviceInfo.capabilities;return(e.maxRecordCount??8e3)*i(this.maxRecordCountFactor,1)}get pageSize(){return Math.min(8e3,this.maxPageSize)}enableEvent(e,t){}subscribe(e,s){super.subscribe(e,s);const i=this._subscriptions.get(e.id);this._fetchDataTile(e).catch((s=>{n(s)||r.getLogger("esri.views.2d.layers.features.sources.BaseFeatureSource").error(new t("mapview-query-error","Encountered error when fetching tile",{tile:e,error:s}))})).then((()=>i.end()))}unsubscribe(e){super.unsubscribe(e)}readers(e){return this._subscriptions.get(e).readers()}async query(e,t={}){const r=t.query??{};return this._adapter.executeQuery(e,{...t,query:{...r,...this._schema?.customParameters}})}async queryLastEditDate(){const t=this._serviceInfo.source,r={...t.query,f:"json"};return(await e(t.path,{query:r,responseType:"json"})).data.editingInfo.lastEditDate}createTileQuery(e,t={}){const r=this._serviceInfo.geometryType,s=this.createQuery(t);s.quantizationParameters=t.quantizationParameters??e.getQuantizationParameters(),s.resultType="tile",s.geometry=e.extent,this._serviceInfo.capabilities.query.supportsQuantization?"esriGeometryPolyline"===r&&(s.maxAllowableOffset=e.resolution*has("feature-polyline-generalization-factor")):"esriGeometryPolyline"!==r&&"esriGeometryPolygon"!==r||(s.maxAllowableOffset=e.resolution,"esriGeometryPolyline"===r&&(s.maxAllowableOffset*=has("feature-polyline-generalization-factor")));const i=this._serviceInfo.capabilities.query;return s.defaultSpatialReferenceEnabled=i.supportsDefaultSpatialReference,s.compactGeometryEnabled=i.supportsCompactGeometry,s}async _executePatchQuery(e,t,r,i){const a=t.clone();a.outFields=[this._serviceInfo.objectIdField,...r],a.returnCentroid=!1,a.returnGeometry=!1;const o=s(a.start)?a.start/8e3:0,n=i.signal;return this._patchQueue.push({tile:e,query:a,signal:n,depth:o})}async _resend(e,t){const{query:r,message:i}=e,n=s(r.outFields)?r.outFields:[],u=this._queryInfo.outFields,c=u.filter((e=>!n.includes(e)));if(a(i.addOrUpdate))this._onMessage({...i,type:"append"});else if(c.length)try{const e=this._subscriptions.get(i.id).tile,s=await this._executePatchQuery(e,r,c,t);o(t),r.outFields=u,i.addOrUpdate.joinAttributes(s),this._onMessage({...i,end:i.end,type:"append"})}catch(l){}else this._onMessage({...i,type:"append"})}async _resendSubscription(e){if(has("esri-2d-update-debug")&&console.debug(e.tile.id,"Resend Subscription"),e.empty)return this._onMessage({id:e.tile.id,addOrUpdate:null,end:!1,type:"append"});const t=e.signal;for(const r of e.requests.done)await this._resend(r,{signal:t});return s(e.edits)?this._onMessage(e.edits):void 0}async resend(){const e=Array.from(this._subscriptions.values());await Promise.all(e.map((e=>this._resendSubscription(e))))}}export{d as BaseFeatureSource};