UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 3.53 kB
import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../core/Accessor.js";import i from"../../../core/Handles.js";import{destroyMaybe as s,isSome as r}from"../../../core/maybe.js";import{watch as o}from"../../../core/reactiveUtils.js";import{property as n}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import"../../../core/arrayUtils.js";import{subclass as l}from"../../../core/accessorSupport/decorators/subclass.js";import{canProjectToWGS84ComparableLonLat as a}from"../../../geometry/projection.js";import{equals as c}from"../../../geometry/support/aaBoundingRect.js";import{isMars as h,isMoon as p}from"../../../geometry/support/spatialReferenceUtils.js";import{isTiledLayer as d}from"../../../layers/support/layerUtils.js";import{ViewingMode as m}from"../../ViewingMode.js";import{isProjectableRasterLayer as y,getTiledLayerInfo as u}from"./terrainUtils.js";import{TilingScheme as S}from"./TilingScheme.js";let g=class extends t{constructor(e){super(e),this._handles=new i}initialize(){this._handles.add(this.layers.on("change",(()=>this._update()))),this._handles.add(o((()=>this.extentHelper.layerViewsExtent),(()=>this._setAdHocTilingScheme()))),this._update(),this.tilingSchemeLocked||this._setAdHocTilingScheme()}destroy(){this._handles=s(this._handles),this._waitTask=null}_update(){if(this._waitTask=null,this.tilingSchemeLocked)return;let e;if(this.layers.some((t=>!(!d(t)||t.isRejected())&&(!(t.isFulfilled()&&!f(t,this.viewSpatialReference,this.viewingMode))&&(e=t,!("vector-tile"===t?.type||y(t)))))),e)if(e.isResolved()){const t=u(e,this.viewSpatialReference,this.viewingMode);if(r(t)){const e=new S(t.tileInfo);this._lockTilingScheme(e)}}else this._updateWhen(e)}_updateWhen(e){const t=e.when().catch((()=>{})).then((()=>{t!==this._waitTask||this.destroyed||this._update()}));this._waitTask=t}_lockTilingScheme(e){if(this.viewingMode===m.Global){const t=e.levels.length-1;e.spatialReference.isWebMercator?e=S.makeWebMercatorAuxiliarySphere(t):a(e.spatialReference)&&(e=S.makeGCSWithTileSize(e.spatialReference,e.pixelSize,t))}this.tilingSchemeLocked=!0,this.tilingScheme=e,this.extentHelper.tilingScheme=this.tilingScheme,this._updateTiledLayerExtent(),this._handles.removeAll(),this._handles.add(o((()=>this.extentHelper.tiledLayersExtent),(()=>this._updateTiledLayerExtent())))}_updateTiledLayerExtent(){this._set("extent",this.extentHelper.tiledLayersExtent)}_setAdHocTilingScheme(){if(this.viewingMode===m.Global){const e=this.extentHelper.viewSpatialReference,t=a(e)||h(e)||p(e);e.isWebMercator?this.tilingScheme=S.WebMercatorAuxiliarySphere:t&&(this.tilingScheme=S.makeGCSWithTileSize(e,256)),this._set("extent",this.extentHelper.layerViewsExtent)}else{const e=this.extentHelper.layerViewsExtent;r(e)&&!c(e,this.extent)&&(this.tilingScheme=S.fromExtent(e,this.extentHelper.viewSpatialReference),this._set("extent",e))}}get test(){return{lockTilingScheme:e=>this._lockTilingScheme(e),done:!this._waitTask}}};function f(e,t,i){return r(u(e,t,i))}e([n()],g.prototype,"tilingScheme",void 0),e([n({readOnly:!0})],g.prototype,"extent",void 0),e([n({value:!1})],g.prototype,"tilingSchemeLocked",void 0),e([n({constructOnly:!0})],g.prototype,"viewSpatialReference",void 0),e([n({constructOnly:!0})],g.prototype,"layers",void 0),e([n({constructOnly:!0})],g.prototype,"extentHelper",void 0),e([n({constructOnly:!0})],g.prototype,"viewingMode",void 0),g=e([l("esri.views.3d.terrain.TilingSchemeLogic")],g);export{g as TilingSchemeLogic};