@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.27 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 t}from"../../../chunks/tslib.es6.js";import a from"../../../Basemap.js";import s from"../../../core/Collection.js";import e from"../../../core/Error.js";import r from"../../../core/Loadable.js";import o from"../../../core/Logger.js";import i from"../../../core/Promise.js";import{isAbortError as l}from"../../../core/promiseUtils.js";import{watch as p,initial as n}from"../../../core/reactiveUtils.js";import{property as m}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/RandomLCG.js";import{subclass as h}from"../../../core/accessorSupport/decorators/subclass.js";import c from"../../../portal/Portal.js";import u from"./LocalBasemapsSource.js";const d=s.ofType(a);let y=class extends(r.LoadableMixin(i.EsriPromiseMixin(u))){constructor(t){super(t),this._lastPortalBasemapFetchController=null,this.basemaps=new d,this.filterFunction=null,this.portal=c.getDefault(),this.query=null,this.updateBasemapsCallback=null,this.viewType=null}initialize(){this.addHandles(p((()=>[this.filterFunction,this.loadStatus,this.portal?.basemapGalleryGroupQuery,this.portal?.basemapGalleryGroupQuery3D,this.portal?.user,this.query,this.updateBasemapsCallback]),(()=>this.refresh()),n))}destroy(){this.filterFunction=null,this.portal=null,this.basemaps.forEach((t=>t.destroy()))}get state(){return"not-loaded"===this.loadStatus?"not-loaded":"loading"===this.loadStatus||this._lastPortalBasemapFetchController?"loading":"ready"}load(t){return this.addResolvingPromise(this.portal.load(t)),Promise.resolve(this)}async refresh(){if("loaded"!==this.loadStatus)return;this._lastPortalBasemapFetchController&&(this._lastPortalBasemapFetchController.abort(),this._lastPortalBasemapFetchController=null);const t=this.portal,a=new AbortController;this._lastPortalBasemapFetchController=a,this.notifyChange("state");try{const s=await t.fetchBasemaps(this._toQueryString(this.query),{signal:a.signal,include3d:"3d"===this.viewType||void 0});await this._updateBasemaps(s)}catch(s){if(l(s))throw s;o.getLogger(this).warn(new e("basemap-source:fetch-basemaps-error","Could not fetch basemaps from portal.",{error:s})),await this._updateBasemaps()}this._lastPortalBasemapFetchController=null,this.notifyChange("state")}_toQueryString(t){return t&&"string"!=typeof t?Object.keys(t).map((a=>`${a}:${t[a]}`)).join(" AND "):t}async _updateBasemaps(t=[]){let a=await this._filterBasemaps(t);a=this.updateBasemapsCallback?await this.updateBasemapsCallback(a):a,this.basemaps.removeAll(),this.basemaps.addMany(a)}async _filterBasemaps(t){if(!this.filterFunction)return t;const a=t.map(this.filterFunction),s=await Promise.all(a);return t.filter(((t,a)=>s[a]))}};t([m({readOnly:!0,type:d})],y.prototype,"basemaps",void 0),t([m()],y.prototype,"filterFunction",void 0),t([m({type:c})],y.prototype,"portal",void 0),t([m()],y.prototype,"query",void 0),t([m({readOnly:!0})],y.prototype,"state",null),t([m()],y.prototype,"updateBasemapsCallback",void 0),t([m()],y.prototype,"viewType",void 0),y=t([h("esri.widgets.BasemapGallery.support.PortalBasemapsSource")],y);const f=y;export{f as default};