/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../../core/Logger.js";import{destroyMaybe as r}from"../../../core/maybe.js";import{isAbortError as i}from"../../../core/promiseUtils.js";import{watch as a}from"../../../core/reactiveUtils.js";import{property as s,subclass as o}from"../../../core/accessorSupport/decorators.js";import n from"../../../geometry/Extent.js";import{BitmapContainer as m}from"../engine/BitmapContainer.js";import{LayerView2D as h}from"./LayerView2D.js";import p from"./support/ExportStrategy.js";import c from"../../layers/LayerView.js";import{RefreshableLayerView as d}from"../../layers/RefreshableLayerView.js";import{WMSLayerView as u}from"../../layers/WMSLayerView.js";let g=class extends(u(d(h(c)))){constructor(){super(...arguments),this.bitmapContainer=new m}supportsSpatialReference(e){return this.layer.serviceSupportsSpatialReference(e)}update(e){this.strategy.update(e).catch(e=>{i(e)||t.getLogger(this).error(e)})}attach(){const{layer:e}=this,{imageMaxHeight:t,imageMaxWidth:r}=e;this.bitmapContainer=new m,this.container.addChild(this.bitmapContainer),this.strategy=new p({container:this.bitmapContainer,fetchSource:this.fetchImage.bind(this),requestUpdate:this.requestUpdate.bind(this),imageMaxHeight:t,imageMaxWidth:r,imageRotationSupported:!1,imageNormalizationSupported:!1,hidpi:!1}),this.addAttachHandles(a(()=>this.exportImageVersion,()=>this.requestUpdate()))}detach(){this.strategy=r(this.strategy),this.container.removeAllChildren()}viewChange(){}moveEnd(){this.requestUpdate()}createFetchPopupFeaturesQuery(e){const{view:t,bitmapContainer:r}=this,{x:i,y:a}=e,{spatialReference:s}=t;let o,m=0,h=0;if(r.children.some(e=>{const{width:t,height:r,resolution:p,x:c,y:d}=e,u=c+p*t,g=d-p*r;return i>=c&&i<=u&&a<=d&&a>=g&&(o=new n({xmin:c,ymin:g,xmax:u,ymax:d,spatialReference:s}),m=t,h=r,!0)}),!o)return null;const p=o.width/m,c=Math.round((i-o.xmin)/p),d=Math.round((o.ymax-a)/p);return{extent:o,width:m,height:h,x:c,y:d}}async doRefresh(){this.requestUpdate()}isUpdating(){return this.strategy.updating||this.updateRequested}fetchImage(e,t,r,i){return this.layer.fetchImageBitmap(e,t,r,{timeExtent:this.timeExtent,...i})}};e([s()],g.prototype,"strategy",void 0),g=e([o("esri.views.2d.layers.WMSLayerView2D")],g);const y=g;export{y as default};
