/*
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/maybe","../../../core/promiseUtils","../../../core/reactiveUtils","../../../core/Logger","../../../core/accessorSupport/ensureType","../../../core/arrayUtils","../../../core/has","../../../core/accessorSupport/set","../../../core/accessorSupport/decorators/subclass","./DynamicLayerView3D","../../layers/ImageryLayerView"],(function(e,t,i,a,r,n,s,o,l,c,u,d,h){"use strict";let p=function(t){function n(){var i;return(i=t.apply(this,arguments)||this).type="imagery-3d",i.redrawDebounced=a.debounce(function(){var t=e._asyncToGenerator((function*(e){i.redraw(((e,t)=>i._redrawImage(e,t)),e)}));return function(e){return t.apply(this,arguments)}}(),2e3),i}e._inheritsLoose(n,t);var s=n.prototype;return s.initialize=function(){this.handles.add([r.when((()=>this.view.basemapTerrain.ready),(()=>this._initializeMaximumDataResolution()),{once:!0,initial:!0}),this.layer.on("redraw",(()=>this.updatingHandles.addPromise(this.redrawDebounced())))]),this.updatingHandles.add((()=>{var e,t;return null==(e=this.layer)||null==(t=e.exportImageServiceParameters)?void 0:t.version}),(()=>{this.updatingHandles.addPromise(this.refreshDebounced())})),this.updatingHandles.add((()=>this.timeExtent),(()=>this.updatingHandles.addPromise(this.refreshDebounced())))},s._initializeMaximumDataResolution=function(){const e=this.view.basemapTerrain.spatialReference,t=this.layer.fullExtent;!t||e.equals(t.spatialReference),this.maximumDataResolution={x:this.layer.pixelSizeX,y:this.layer.pixelSizeY}},s.getFetchOptions=function(){return{timeExtent:this.timeExtent}},s.processResult=function(){var t=e._asyncToGenerator((function*(e,t,i){t.imageElement?e.image=t.imageElement:(e.image=document.createElement("canvas"),e.pixelData=t.pixelData,yield this._redrawImage(e,i))}));function i(e,i,a){return t.apply(this,arguments)}return i}(),s._redrawImage=function(){var t=e._asyncToGenerator((function*(e,t){if(!(e.image instanceof HTMLCanvasElement)||i.isNone(e.pixelData))throw new Error;const a=e.image,r=a.getContext("2d"),n=yield this.layer.applyRenderer(e.pixelData,{signal:t}),s=this.layer.applyFilter(n).pixelBlock;if(i.isNone(s))throw new Error;a.width=s.width,a.height=s.height;const o=r.createImageData(s.width,s.height);o.data.set(s.getAsRGBA()),r.putImageData(o,0,0)}));function a(e,i){return t.apply(this,arguments)}return a}(),n}(h(d));p=t.__decorate([u.subclass("esri.views.3d.layers.ImageryLayerView3D")],p);return p}));
