12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.24/esri/copyright.txt for details.
- */
- import{_ as e}from"../../chunks/tslib.es6.js";import{typeCast as t}from"../../core/compilerUtils.js";import a from"../../core/Evented.js";import{isSome as s}from"../../core/maybe.js";import{watch as i,whenOnce as r,initial as o}from"../../core/reactiveUtils.js";import{property as n}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/has.js";import{cast as p}from"../../core/accessorSupport/decorators/cast.js";import{subclass as l}from"../../core/accessorSupport/decorators/subclass.js";import{isLoaded as c,canProjectWithoutEngine as m,load as h}from"../../geometry/projection.js";import{equals as f}from"../../geometry/support/spatialReferenceUtils.js";import{esriBasemapDefinitions as u}from"../../support/basemapDefinitions.js";import{ensureType as d,destroyCache as g,findSpatialReference as v,getWellKnownBasemapId as b}from"../../support/basemapUtils.js";let B=class extends a.EventedAccessor{constructor(e){super(e),this._basemapCache={},this._loadingProjectionEngine=!1,this.nextBasemap=d("hybrid",this._basemapCache),this.view=null,this.toggle=this.toggle.bind(this)}initialize(){i((()=>this.nextBasemap),(e=>{e&&!e.loaded&&e.load().catch((()=>{}))}),o)}destroy(){this.view=null,g(this._basemapCache),this._basemapCache=null}get _nextBasemapSpatialReferenceTask(){return v(this.view,this.nextBasemap)}get _viewSpatialReferenceLocked(){return!("spatialReferenceLocked"in this.view)||this.view.spatialReferenceLocked}get activeBasemap(){return d(this.view?.map?.basemap??"topo",this._basemapCache)}castNextBasemap(e){return d(e,this._basemapCache)}get state(){const{view:e}=this;if(!e?.ready)return"disabled";if(this._nextBasemapSpatialReferenceTask.updating)return"disabled";const{spatialReference:t}=this._nextBasemapSpatialReferenceTask;return this._viewSpatialReferenceLocked&&s(t)&&!e.spatialReference.equals(t)?"incompatible-next-basemap":this._loadingProjectionEngine?"loading":"ready"}async toggle(){if("disabled"===this.state||"incompatible-next-basemap"===this.state)return;const{activeBasemap:e,nextBasemap:t}=this,a=this._viewSpatialReferenceLocked;if(!a){if(await r((()=>!this._nextBasemapSpatialReferenceTask.updating)),t!==this.nextBasemap||e!==this.activeBasemap)return;const{spatialReference:a}=this._nextBasemapSpatialReferenceTask;if(!s(a)||f(this.view.spatialReference,a)||c()||m(this.view.spatialReference,a)||(this._loadingProjectionEngine=!0,await h(),this._loadingProjectionEngine=!1),t!==this.nextBasemap||e!==this.activeBasemap)return}this.view.map.basemap=t,a||!s(this._nextBasemapSpatialReferenceTask.spatialReference)||f(this.view.spatialReference,this._nextBasemapSpatialReferenceTask.spatialReference)||(this.view.spatialReference=this._nextBasemapSpatialReferenceTask.spatialReference),this.nextBasemap=e,this.emit("toggle",{previous:e,current:t})}static getThumbnailUrl(e){if(!e)return null;const{thumbnailUrl:a}=e;if(a)return a;const s=b(e);if(s)return u[s].thumbnailUrl;const i=e.baseLayers.find((e=>!!t(e)().get("portalItem.thumbnailUrl")));return i?t(i)().get("portalItem.thumbnailUrl"):null}};e([n()],B.prototype,"_loadingProjectionEngine",void 0),e([n({readOnly:!0})],B.prototype,"_nextBasemapSpatialReferenceTask",null),e([n({readOnly:!0})],B.prototype,"_viewSpatialReferenceLocked",null),e([n({readOnly:!0})],B.prototype,"activeBasemap",null),e([n()],B.prototype,"nextBasemap",void 0),e([p("nextBasemap")],B.prototype,"castNextBasemap",null),e([n({readOnly:!0})],B.prototype,"state",null),e([n()],B.prototype,"view",void 0),e([n()],B.prototype,"toggle",null),B=e([l("esri.widgets.BasemapToggle.BasemapToggleViewModel")],B);const R=B;export{R as default};
|