UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 9.14 kB
import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../core/Accessor.js";import{createTask as a}from"../../core/asyncUtils.js";import{abortMaybe as n,isSome as s,unwrap as i,isNone as r}from"../../core/maybe.js";import{isAborted as l}from"../../core/promiseUtils.js";import{property as o}from"../../core/accessorSupport/decorators/property.js";import"../../core/accessorSupport/ensureType.js";import"../../core/arrayUtils.js";import{subclass as p}from"../../core/accessorSupport/decorators/subclass.js";import{supportsHeightModelInfo as c,deriveHeightModelInfoFromLayer as u}from"../../geometry/support/heightModelInfoUtils.js";import{ViewingMode as d}from"../ViewingMode.js";import{projectWithEngineOrService as f}from"./projectionUtils.js";let h=class extends t{constructor(e){super(e),this.required={tileInfo:!1,heightModelInfo:!1,extent:!1},this.defaultSpatialReference=null,this.userSpatialReference=null,this.sourcePreloadCount=10,this.priorityCollection=null,this.requiresExtentInSpatialReference=!0,this.suspended=!1,this._projectExtentTask={task:null,input:null,output:null,spatialReference:null}}destroy(){this._projectExtentTask.task&&(this._projectExtentTask.task=n(this._projectExtentTask.task)),this._set("map",null)}get ready(){return!this._spatialReferenceTask.updating&&!this._tileInfoTask.updating&&!this._extentTask.updating}get heightModelInfoReady(){return!this._heightModelInfoTask.updating}get spatialReference(){return s(this.userSpatialReference)?this.userSpatialReference:i(this._spatialReferenceTask.spatialReference)}get extent(){return i(this._extentTask.extent)}get heightModelInfo(){return i(this._heightModelInfoTask.heightModelInfo)}get vcsWkid(){return i(this._heightModelInfoTask.vcsWkid)}get latestVcsWkid(){return i(this._heightModelInfoTask.latestVcsWkid)}get viewingMode(){return r(this.userSpatialReference)||this.userSpatialReference.equals(i(this._spatialReferenceTask.spatialReference))?i(this._spatialReferenceTask.viewingMode):null}get tileInfo(){return i(this._tileInfoTask.tileInfo)}get mapCollections(){const e=this.map?.(),t=[];return s(this.priorityCollection)&&t.push(this.priorityCollection),t.push({parent:e?.basemap,layers:e?.basemap?.baseLayers},{layers:e?.layers},{parent:e?.ground,layers:e?.ground?.layers},{parent:e?.basemap,layers:e?.basemap?.referenceLayers}),t}get _allLayers(){return this._collectLayers(this.mapCollections)}get _spatialReferenceTask(){if(this.suspended)return this._get("_spatialReferenceTask")??{updating:!1};const{layers:e,updating:t}=this._allLayers;let a=null;for(const i of e){const e=this._getSupportedSpatialReferences(i);if(e.length>0){const t=this._narrowDownSpatialReferenceCandidates(a,e);s(t)&&(a=t)}if(s(a)&&1===a.length)break}if(t&&(r(a)||1!==a.length))return{updating:!0};const n=this._pickSpatialReferenceCandidate(a);return{spatialReference:s(n)?n.spatialReference:null,viewingMode:s(n)?n.viewingMode:null,updating:!1}}get _tileInfoTask(){if(!this.required.tileInfo)return this._get("_tileInfoTask")??{updating:!1};if(!this.spatialReference)return{updating:this._spatialReferenceTask.updating};const{layers:e,updating:t}=this._collectLayers([{parent:this.map?.()?.basemap,layers:this.map?.()?.basemap?.baseLayers},{layers:this.map?.()?.layers}]);if(e&&e.length>0&&"tileInfo"in e[0]){const t=e[0].tileInfo;return{tileInfo:t&&t.spatialReference.equals(this.spatialReference)?t:null,updating:!1}}return{updating:t}}get _heightModelInfoTask(){if(!this.required.heightModelInfo||this.suspended&&this._get("_heightModelInfoTask")?.heightModelInfo)return this._get("_heightModelInfoTask")??{updating:!1};const{layers:e,updating:t}=this._allLayers;for(const a of e)if(c(a)){const e=u(a);if(e)return{heightModelInfo:e,vcsWkid:a.spatialReference?.vcsWkid,latestVcsWkid:a.spatialReference?.latestVcsWkid,updating:!1}}return{updating:t}}get _extentCandidatesTask(){if(this.suspended||!this.required.extent)return this._get("_extentCandidatesTask")??{updating:!1};if(!this.spatialReference)return{updating:this._spatialReferenceTask.updating};const e=this._allLayers,t=e.updating,a=[];for(const n of e.layers){const e="fullExtents"in n&&n.fullExtents||(s(n.fullExtent)?[n.fullExtent]:[]),t=this.requiresExtentInSpatialReference?null:e[0],i=e.find((e=>e.spatialReference.equals(this.spatialReference)))??t;if(i)return{candidates:[{extent:i,layer:n}],updating:!1};if(this._getSupportedSpatialReferences(n).length>0)for(const s of e)a.push({extent:s,layer:n})}return{candidates:a,updating:t}}get _extentTask(){const{candidates:e,updating:t}=this._extentCandidatesTask;if(t)return{updating:t};if(r(e)||0===e.length)return{updating:!1};if(!this.spatialReference)return{updating:this._spatialReferenceTask.updating};const i=this._pickExtentCandidate(e),o=this.spatialReference;return i.extent.equals(this._projectExtentTask.input)&&o.equals(this._projectExtentTask.spatialReference)?{extent:this._projectExtentTask.output,updating:s(this._projectExtentTask.task)&&!this._projectExtentTask.task.finished}:(s(this._projectExtentTask.task)&&(this._projectExtentTask.task=n(this._projectExtentTask.task)),this._projectExtentTask={input:i.extent.clone(),output:null,spatialReference:o.clone(),task:a((async e=>{try{const t=await f(i.extent,o,i.layer.portalItem,e);this._projectExtentTask={...this._projectExtentTask,task:null,output:t}}catch(t){if(l(e))return;this._projectExtentTask={...this._projectExtentTask,task:null}}}))},{updating:!0})}_narrowDownSpatialReferenceCandidates(e,t){if(r(e))return t;const a=[],n=(e,t)=>s(e)?s(t)?e===t&&e:e:t;for(const s of e)for(const e of t){if(!s.spatialReference.equals(e.spatialReference))continue;const t=n(s.viewingMode,e.viewingMode);if(!1!==t){a.push({spatialReference:s.spatialReference,viewingMode:t});break}}return a.length>0?a:null}_pickSpatialReferenceCandidate(e){const t=this.defaultSpatialReference;return r(e)||e.length<1?s(t)?{spatialReference:t,viewingMode:null}:null:(s(t)&&e.length>1&&e.some((({spatialReference:e})=>e.equals(t)))&&(e=e.filter((({spatialReference:e})=>e.equals(t)))),e.length>1&&e.some((({viewingMode:e})=>e!==d.Local))&&(e=e.filter((({viewingMode:e})=>e!==d.Local))),e[0])}_getSupportedSpatialReferences(e){const t="supportedSpatialReferences"in e&&e.supportedSpatialReferences||(e.spatialReference?[e.spatialReference]:[]);if(0===t.length)return[];const a=[];for(const n of t){const t=this.getSpatialReferenceSupport({spatialReference:n,layer:e});if(s(t)){const e=s(t.constraints)?t.constraints:[{spatialReference:n,viewingMode:null}];for(const{spatialReference:t,viewingMode:n}of e)(!this.requiresExtentInSpatialReference||r(this.userSpatialReference)||t.equals(this.userSpatialReference))&&a.push({spatialReference:t,viewingMode:n})}}return a}_pickExtentCandidate(e){const t=this.spatialReference;return e.find((({extent:e})=>t.equals(e.spatialReference)))||e[0]}_collectLayers(e){if("loaded"!==this._loadMaybe(this.map?.()))return{layers:[],updating:!0};const t={layers:[],preloading:-1,updating:!1};for(const a of e)if(this._collectCollection(a,t),t.preloading===this.sourcePreloadCount)break;return{layers:t.layers,updating:t.updating}}_collectCollection(e,t){if(e.layers){switch(this._loadMaybe(e.parent)){case"loading":return t.updating=!0,void++t.preloading;case"failed":return}for(const a of e.layers){switch(this._loadMaybe(a)){case"failed":continue;case"loading":t.updating=!0,++t.preloading;break;case"loaded":t.updating||t.layers.push(a),"layers"in a&&this._collectCollection({layers:a.layers},t)}if(t.preloading===this.sourcePreloadCount)break}}}_loadMaybe(e){return e&&"loadStatus"in e&&null!=e.loadStatus?"not-loaded"===e.loadStatus?(e.load().catch((()=>{})),"loading"):e.loadStatus:"loaded"}};e([o()],h.prototype,"required",void 0),e([o({constructOnly:!0})],h.prototype,"map",void 0),e([o({constructOnly:!0})],h.prototype,"getSpatialReferenceSupport",void 0),e([o()],h.prototype,"defaultSpatialReference",void 0),e([o()],h.prototype,"userSpatialReference",void 0),e([o()],h.prototype,"sourcePreloadCount",void 0),e([o()],h.prototype,"priorityCollection",void 0),e([o()],h.prototype,"requiresExtentInSpatialReference",void 0),e([o()],h.prototype,"suspended",void 0),e([o({readOnly:!0})],h.prototype,"ready",null),e([o({readOnly:!0})],h.prototype,"heightModelInfoReady",null),e([o({readOnly:!0})],h.prototype,"spatialReference",null),e([o({readOnly:!0})],h.prototype,"extent",null),e([o({readOnly:!0})],h.prototype,"heightModelInfo",null),e([o({readOnly:!0})],h.prototype,"vcsWkid",null),e([o({readOnly:!0})],h.prototype,"latestVcsWkid",null),e([o({readOnly:!0})],h.prototype,"viewingMode",null),e([o({readOnly:!0})],h.prototype,"tileInfo",null),e([o({readOnly:!0})],h.prototype,"mapCollections",null),e([o({readOnly:!0})],h.prototype,"_allLayers",null),e([o({readOnly:!0})],h.prototype,"_spatialReferenceTask",null),e([o({readOnly:!0})],h.prototype,"_tileInfoTask",null),e([o({readOnly:!0})],h.prototype,"_heightModelInfoTask",null),e([o({readOnly:!0})],h.prototype,"_extentCandidatesTask",null),e([o()],h.prototype,"_extentTask",null),e([o()],h.prototype,"_projectExtentTask",void 0),h=e([p("esri.views.support.DefaultsFromMap")],h);export{h as DefaultsFromMap};