@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 2.74 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{handlesGroup as t}from"../../../../../../core/handleUtils.js";import has from"../../../../../../core/has.js";import{getOrCreateMapValue as e}from"../../../../../../core/MapUtils.js";import{throwIfAborted as o,isAbortError as s,onAbort as r}from"../../../../../../core/promiseUtils.js";import{ATileLoadStrategy as a}from"./ATileLoadStrategy.js";import{PagedTileSourceChunk as i}from"./chunks/PagedTileSourceChunk.js";import{FeatureSetReaderJSON as n}from"../../support/FeatureSetReaderJSON.js";class l{constructor(e,o){this.subscription=e,this._pages=new Set,this._controller=new AbortController,this._done=!1,this._handles=t([r(e.signal,(()=>this._controller.abort())),r(o,(()=>this._controller.abort()))])}destroy(){this._controller.abort(),this._handles.remove()}get pageStart(){let t=-1;for(const e of this._pages.values())t=Math.max(t,e);return t+1}get done(){return this._done}get options(){return{signal:this._controller.signal}}add(t,e){this._pages.add(t),this._done=this._done||e}}class c extends a{constructor(){super(...arguments),this._loadStates=new Map}destroy(){super.destroy();for(const t of this._loadStates.values())t.destroy();this._loadStates.clear()}get about(){return{supportsDisplayFilter:!0,willQueryAllFeatures:!1,willQueryFullResolutionGeometry:!1}}async load(t){const o=e(this._loadStates,t.key.id,(()=>new l(t,this._options)));for await(const e of this._fetchPages(o))this._addChunk(e)}unload(t){super.unload(t),this._loadStates.get(t.key.id)?.destroy(),this._loadStates.delete(t.key.id)}async*_fetchPages(t){let e;try{for await(const e of this._concurrentPageStream(t))o(t.options),0!==e.size()&&(yield e)}catch(r){e=r}if(e&&s(e)||(yield new i(n.empty(this._metadata),null,t.subscription.tile,-1,!0)),e)throw e}async*_concurrentPageStream(t){const e=has("featurelayer-query-tile-concurrency"),o=this._pageStreamAll(t),s=[];let r=!1,a=1;for(;!r;){const t=[];for(;!r&&s.length<a;){const e=o.next();if(!e.value){r=!0;break}const a=e.value;a.then((t=>{t.reader.exceededTransferLimit||(r=!0)})).catch((t=>{r=!0})).finally((()=>{s.splice(s.indexOf(a),1)})),s.push(a),t.push(a)}for(const e of t)yield e;s.length&&await Promise.race(s),a<e&&(a+=1)}}*_pageStreamAll(t){const e=Math.ceil(has("featurelayer-query-tile-max-features")/this._queryInfo.pageSize);for(let o=0;o<e;o++)yield this._downloadPage(o,t)}async _downloadPage(t,e){o(e.options);const s=e.subscription.tile,r=this._queryInfo.createPagedTileQuery(s,t),a=await this._fetch(r,e.options,{chunkId:`${s.id}-${t}`});return o(e.options),new i(a,r.inner.toJSON(),s,t,!1)}}export{c as PagedTileLoadStrategy};