UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) • 17.2 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as e}from"tslib";import t from"../Map.js";import{createTask as i}from"../core/asyncUtils.js";import r from"../core/Collection.js";import s from"../core/CollectionFlattener.js";import{referenceSetter as a}from"../core/collectionUtils.js";import o from"../core/Error.js";import{EventedMixin as n}from"../core/Evented.js";import l from"../core/Handles.js";import{makeHandle as p}from"../core/handleUtils.js";import has from"../core/has.js";import{isLoadable as h}from"../core/Loadable.js";import d from"../core/Logger.js";import{destroyMaybe as y,abortMaybe as u}from"../core/maybe.js";import{EsriPromise as m}from"../core/Promise.js";import{after as c}from"../core/promiseUtils.js";import{watch as g,sync as f,whenOnce as w,when as v,syncAndInitial as _}from"../core/reactiveUtils.js";import{property as V,subclass as M}from"../core/accessorSupport/decorators.js";import{owningCollectionProperty as b}from"../core/support/OwningCollection.js";import{UpdatingHandles as R}from"../core/support/UpdatingHandles.js";import S from"../geometry/Extent.js";import T from"../geometry/HeightModelInfo.js";import j from"../geometry/SpatialReference.js";import{equals as E}from"../geometry/support/spatialReferenceUtils.js";import{AnalysesCollection as L}from"../support/AnalysesCollection.js";import{GraphicsCollection as x}from"../support/GraphicsCollection.js";import{system as F}from"../time/constants.js";import k from"../time/TimeExtent.js";import{isTimeZoneValid as O}from"../time/timeZoneUtils.js";import C from"./BasemapView.js";import H from"./Magnifier.js";import I from"./SelectionManager.js";import Z from"./Theme.js";import{ToolViewManager as W}from"./ToolViewManager.js";import{makeDefaultHighlightOptions as q}from"./3d/support/DefaultHighlights.js";import A from"./input/Input.js";import{ViewEvents as P}from"./input/ViewEvents.js";import D from"./navigation/Navigation.js";import{deduplicateAttributionItems as U}from"./support/attributionUtils.js";import{DefaultsFromMap as z}from"./support/DefaultsFromMap.js";import{defaultHighlightName as N}from"./support/HighlightDefaults.js";import G from"./support/HighlightOptions.js";import $ from"./support/LayerViewManager.js";import B from"./support/RequiredFieldsOptions.js";import{checkWebAssemblyRequirements as J}from"./support/WebAssemblyRequirements.js";import{checkWebGLRequirements as K}from"./support/WebGLRequirements.js";var Q;let X=class extends(n(m)){static{Q=this}constructor(e){super(e),this._userSpatialReference=null,this.handles=new l,this.updatingHandles=new R,this.allLayerViews=new s({getCollections:()=>this.layerviewCollections,getChildrenFunction:te}),this.animationsEnabled=!0,this.attributionVisible=!0,this.basemapView=null,this.dependencies={popup:void 0},this.displayFilterEnabled=!0,this.fatalError=null,this.graphics=new x,this.typeSpecificPreconditionsReady=!0,this.layerViews=new r,this.magnifier=new H,this.padding={left:0,top:0,right:0,bottom:0},this.ready=!1,this._readyStateWaitingTask=null,this.type=null,this.scale=null,this.updating=!1,this.initialExtentRequired=!0,this._lowPriorityCursorHandles=new r,this._highPriorityCursorHandles=new r,this.input=new A,this.navigation=new D,this.layerViewManager=null,this.analysisViewManager=null,this.isHeightModelInfoRequired=!1,this.width=null,this.height=null,this.resizing=!1,this.suspended=!1,this.viewEvents=new P(this),this.persistableViewModels=new r,this.requiredFieldsOptions=new B,this._isValid=!1,this._readyCycleForced=!1,this._lockedSpatialReference=null,this._userTimeZone=null,this._lockedTimeZone=null,this._userTimeExtent=null,this._lockedTimeExtent=null,this.theme=null,this.handles.add(g(()=>this.preconditionsReady,e=>{const t=this.ready;if(e?(this._lockedSpatialReference=this.spatialReference,this._lockedTimeZone=this.timeZone,this._lockedTimeExtent=this.timeExtent,Q.views.add(this)):(this._lockedSpatialReference=null,Q.views.remove(this)),this.notifyChange("spatialReference"),!e&&t)this.toolViewManager?.detach(),this.analysisViewManager?.detach(),this.layerViewManager?.clear(),this._teardown();else if(e&&!t){try{this._startup()}catch(i){return void queueMicrotask(()=>{this.fatalError=new o("view:startup-error","View._startup failed",i)})}this.analysisViewManager?.attach(),this.toolViewManager.attach()}},f)),this.analyses=new L}initialize(){this.addResolvingPromise(Promise.all([this.loadAsyncDependencies(),this.validate()]).then(()=>(this._isValid=!0,w(()=>this.ready)))),this.basemapView=new C({view:this}),this.layerViewManager=new $({view:this,layerViewFilter:e=>this.layerViewFilter?.(e)??!0,layerViewImporter:{importLayerView:e=>this.importLayerView(e),hasLayerViewModule:e=>this.hasLayerViewModule(e)},layerviewMapping:this._layerToLayerviewMapping}),this.toolViewManager=new W({view:this}),this.selectionManager=new I({view:this}),this.addHandles([v(()=>"map-content-error"===this.readyState&&!this.spatialReference,()=>{d.getLogger(this).warn("#spatialReference","no spatial reference could be derived from the currently added map layers")}),g(()=>this.initialExtentRequired,e=>this.defaultsFromMap.required={...this.defaultsFromMap.required,extent:e},_),g(()=>this.ready,e=>{this.defaultsFromMap&&(this.defaultsFromMap.suspended=e,this.defaultsFromMap.userSpatialReference=e?this.spatialReference:this._userSpatialReference)},f),g(()=>this._userSpatialReference,e=>{this.defaultsFromMap&&(this.defaultsFromMap.userSpatialReference=e)},_)])}get _layerToLayerviewMapping(){return Q._layerToLayerview}static{this._layerToLayerview=[["view.map.basemap.baseLayers","view.basemapView.baseLayerViews"],["view.map.basemap.groundLayers","view.basemapView.groundLayerViews"],["view.map.basemap.referenceLayers","view.basemapView.referenceLayerViews"],["view.map.layers","view.layerViews"]]}destroy(){this.destroyed||(Q.views.remove(this),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.defaultsFromMap.destroy(),this._set("defaultsFromMap",null),this.analysisViewManager=y(this.analysisViewManager),this.toolViewManager=y(this.toolViewManager),this.layerViewManager=y(this.layerViewManager),this.selectionManager=y(this.selectionManager),this.basemapView=y(this.basemapView),this.layerViews.destroyAll(),this.invalidate(),this.handles.destroy(),this.map=y(this.map),this.updatingHandles.destroy())}_startup(){this._set("ready",!0)}_teardown(){this._set("ready",!1)}whenReady(){return Promise.resolve(this)}toMap(){return d.getLogger(this).error("#toMap()","Not implemented on this instance of View"),null}get activeTool(){return this.toolViewManager?.activeTool}set activeTool(e){this.toolViewManager&&(this.toolViewManager.activeTool=e)}get layerviewCollections(){return[this.basemapView?.baseLayerViews,this.basemapView?.groundLayerViews,this.layerViews,this.basemapView?.referenceLayerViews]}get analyses(){return this._get("analyses")}set analyses(e){this._set("analyses",e)}get animation(){return this._get("animation")}set animation(e){this._set("animation",e)}get attributionItems(){return this.suspended?[]:U(this._get("attributionItems"),this.getAttributionItems())}get center(){return null}get defaultsFromMapSettings(){return{}}get defaultsFromMap(){return new z({required:{tileInfo:!1,heightModelInfo:!1,extent:!1},map:()=>this.map,getSpatialReferenceSupport:(e,t)=>this.getSpatialReferenceSupport(e,t),...this.defaultsFromMapSettings})}get extent(){return this._get("extent")}set extent(e){this._set("extent",e)}get heightModelInfo(){return this.getDefaultHeightModelInfo()}get highlights(){return this._get("highlights")??q()}set highlights(e){this._set("highlights",a(e,this._get("highlights"),r.ofType(G)))}get defaultHighlight(){return this.highlights.find(({name:e})=>e===N)}get interacting(){return this.navigating}get navigating(){return!1}get preconditionsReady(){if(this.destroying||this.destroyed)return!1;const{map:e,spatialReference:t}=this;return!(this.fatalError||!this._isValid||this._readyCycleForced||!e||h(e)&&!e.loaded||0===this.width||0===this.height||!t||!this._validateSpatialReference(t)||!this._lockedSpatialReference&&!this.defaultsFromMap?.ready||!this.typeSpecificPreconditionsReady)}get resolution(){return 0}set map(e){e!==this._get("map")&&(e?.destroyed&&(d.getLogger(this).warn("#map","The provided map is already destroyed",{map:e}),e=null),h(e)&&e.load().catch(()=>{}),this.constructed&&!this.destroyed&&(this.forceReadyCycle(),this._lockedSpatialReference=null),this._set("map",e))}get canZoomIn(){return!!this.ready}get canZoomOut(){return!!this.ready}get readyState(){if(this.destroyed)return this._get("readyState");if(!this.map)return"missing-map";if("container"in this&&!this.container)return"missing-container";if(this.fatalError)return"rendering-error";if((this.defaultsFromMap?.ready??!1)&&!this.spatialReference){const e=!("loaded"in this.map)||this.map.loaded,t=this.map.ground.loaded,r=this.map.basemap?.loaded??!0;return e&&r&&t&&!this.map?.allLayers.length?"empty-map":(this._readyStateWaitingTask||(this._readyStateWaitingTask=i(e=>c(has("view-readyState-waiting-delay"),null,e)),this.addHandles(this._readyStateWaitingTask),this.addHandles(this._readyStateWaitingTask,"ready-state-task")),this._readyStateWaitingTask?.finished?"map-content-error":"loading")}return this._readyStateWaitingTask=u(this._readyStateWaitingTask),this.removeHandles("ready-state-task"),this.ready?"ready":"loading"}get spatialReference(){const{_userSpatialReference:e}=this;if(e&&null!==e.vcsWkid)return e;const t=e||this._lockedSpatialReference||this.getDefaultSpatialReference()||null;if(t&&this.defaultsFromMap?.required?.heightModelInfo){const e=t.clone();return e.vcsWkid=this.defaultsFromMap.vcsWkid,e.latestVcsWkid=this.defaultsFromMap.latestVcsWkid,e}return t}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 timeExtent(){return this._userTimeExtent??this._lockedTimeExtent??this.getDefaultTimeExtent()??null}set timeExtent(e){this._userTimeExtent=e}get timeZone(){return this._userTimeZone??this._lockedTimeZone??this.getDefaultTimeZone()??F}set timeZone(e){this._userTimeZone=e,O(e)||d.getLogger(this).warn("#timeZone",`the parsed value '${e}' may not be a valid IANA time zone`)}get tools(){return this.toolViewManager?.tools}get initialExtent(){return this.defaultsFromMap?.extent}get cursor(){return this.toolViewManager?.cursor??this._highPriorityCursorHandles.at(-1)?.cursor??this._lowPriorityCursorHandles.at(-1)?.cursor??"default"}acquireCursor(e,t="low"){const i="high"===t?this._highPriorityCursorHandles:this._lowPriorityCursorHandles,r={cursor:e},s=p(()=>i.remove(r));return i.add(r),this.addHandles(s),s}get size(){return[this.width,this.height]}get effectiveTheme(){return this.theme??new Z}whenLayerView(e){return this.layerViewManager?.whenLayerView(e)??Promise.reject()}getAttributionItems(){return this.allLayerViews.items.flatMap(e=>e.attributionItems)}getDefaultSpatialReference(){return this.defaultsFromMap?.spatialReference}getDefaultHeightModelInfo(){return(this.map&&"heightModelInfo"in this.map?this.map.heightModelInfo:void 0)??this.defaultsFromMap?.heightModelInfo??null}getDefaultTimeZone(){return null}getDefaultTimeExtent(){return null}getSurface(){return null}importLayerView(e){throw new o("view:importLayerView-missing","importLayerView() not implemented")}hasLayerViewModule(e){return!1}async validate(){const e=K(this.type);if(e)throw this._displayWebGLError(),d.getLogger(this).warn("#validate()",e.message),e;const t=await J();if(t)throw d.getLogger(this).warn("#validate()",t.message),t}async loadAsyncDependencies(){}invalidate(){this._isValid=!1}getSpatialReferenceSupport(){return{constraints:null}}_validateSpatialReference(e){return null!=this.getSpatialReferenceSupport(e)}when(e,t){return this.isResolved()&&!this.ready&&d.getLogger(this).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&&(v(()=>this.destroyed||!1===this.preconditionsReady,()=>this._readyCycleForced=!1,{once:!0}),this._readyCycleForced=!0)}on(e,t){return super.on(e,t)}addAndActivateTool(e){this.toolViewManager.tools.add(e),this.activeTool=e}tryFatalErrorRecovery(){this.fatalError=null}static{this.views=new r}_displayWebGLError(){const e=document.createElement("div");e.setAttribute("style","display: flex; flex-direction: column; gap: 8px; padding: 20px; height: 100%; justify-content: center; color: black; background: white; font-family: sans-serif;");const t=document.createElement("div");t.innerHTML="Unable to display map. WebGL2 support is required.",t.setAttribute("style","font-size: 24px; font-weight: bold;");const i=document.createElement("div");i.innerHTML="Ensure that your browser and hardware meet the minimum requirements.",i.setAttribute("style","font-size: 18px;");const r=document.createElement("a");r.innerHTML="https://esriurl.com/webgl-faq",r.target="_blank",r.setAttribute("style","font-size: 18px;"),r.href="https://esriurl.com/webgl-faq",e.appendChild(t),e.appendChild(i),e.appendChild(r);const s=this.getSurface();s&&s.appendChild(e)}};e([V()],X.prototype,"_userSpatialReference",void 0),e([V()],X.prototype,"activeTool",null),e([V({readOnly:!0})],X.prototype,"allLayerViews",void 0),e([V({readOnly:!0})],X.prototype,"layerviewCollections",null),e([V(b(L,"analyses"))],X.prototype,"analyses",null),e([V()],X.prototype,"animation",null),e([V()],X.prototype,"animationsEnabled",void 0),e([V({readOnly:!0})],X.prototype,"attributionItems",null),e([V()],X.prototype,"attributionVisible",void 0),e([V()],X.prototype,"basemapView",void 0),e([V()],X.prototype,"center",null),e([V()],X.prototype,"defaultsFromMapSettings",null),e([V()],X.prototype,"defaultsFromMap",null),e([V()],X.prototype,"dependencies",void 0),e([V()],X.prototype,"displayFilterEnabled",void 0),e([V({type:S})],X.prototype,"extent",null),e([V()],X.prototype,"fatalError",void 0),e([V(b(x,"graphics"))],X.prototype,"graphics",void 0),e([V({readOnly:!0,type:T})],X.prototype,"heightModelInfo",null),e([V({type:r.ofType(G)})],X.prototype,"highlights",null),e([V({readOnly:!0})],X.prototype,"interacting",null),e([V({constructOnly:!0})],X.prototype,"layerViewFilter",void 0),e([V({readOnly:!0})],X.prototype,"navigating",null),e([V({readOnly:!0})],X.prototype,"preconditionsReady",null),e([V({readOnly:!0})],X.prototype,"typeSpecificPreconditionsReady",void 0),e([V({type:r,readOnly:!0})],X.prototype,"layerViews",void 0),e([V()],X.prototype,"resolution",null),e([V({type:H})],X.prototype,"magnifier",void 0),e([V({value:null,type:t})],X.prototype,"map",null),e([V()],X.prototype,"padding",void 0),e([V({readOnly:!0})],X.prototype,"ready",void 0),e([V({readOnly:!0})],X.prototype,"canZoomIn",null),e([V({readOnly:!0})],X.prototype,"canZoomOut",null),e([V()],X.prototype,"_readyStateWaitingTask",void 0),e([V({readOnly:!0})],X.prototype,"readyState",null),e([V({type:j})],X.prototype,"spatialReference",null),e([V()],X.prototype,"stationary",null),e([V({type:k})],X.prototype,"timeExtent",null),e([V({type:String,nonNullable:!0})],X.prototype,"timeZone",null),e([V()],X.prototype,"tools",null),e([V()],X.prototype,"toolViewManager",void 0),e([V({readOnly:!0})],X.prototype,"type",void 0),e([V({type:Number})],X.prototype,"scale",void 0),e([V({readOnly:!0})],X.prototype,"updating",void 0),e([V({readOnly:!0})],X.prototype,"initialExtentRequired",void 0),e([V({readOnly:!0})],X.prototype,"initialExtent",null),e([V()],X.prototype,"cursor",null),e([V({readOnly:!0})],X.prototype,"input",void 0),e([V({type:D,nonNullable:!0})],X.prototype,"navigation",void 0),e([V()],X.prototype,"layerViewManager",void 0),e([V()],X.prototype,"analysisViewManager",void 0),e([V()],X.prototype,"selectionManager",void 0),e([V()],X.prototype,"width",void 0),e([V()],X.prototype,"height",void 0),e([V({readOnly:!0})],X.prototype,"resizing",void 0),e([V({value:null,readOnly:!0})],X.prototype,"size",null),e([V({readOnly:!0})],X.prototype,"suspended",void 0),e([V({readOnly:!0})],X.prototype,"viewEvents",void 0),e([V({readOnly:!0})],X.prototype,"persistableViewModels",void 0),e([V()],X.prototype,"_isValid",void 0),e([V()],X.prototype,"_readyCycleForced",void 0),e([V()],X.prototype,"_lockedSpatialReference",void 0),e([V()],X.prototype,"_userTimeZone",void 0),e([V()],X.prototype,"_lockedTimeZone",void 0),e([V()],X.prototype,"_userTimeExtent",void 0),e([V()],X.prototype,"_lockedTimeExtent",void 0),e([V({type:Z})],X.prototype,"theme",void 0),e([V({readOnly:!0,type:Z})],X.prototype,"effectiveTheme",null),X=Q=e([M("esri.views.View")],X);const Y=globalThis.$arcgis;Y&&!Y.views&&Object.defineProperty(Y,"views",{configurable:!1,enumerable:!0,writable:!1,value:X.views});const ee=X;function te(e){return e.layerViews}export{ee as default};