/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../../chunks/_rollupPluginBabelHelpers","../../../chunks/tslib.es6","../../../core/Error","../../../core/maybe","../../../core/reactiveUtils","../../../core/accessorSupport/decorators/property","../../../core/arrayUtils","../../../core/has","../../../core/accessorSupport/ensureType","../../../core/accessorSupport/decorators/subclass","./LayerView3D","./TiledLayerView3D","../terrain/RasterTile","../../layers/ImageryTileLayerView","../../layers/LayerView","../../layers/RefreshableLayerView","../../support/drapedUtils","../../webgl/capabilities"],(function(e,r,t,i,a,n,s,l,o,c,y,p,h,u,d,m,f,g){"use strict";let b=function(r){function n(){var e;return(e=r.apply(this,arguments)||this).type="imagery-tile-3d",e.isAlignedMapTile=!0,e}e._inheritsLoose(n,r);var s=n.prototype;return s.initialize=function(){this.layer.increaseRasterJobHandlerUsage(),null==this.fullExtent&&this.addResolvingPromise(Promise.reject(new t("layerview:spatial-reference-incompatible","The layer extent cannot be projected to the view's spatial reference",{layer:this.layer})));const e=a.whenOnce((()=>{var e,r;return null==(e=this.view)||null==(r=e.basemapTerrain)?void 0:r.tilingSchemeLocked})).then((()=>{const e=this.view.basemapTerrain.tilingScheme,{tileInfo:r}=this.layer,t=["png","png24","png32","jpg","mixed"].includes(r.format)&&e.compatibleWith(r);this.isAlignedMapTile=t;const i=t?r:e.toTileInfo();this.tileInfo=i,this.updatingHandles.add((()=>[this.layer.renderer,this.layer.interpolation,this.layer.bandIds,this.layer.multidimensionalDefinition]),(()=>this.refresh()))}));this.addResolvingPromise(e)},s.destroy=function(){this.layer.decreaseRasterJobHandlerUsage(),this.view=null},s._getfullExtent=function(){return this.projectFullExtent(this.view.basemapTerrain&&null!==this.view.basemapTerrain.spatialReference?this.view.basemapTerrain.spatialReference:this.view.spatialReference)},s.fetchTile=function(){var r=e._asyncToGenerator((function*(e,r,t,a){const n=this.tileInfo,s=this._canSymbolizeInWebGL(),l={tileInfo:n,requestRawData:s,signal:i.unwrap(a.signal),requestAsImageElement:this.isAlignedMapTile},o=yield this.layer.fetchTile(e,r,t,l);if(o instanceof HTMLImageElement)return o;let c=o&&o.pixelBlock;if(i.isNone(c))return this._blankTile;if(!s&&(c=yield this.layer.applyRenderer(o),i.isNone(c)))return this._blankTile;const y=new h.RasterTile([e,r,t],c,n.size[0],n.size[1]);return s?(y.symbolizerRenderer=this.layer.symbolizer.rendererJSON,y.symbolizerParameters=this.layer.symbolizer.generateWebGLParameters(this._getSymbolizerOptions(e)),y.transformGrid=o.transformGrid):y.isRendereredSource=!0,y.interpolation=this.layer.interpolation,y.bandIds=this.layer.bandIds,y}));function t(e,t,i,a){return r.apply(this,arguments)}return t}(),s._getSymbolizerOptions=function(e){const r=this.tileInfo.lodAt(e).resolution;return{pixelBlock:null,isGCS:this.view.basemapTerrain?this.view.basemapTerrain.spatialReference.isGeographic:this.view.spatialReference.isGeographic,resolution:{x:r,y:r},bandIds:this.layer.bandIds}},s.ensureSymbolizerParameters=function(e){this._canSymbolizeInWebGL()&&JSON.stringify(e.symbolizerRenderer)!==JSON.stringify(this.layer.symbolizer.rendererJSON)&&(e.symbolizerParameters=this.layer.symbolizer.generateWebGLParameters(this._getSymbolizerOptions(e.lij[0])))},s.createFetchPopupFeaturesQueryGeometry=function(e,r){return f.createQueryGeometry(e,r,this.view)},s.refresh=function(){this.emit("data-changed")},s.doRefresh=function(){var r=e._asyncToGenerator((function*(){this.suspended||this.emit("data-changed")}));function t(){return r.apply(this,arguments)}return t}(),s._canSymbolizeInWebGL=function(){return g.getWebGLCapabilities("3d").supportsTextureFloat&&this.layer.symbolizer.canRenderInWebGL},e._createClass(n,[{key:"_blankTile",get:function(){const e=document.createElement("canvas"),r=e.getContext("2d"),[t,i]=this.tileInfo.size;return e.width=t,e.height=i,r.clearRect(0,0,t,i),r.getImageData(0,0,t,i)}},{key:"imageFormatIsOpaque",get:function(){return"jpg"===this.layer.tileInfo.format}},{key:"hasMixedImageFormats",get:function(){return"mixed"===this.layer.tileInfo.format}},{key:"dataLevelRange",get:function(){const e=this.tileInfo.lods,r=this.layer.tileInfo.lods,t=e[0].scale,i=r[r.length-1].scale;return this.levelRangeFromScaleRange(t,i)}}]),n}(u(m(p.TiledLayerView3D(y.LayerView3D(d)))));r.__decorate([n.property({readOnly:!0})],b.prototype,"_blankTile",null),r.__decorate([n.property({readOnly:!0})],b.prototype,"imageFormatIsOpaque",null),r.__decorate([n.property({readOnly:!0})],b.prototype,"hasMixedImageFormats",null),r.__decorate([n.property({readOnly:!0})],b.prototype,"dataLevelRange",null),b=r.__decorate([c.subclass("esri.views.3d.layers.ImageryTileLayerView3D")],b);return b}));
