/*
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","../../../Graphic","../../../core/Logger","../../../core/promiseUtils","../../../core/reactiveUtils","../../../core/accessorSupport/decorators/property","../../../core/arrayUtils","../../../core/has","../../../core/accessorSupport/ensureType","../../../core/accessorSupport/decorators/subclass","../engine/flow/FlowView2D","./LayerView2D","./imagery/ImageryTileView2D","./imagery/VectorFieldTileView2D","./support/util","../../layers/ImageryTileLayerView","../../layers/LayerView","../../layers/RefreshableLayerView"],(function(e,t,i,r,s,n,a,o,u,c,h,l,d,v,p,w,y,b,f){"use strict";const g=r.getLogger("esri.views.2d.layers.ImageryTileLayerView2D");let _=function(t){function r(){var e;return(e=t.apply(this,arguments)||this)._useWebGLForProcessing=!0,e._useProgressiveUpdate=!0,e.subview=null,e}e._inheritsLoose(r,t);var a=r.prototype;return a.update=function(e){this.subview.update(e),this.notifyChange("updating")},a.isUpdating=function(){return!this.subview||this.subview.updating},a.attach=function(){this.layer.increaseRasterJobHandlerUsage(),this._updateSubview(),this.handles.add([n.watch((()=>{const{layer:e}=this;return{bandIds:e.bandIds,renderer:e.renderer,interpolation:e.interpolation,multidimensionalDefinition:e.multidimensionalDefinition}}),((e,t)=>{var i,r;const n=e.interpolation!==t.interpolation&&("majority"===e.interpolation||"majority"===t.interpolation)&&w.canUseMajorityInterpolationOnDataSource(this.layer),a=e.renderer!==t.renderer&&(null==(i=t.renderer)?void 0:i.type)!==(null==(r=e.renderer)?void 0:r.type);a&&this._updateSubview();const o=e.multidimensionalDefinition!==t.multidimensionalDefinition||n||a;this.subview.redrawOrRefetch(o).catch((e=>{s.isAbortError(e)||g.error(e)})),this.notifyChange("updating")})),n.watch((()=>{var e;return null!=(e=this.layer.blendMode)?e:"normal"}),(e=>{this.subview.container.blendMode=e}),n.syncAndInitial),n.watch((()=>{var e;return null!=(e=this.layer.effect)?e:null}),(e=>{this.subview.container.effect=e}),n.syncAndInitial),n.watch((()=>this.timeExtent),(()=>{this.subview.timeExtent=this.timeExtent,this.subview.redrawOrRefetch(!0).catch((e=>{s.isAbortError(e)||g.error(e)}))}),n.initial)],"attach")},a.detach=function(){var e;this.handles.remove("attach"),this.layer.decreaseRasterJobHandlerUsage(),this._detachSubview(this.subview),null==(e=this.subview)||e.destroy(),this.subview=null},a.moveStart=function(){this.requestUpdate()},a.viewChange=function(){this.requestUpdate()},a.moveEnd=function(){this.subview.moveEnd()},a.hitTest=function(){var t=e._asyncToGenerator((function*(e,t){return[{type:"graphic",layer:this.layer,mapPoint:e,graphic:new i({attributes:{},geometry:e.clone()})}]}));function r(e,i){return t.apply(this,arguments)}return r}(),a.doRefresh=function(){return this.subview.doRefresh()},a._updateSubview=function(){const e="vector-field"===this.layer.renderer.type?"rasterVF":"flow"===this.layer.renderer.type?"flow":"raster";if(this.subview){var t;if(this.subview.type===e)return void this._attachSubview(this.subview);this._detachSubview(this.subview),null==(t=this.subview)||t.destroy(),this.subview=null}const{layer:i}=this;let r;r="rasterVF"===e?new p({layer:i,layerView:this}):"flow"===e?new l({layer:i,layerView:this}):new v({layer:i,layerView:this}),"useWebGLForProcessing"in r&&(r.useWebGLForProcessing=this._useWebGLForProcessing),"useProgressiveUpdate"in r&&(r.useProgressiveUpdate=this._useProgressiveUpdate),"previousLOD"in r&&(r.previousLOD=this.subview&&"previousLOD"in this.subview&&this.subview.previousLOD),this._attachSubview(r),this.subview=r,this.requestUpdate()},a._attachSubview=function(e){e&&!e.attached&&(e.attach(),e.attached=!0,this.container.addChildAt(e.container,0),e.container.blendMode=this.layer.blendMode,e.container.effect=this.layer.effect)},a._detachSubview=function(e){null!=e&&e.attached&&(this.container.removeChild(e.container),e.detach(),e.attached=!1)},e._createClass(r,[{key:"useWebGLForProcessing",get:function(){return this._useWebGLForProcessing},set:function(e){this._useWebGLForProcessing=e,this.subview&&"useWebGLForProcessing"in this.subview&&(this.subview.useWebGLForProcessing=e)}},{key:"useProgressiveUpdate",get:function(){return this._useWebGLForProcessing},set:function(e){this._useProgressiveUpdate=e,this.subview&&"useProgressiveUpdate"in this.subview&&(this.subview.useProgressiveUpdate=e)}}]),r}(y(f(d.LayerView2DMixin(b))));t.__decorate([a.property()],_.prototype,"subview",void 0),t.__decorate([a.property()],_.prototype,"useWebGLForProcessing",null),t.__decorate([a.property()],_.prototype,"useProgressiveUpdate",null),_=t.__decorate([h.subclass("esri.views.2d.layers.ImageryTileLayerView2D")],_);return _}));
