var __extends=this&&this.__extends||function(){var r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)t.hasOwnProperty(o)&&(e[o]=t[o])})(e,t)};return function(e,t){function o(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}}();import Event from"../events/Event.js";import ImageState from"../ImageState.js";import ReprojImage from"../reproj/Image.js";import Source from"./Source.js";import{ENABLE_RASTER_REPROJECTION}from"../reproj/common.js";import{IMAGE_SMOOTHING_DISABLED}from"./common.js";import{abstract}from"../util.js";import{equals}from"../extent.js";import{equivalent}from"../proj.js";import{linearFindNearest}from"../array.js";var ImageSourceEventType={IMAGELOADSTART:"imageloadstart",IMAGELOADEND:"imageloadend",IMAGELOADERROR:"imageloaderror"},ImageSourceEvent=function(o){function e(e,t){e=o.call(this,e)||this;return e.image=t,e}return __extends(e,o),e}(Event),ImageSource=function(o){function e(e){var t=o.call(this,{attributions:e.attributions,projection:e.projection,state:e.state})||this;return t.resolutions_=void 0!==e.resolutions?e.resolutions:null,t.reprojectedImage_=null,t.reprojectedRevision_=0,t.contextOptions_=!1===e.imageSmoothing?IMAGE_SMOOTHING_DISABLED:void 0,t}return __extends(e,o),e.prototype.getResolutions=function(){return this.resolutions_},e.prototype.getContextOptions=function(){return this.contextOptions_},e.prototype.findNearestResolution=function(e){var t;return this.resolutions_&&(t=linearFindNearest(this.resolutions_,e,0),e=this.resolutions_[t]),e},e.prototype.getImage=function(e,t,o,r){var n=this.getProjection();if(ENABLE_RASTER_REPROJECTION&&n&&r&&!equivalent(n,r)){if(this.reprojectedImage_){if(this.reprojectedRevision_==this.getRevision()&&equivalent(this.reprojectedImage_.getProjection(),r)&&this.reprojectedImage_.getResolution()==t&&equals(this.reprojectedImage_.getExtent(),e))return this.reprojectedImage_;this.reprojectedImage_.dispose(),this.reprojectedImage_=null}return this.reprojectedImage_=new ReprojImage(n,r,e,t,o,function(e,t,o){return this.getImageInternal(e,t,o,n)}.bind(this),this.contextOptions_),this.reprojectedRevision_=this.getRevision(),this.reprojectedImage_}return this.getImageInternal(e,t,o,r=n?n:r)},e.prototype.getImageInternal=function(e,t,o,r){return abstract()},e.prototype.handleImageChange=function(e){var t=e.target;switch(t.getState()){case ImageState.LOADING:this.loading=!0,this.dispatchEvent(new ImageSourceEvent(ImageSourceEventType.IMAGELOADSTART,t));break;case ImageState.LOADED:this.loading=!1,this.dispatchEvent(new ImageSourceEvent(ImageSourceEventType.IMAGELOADEND,t));break;case ImageState.ERROR:this.loading=!1,this.dispatchEvent(new ImageSourceEvent(ImageSourceEventType.IMAGELOADERROR,t))}},e}(Source);function defaultImageLoadFunction(e,t){e.getImage().src=t}export default ImageSource;export{ImageSourceEventType,ImageSourceEvent,defaultImageLoadFunction};