/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../../core/Collection.js";import i from"../../../core/Logger.js";import{throwIfAborted as r}from"../../../core/promiseUtils.js";import{whenOnce as s}from"../../../core/reactiveUtils.js";import{property as o,subclass as l}from"../../../core/accessorSupport/decorators.js";import{getTileMaxtrixSetFromActiveLayer as a}from"../../../layers/support/layerUtils.js";import{LayerView3D as n}from"./LayerView3D.js";import{TiledLayerView3D as h}from"./TiledLayerView3D.js";import m from"../../layers/LayerView.js";import{RefreshableLayerView as f}from"../../layers/RefreshableLayerView.js";let d=class extends(f(h(n(m)))){constructor(){super(...arguments),this.type="wmts-3d"}initialize(){this._getCompatibleTileInfoMatrixSet(e=>this._getTileInfoSupportError(e.tileInfo,e.fullExtent));const e=s(()=>this.view?.basemapTerrain?.tilingSchemeLocked).then(()=>{const e=this._getCompatibleTileInfoMatrixSet(e=>this._getTileInfoError(e.tileInfo,e.fullExtent));null!=e&&(null!==e.id&&this.layer.activeLayer.tileMatrixSetId!==e.id&&(this.layer.activeLayer.tileMatrixSetId=e.id),e.tileInfo&&(this.tileInfo=e.tileInfo),this.layer.fullExtent=e.fullExtent)});this.addResolvingPromise(e),this.when(()=>this._postInitialize())}refresh(){this.emit("data-changed")}canResume(){if(!super.canResume())return!1;const e=this.layer.activeLayer.tileMatrixSet;return null!=e&&!this._getTileInfoError(e.tileInfo,e.fullExtent)}async fetchTile([e,t,i],s){const o=await this.layer.fetchImageBitmapTile(e,t,i,{...s,allowDeriveTypeFromData:!0,imageOrientation:"flipY"});return r(s),o}async doRefresh(){this.suspended||this.emit("data-changed")}_postInitialize(){this._updatingHandles.add(()=>this.layer?.activeLayer?.styleId,()=>this.refresh()),this._updatingHandles.add(()=>this.layer?.activeLayer,e=>{const t=this._getCompatibleTileInfoMatrixSet(e=>this._getTileInfoError(e.tileInfo,e.fullExtent),!0);t&&null!=t.id&&e.tileMatrixSetId!==t.id&&(this.layer.activeLayer.tileMatrixSetId=t.id),this.notifyChange("suspended"),this.canResume()&&this.refresh()})}_getCompatibleTileInfoMatrixSet(e,r=!1){const s=a(this.layer);if(null!=s){if(t.isCollection(s)){const t=s.find(t=>{const s=e(t);return null!=s&&(r?i.getLogger(this).error("The selected tile matrix set is not compatible with the view",s):this.addResolvingPromise(Promise.reject(s))),null==s});return t}const o=e(s);return null!=o&&(r?i.getLogger(this).error("The selected tile matrix set is not compatible with the view",o):this.addResolvingPromise(Promise.reject(o))),s}return null}_getTileInfoError(e,t){return this._getTileInfoSupportError(e,t)||this._getTileInfoCompatibilityError(e,this.view.basemapTerrain.tilingScheme)}};e([o()],d.prototype,"layer",void 0),e([o()],d.prototype,"suspended",void 0),e([o()],d.prototype,"tileInfo",void 0),d=e([l("esri.views.3d.layers.WMTSLayerView3D")],d);const p=d;export{p as default};
