View.js 11 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.24/esri/copyright.txt for details.
  4. */
  5. import{_ as e}from"../chunks/tslib.es6.js";import t from"../Map.js";import i from"../TimeExtent.js";import r from"../core/Accessor.js";import a from"../core/Collection.js";import s from"../core/CollectionFlattener.js";import o from"../core/Error.js";import n from"../core/Evented.js";import{HandleOwnerMixin as l}from"../core/HandleOwner.js";import{makeHandle as p}from"../core/handleUtils.js";import d from"../core/Loadable.js";import h from"../core/Logger.js";import{destroyMaybe as y,isSome as c,abortMaybe as u}from"../core/maybe.js";import{EsriPromiseMixin as m}from"../core/Promise.js";import{createTask as f,after as g}from"../core/promiseUtils.js";import{watch as w,whenOnce as v,when as M,sync as V}from"../core/reactiveUtils.js";import{aliasOf as R}from"../core/accessorSupport/decorators/aliasOf.js";import"../core/arrayUtils.js";import"../core/has.js";import"../core/accessorSupport/ensureType.js";import{property as _}from"../core/accessorSupport/decorators/property.js";import{subclass as S}from"../core/accessorSupport/decorators/subclass.js";import{owningCollectionProperty as j}from"../core/support/OwningCollection.js";import F from"../geometry/Extent.js";import O from"../geometry/HeightModelInfo.js";import L from"../geometry/SpatialReference.js";import{equals as E}from"../geometry/support/spatialReferenceUtils.js";import{AnalysesCollection as b}from"../support/AnalysesCollection.js";import{GraphicsCollection as C}from"../support/GraphicsCollection.js";import{BasemapView as x}from"./BasemapView.js";import I from"./LayerViewManager.js";import q from"./Magnifier.js";import D from"./ToolViewManager.js";import T from"./input/Input.js";import{ViewEvents as k}from"./input/ViewEvents.js";import z from"./navigation/Navigation.js";import{DefaultsFromMap as P}from"./support/DefaultsFromMap.js";var U;const W=h.getLogger("esri.views.View");let A=U=class extends(l(n.EventedMixin(m(r)))){constructor(e){super(e),this._userSpatialReference=null,this._cursor=null,this.allLayerViews=new s({getCollections:()=>[this.basemapView?.baseLayerViews,this.groundView?.layerViews,this.layerViews,this.basemapView?.referenceLayerViews],getChildrenFunction:e=>e.layerViews}),this.groundView=null,this.animation=null,this.basemapView=null,this.fatalError=null,this.extent=null,this.graphics=new C,this.analyses=new b,this.navigating=!1,this.typeSpecificPreconditionsReady=!0,this.layerViews=new a,this.magnifier=new q,this.padding={left:0,top:0,right:0,bottom:0},this.ready=!1,this.spatialReferenceWarningDelay=1e3,this.supportsGround=!0,this.timeExtent=null,this.type=null,this.scale=null,this.updating=!1,this.initialExtentRequired=!0,this.input=new T,this.navigation=new z,this.layerViewManager=null,this.analysisViewManager=null,this.isHeightModelInfoRequired=!1,this.width=null,this.height=null,this.resizing=!1,this.suspended=!1,this.viewEvents=new k(this),this.persistableViewModels=new a,this._isValid=!1,this._readyCycleForced=!1,this.handles.add(w((()=>this.preconditionsReady),(e=>{e?(this._currentSpatialReference=this.spatialReference,U.views.add(this)):(this._currentSpatialReference=null,U.views.remove(this)),this.notifyChange("spatialReference"),!e&&this.ready?(this.layerViewManager?.clear(),this.toolViewManager?.detach(),c(this.analysisViewManager)&&this.analysisViewManager.detach(),this._teardown()):e&&!this.ready&&(this._startup(),c(this.analysisViewManager)&&this.analysisViewManager.attach(),this.toolViewManager.attach())}),V))}initialize(){this.addResolvingPromise(this.validate().then((()=>(this._isValid=!0,v((()=>this.ready)))))),this.basemapView=new x({view:this}),this.layerViewManager=new I({view:this,layerViewImporter:{importLayerView:e=>this.importLayerView(e),hasLayerViewModule:e=>this.hasLayerViewModule(e)},supportsGround:this.supportsGround}),this.toolViewManager=new D({view:this}),this._setupSpatialReferenceLogger(),this.handles.add([w((()=>this.initialExtentRequired),(e=>this.defaultsFromMap.required={...this.defaultsFromMap.required,extent:e}),{sync:!0,initial:!0}),w((()=>this.ready),(e=>{this.defaultsFromMap&&(this.defaultsFromMap.suspended=e,this.defaultsFromMap.userSpatialReference=e?this.spatialReference:this._userSpatialReference)}),{sync:!0}),w((()=>this._userSpatialReference),(e=>{this.defaultsFromMap&&(this.defaultsFromMap.userSpatialReference=e)}),{sync:!0,initial:!0})])}_setupSpatialReferenceLogger(){let e=null;this.handles.add([w((()=>this.defaultsFromMap?.ready),(t=>{const i=this.map?.allLayers.length>0;if(t&&!this.spatialReference&&i){if(c(e))return;const t=p((()=>e=u(e)));e=f((async t=>{try{await g(this.spatialReferenceWarningDelay,null,t)}catch{return}finally{e=null}W.warn("#spatialReference","no spatial reference could be derived from the currently added map layers")})),this.handles.add(t,"spatial-reference-logger-task")}else this.handles.remove("spatial-reference-logger-task")}),{sync:!0})])}destroy(){if(this.destroyed)return;this.viewEvents.destroy(),this.allLayerViews.destroy(),this.navigation&&(this.navigation.destroy(),this._set("navigation",null)),this.graphics=y(this.graphics),this.analyses=y(this.analyses),this.handles.remove("defaultsFromMap"),this.defaultsFromMap.destroy(),this._set("defaultsFromMap",null),y(this.analysisViewManager),this.toolViewManager=y(this.toolViewManager),this.layerViewManager=y(this.layerViewManager),this.basemapView=y(this.basemapView),this.invalidate(),this._emitter.clear(),this.handles.removeAll();const e=this.map;this.map=null,e?.destroy()}_startup(){this._set("ready",!0)}_teardown(){this._set("ready",!1)}whenReady(){return Promise.resolve(this)}toMap(){return W.error("#toMap()","Not implemented on this instance of View"),null}get _defaultsFromMapSettings(){return{}}get defaultsFromMap(){return new P({required:{tileInfo:!1,heightModelInfo:!1,extent:!1},map:()=>this.map,getSpatialReferenceSupport:e=>this.getSpatialReferenceSupport(e),...this._defaultsFromMapSettings})}get heightModelInfo(){return this.getDefaultHeightModelInfo()}get interacting(){return this.navigating}get preconditionsReady(){return!(this.fatalError||!this._isValid||this._readyCycleForced||!this.map||d.isLoadable(this.map)&&!this.map.loaded||0===this.width||0===this.height||!this.spatialReference||!this._validateSpatialReference(this.spatialReference)||!this._currentSpatialReference&&!this.defaultsFromMap?.ready||!this.typeSpecificPreconditionsReady)}set map(e){e!==this._get("map")&&(e?.destroyed&&(W.warn("#map","The provided map is already destroyed",{map:e}),e=null),d.isLoadable(e)&&e.load().catch((()=>{})),this.initialized&&(this.forceReadyCycle(),this._currentSpatialReference=null),this._set("map",e))}get spatialReference(){let e=this._userSpatialReference||this._currentSpatialReference||this.getDefaultSpatialReference()||null;return e&&this.defaultsFromMap?.required?.heightModelInfo&&(e=e.clone(),e.vcsWkid=this.defaultsFromMap.vcsWkid,e.latestVcsWkid=this.defaultsFromMap.latestVcsWkid),e}set spatialReference(e){const t=!E(e,this._get("spatialReference"));this._set("_userSpatialReference",e),t&&(this._set("spatialReference",e),this._spatialReferenceChanged(e))}_spatialReferenceChanged(e){}get stationary(){return!this.animation&&!this.navigating&&!this.resizing}get initialExtent(){return this.defaultsFromMap?.extent}get cursor(){const e=this.toolViewManager?this.toolViewManager.cursor:null;return c(e)?e:this._cursor||"default"}set cursor(e){this._cursor=e,this.notifyChange("cursor")}get size(){return[this.width,this.height]}whenLayerView(e){return this.layerViewManager.whenLayerView(e)}getDefaultSpatialReference(){return this.defaultsFromMap?.spatialReference}getDefaultHeightModelInfo(){return(this.map&&"heightModelInfo"in this.map?this.map.heightModelInfo:void 0)??this.defaultsFromMap?.heightModelInfo??null}importLayerView(e){throw new o("importLayerView() not implemented")}hasLayerViewModule(e){return!1}async validate(){}invalidate(){this._isValid=!1}getSpatialReferenceSupport(){return{constraints:null}}_validateSpatialReference(e){return c(this.getSpatialReferenceSupport({spatialReference:e}))}when(e,t){return this.isResolved()&&!this.ready&&W.warn("#when()","Calling view.when() while the view is no longer ready but was already resolved once will resolve immediately. Use reactiveUtils.whenOnce(() => view.ready).then(...) instead."),super.when(e,t)}forceReadyCycle(){this.ready&&(M((()=>!1===this.preconditionsReady),(()=>this._readyCycleForced=!1),{once:!0}),this._readyCycleForced=!0)}addAndActivateTool(e){this.toolViewManager.tools.add(e),this.activeTool=e}tryFatalErrorRecovery(){this.fatalError=null}};A.views=new a,e([_()],A.prototype,"_userSpatialReference",void 0),e([R("toolViewManager.activeTool")],A.prototype,"activeTool",void 0),e([_({readOnly:!0})],A.prototype,"allLayerViews",void 0),e([_()],A.prototype,"groundView",void 0),e([_()],A.prototype,"animation",void 0),e([_()],A.prototype,"basemapView",void 0),e([_({readOnly:!0})],A.prototype,"_defaultsFromMapSettings",null),e([_()],A.prototype,"defaultsFromMap",null),e([_()],A.prototype,"fatalError",void 0),e([_({type:F})],A.prototype,"extent",void 0),e([_(j(C,"graphics"))],A.prototype,"graphics",void 0),e([_(j(b,"analyses"))],A.prototype,"analyses",void 0),e([_({readOnly:!0,type:O})],A.prototype,"heightModelInfo",null),e([_({readOnly:!0})],A.prototype,"interacting",null),e([_({readOnly:!0})],A.prototype,"navigating",void 0),e([_({readOnly:!0,dependsOn:["fatalError","_isValid","_readyCycleForced","map","map.loaded?","width","height","spatialReference","_currentSpatialReference","defaultsFromMap.ready","typeSpecificPreconditionsReady"]})],A.prototype,"preconditionsReady",null),e([_({readOnly:!0})],A.prototype,"typeSpecificPreconditionsReady",void 0),e([_({type:a,readOnly:!0})],A.prototype,"layerViews",void 0),e([_({type:q})],A.prototype,"magnifier",void 0),e([_({value:null,type:t})],A.prototype,"map",null),e([_()],A.prototype,"padding",void 0),e([_({readOnly:!0})],A.prototype,"ready",void 0),e([_({type:L})],A.prototype,"spatialReference",null),e([_()],A.prototype,"spatialReferenceWarningDelay",void 0),e([_()],A.prototype,"stationary",null),e([_({readOnly:!0})],A.prototype,"supportsGround",void 0),e([_({type:i})],A.prototype,"timeExtent",void 0),e([R("toolViewManager.tools")],A.prototype,"tools",void 0),e([_()],A.prototype,"toolViewManager",void 0),e([_({readOnly:!0})],A.prototype,"type",void 0),e([_({type:Number})],A.prototype,"scale",void 0),e([_({readOnly:!0})],A.prototype,"updating",void 0),e([_({readOnly:!0})],A.prototype,"initialExtentRequired",void 0),e([_({readOnly:!0})],A.prototype,"initialExtent",null),e([_()],A.prototype,"cursor",null),e([_({readOnly:!0})],A.prototype,"input",void 0),e([_({type:z,nonNullable:!0})],A.prototype,"navigation",void 0),e([_()],A.prototype,"layerViewManager",void 0),e([_()],A.prototype,"analysisViewManager",void 0),e([_()],A.prototype,"width",void 0),e([_()],A.prototype,"height",void 0),e([_({readOnly:!0})],A.prototype,"resizing",void 0),e([_({value:null,readOnly:!0})],A.prototype,"size",null),e([_({readOnly:!0})],A.prototype,"suspended",void 0),e([_({readOnly:!0})],A.prototype,"viewEvents",void 0),e([_({readOnly:!0})],A.prototype,"persistableViewModels",void 0),e([_()],A.prototype,"_isValid",void 0),e([_()],A.prototype,"_readyCycleForced",void 0),e([_()],A.prototype,"_currentSpatialReference",void 0),A=U=e([S("esri.views.View")],A);const G=A;export{G as default};