/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{__decorate as e}from"tslib";import r from"../request.js";import t from"../core/Error.js";import{releaseMaybe as i}from"../core/maybe.js";import{MultiOriginJSONMixin as o}from"../core/MultiOriginJSONSupport.js";import{throwIfAbortError as s,throwIfAborted as a}from"../core/promiseUtils.js";import{objectToQuery as p}from"../core/urlUtils.js";import{property as l,subclass as n}from"../core/accessorSupport/decorators.js";import c from"../geometry/HeightModelInfo.js";import d from"./Layer.js";import{ArcGISCachedService as y}from"./mixins/ArcGISCachedService.js";import{ArcGISService as h}from"./mixins/ArcGISService.js";import{OperationalLayer as m}from"./mixins/OperationalLayer.js";import{PortalLayer as u}from"./mixins/PortalLayer.js";import{url as v}from"./support/commonProperties.js";import f from"./support/ElevationTileData.js";import{acquireDecoder as g}from"./support/LercDecoder.js";import{reader as S}from"../core/accessorSupport/decorators/reader.js";let w=class extends(y(h(m(u(o(d)))))){constructor(...e){super(...e),this.capabilities={operations:{supportsTileMap:!1}},this.copyright=null,this.heightModelInfo=null,this.path=null,this.minScale=void 0,this.maxScale=void 0,this.opacity=1,this.operationalLayerType="ArcGISTiledElevationServiceLayer",this.sourceJSON=null,this.type="elevation",this.url=null,this.version=null,this._lercDecoder=g()}normalizeCtorArgs(e,r){return"string"==typeof e?{url:e,...r}:e}destroy(){this._lercDecoder=i(this._lercDecoder)}readCapabilities(e,r){const t=r.capabilities&&r.capabilities.split(",").map(e=>e.toLowerCase().trim());if(!t)return{operations:{supportsTileMap:!1}};return{operations:{supportsTileMap:t.includes("tilemap")}}}readVersion(e,r){let t=r.currentVersion;return t||(t=9.3),t}load(e){const r=null!=e?e.signal:null;return this.addResolvingPromise(this.loadFromPortal({supportedTypes:["Image Service"],supportsData:!1,validateItem:e=>{if(e.typeKeywords)for(let r=0;r<e.typeKeywords.length;r++)if("elevation 3d layer"===e.typeKeywords[r].toLowerCase())return!0;throw new t("portal:invalid-layer-item-type","Invalid layer item type '${type}', expected '${expectedType}' ",{type:"Image Service",expectedType:"Image Service Elevation 3D Layer"})}},e).catch(s).then(()=>this._fetchImageService(r))),Promise.resolve(this)}fetchTile(e,t,i,o){const s=o?.signal,a={responseType:"array-buffer",signal:s},p={noDataValue:o?.noDataValue,returnFileInfo:!0};return this.load().then(()=>this._fetchTileAvailability(e,t,i,o)).then(()=>r(this.getTileUrl(e,t,i),a)).then(e=>this._lercDecoder.decode(e.data,p,s)).then(e=>new f(e))}getTileUrl(e,r,t){const i=!this.capabilities.operations.supportsTileMap&&this.supportsBlankTile,o=p({...this.parsedUrl.query,blankTile:!i&&null});return`${this.parsedUrl.path}/tile/${e}/${r}/${t}${o?"?"+o:""}`}async queryElevation(e,r){const{query:t}=await import("./support/ElevationQuery.js");return a(r),t(this,e,r)}async createElevationSampler(e,r){const{createSampler:t}=await import("./support/ElevationQuery.js");return a(r),t(this,e,r)}_fetchTileAvailability(e,r,t,i){return this.tilemapCache?this.tilemapCache.fetchAvailability(e,r,t,i):Promise.resolve("unknown")}async _fetchImageService(e){if(this.sourceJSON)return this.sourceJSON;const t={query:{f:"json",...this.parsedUrl.query},responseType:"json",signal:e},i=await r(this.parsedUrl.path,t);i.ssl&&(this.url=this.url?.replace(/^http:/i,"https:")),this.sourceJSON=i.data,this.read(i.data,{origin:"service",url:this.parsedUrl})}get hasOverriddenFetchTile(){return!this.fetchTile[j]}};e([l({readOnly:!0})],w.prototype,"capabilities",void 0),e([S("service","capabilities",["capabilities"])],w.prototype,"readCapabilities",null),e([l({json:{read:{source:"copyrightText"}}})],w.prototype,"copyright",void 0),e([l({readOnly:!0,type:c})],w.prototype,"heightModelInfo",void 0),e([l({type:String,json:{origins:{"web-scene":{read:!0,write:!0}},read:!1}})],w.prototype,"path",void 0),e([l({type:["show","hide"]})],w.prototype,"listMode",void 0),e([l({json:{read:!1,write:!1,origins:{service:{read:!1,write:!1},"portal-item":{read:!1,write:!1},"web-document":{read:!1,write:!1}}},readOnly:!0})],w.prototype,"minScale",void 0),e([l({json:{read:!1,write:!1,origins:{service:{read:!1,write:!1},"portal-item":{read:!1,write:!1},"web-document":{read:!1,write:!1}}},readOnly:!0})],w.prototype,"maxScale",void 0),e([l({json:{read:!1,write:!1,origins:{"web-document":{read:!1,write:!1}}}})],w.prototype,"opacity",void 0),e([l({type:["ArcGISTiledElevationServiceLayer"]})],w.prototype,"operationalLayerType",void 0),e([l()],w.prototype,"sourceJSON",void 0),e([l({json:{read:!1},value:"elevation",readOnly:!0})],w.prototype,"type",void 0),e([l(v)],w.prototype,"url",void 0),e([l()],w.prototype,"version",void 0),e([S("version",["currentVersion"])],w.prototype,"readVersion",null),w=e([n("esri.layers.ElevationLayer")],w);const j=Symbol("default-fetch-tile");w.prototype.fetchTile[j]=!0;const T=w;export{T as default};
