var __extends=this&&this.__extends||function(){var o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)};return function(e,t){function r(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}}();import{abstract}from"../util.js";import{ENABLE_RASTER_REPROJECTION}from"../reproj/common.js";import ImageState from"../ImageState.js";import{linearFindNearest}from"../array.js";import Event from"../events/Event.js";import{equals}from"../extent.js";import{equivalent}from"../proj.js";import ReprojImage from"../reproj/Image.js";import Source from"./Source.js";var ImageSourceEventType={IMAGELOADSTART:"imageloadstart",IMAGELOADEND:"imageloadend",IMAGELOADERROR:"imageloaderror"},ImageSourceEvent=function(r){function e(e,t){e=r.call(this,e)||this;return e.image=t,e}return __extends(e,r),e}(Event),ImageSource=function(r){function e(e){var t=r.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}return __extends(e,r),e.prototype.getResolutions=function(){return this.resolutions_},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,r,o){var n=this.getProjection();if(ENABLE_RASTER_REPROJECTION&&n&&o&&!equivalent(n,o)){if(this.reprojectedImage_){if(this.reprojectedRevision_==this.getRevision()&&equivalent(this.reprojectedImage_.getProjection(),o)&&this.reprojectedImage_.getResolution()==t&&equals(this.reprojectedImage_.getExtent(),e))return this.reprojectedImage_;this.reprojectedImage_.dispose(),this.reprojectedImage_=null}return this.reprojectedImage_=new ReprojImage(n,o,e,t,r,function(e,t,r){return this.getImageInternal(e,t,r,n)}.bind(this)),this.reprojectedRevision_=this.getRevision(),this.reprojectedImage_}return this.getImageInternal(e,t,r,o=n?n:o)},e.prototype.getImageInternal=function(e,t,r,o){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{ImageSourceEvent,defaultImageLoadFunction};