var __extends=this&&this.__extends||function(){var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])})(t,e)};return function(t,e){function i(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}}();import ImageWrapper from"../Image.js";import EventType from"../events/EventType.js";import{containsExtent,getCenter,getHeight,getWidth,scaleFromCenter}from"../extent.js";import{assign}from"../obj.js";import ImageSource,{defaultImageLoadFunction}from"./Image.js";import{appendParams}from"../uri.js";var ImageMapGuide=function(i){function t(t){var e=i.call(this,{projection:t.projection,resolutions:t.resolutions})||this;return e.crossOrigin_=void 0!==t.crossOrigin?t.crossOrigin:null,e.displayDpi_=void 0!==t.displayDpi?t.displayDpi:96,e.params_=t.params||{},e.url_=t.url,e.imageLoadFunction_=void 0!==t.imageLoadFunction?t.imageLoadFunction:defaultImageLoadFunction,e.hidpi_=void 0===t.hidpi||t.hidpi,e.metersPerUnit_=void 0!==t.metersPerUnit?t.metersPerUnit:1,e.ratio_=void 0!==t.ratio?t.ratio:1,e.useOverlay_=void 0!==t.useOverlay&&t.useOverlay,e.image_=null,e.renderedRevision_=0,e}return __extends(t,i),t.prototype.getParams=function(){return this.params_},t.prototype.getImageInternal=function(t,e,i,r){e=this.findNearestResolution(e),i=this.hidpi_?i:1;var n=this.image_;if(n&&this.renderedRevision_==this.getRevision()&&n.getResolution()==e&&n.getPixelRatio()==i&&containsExtent(n.getExtent(),t))return n;1!=this.ratio_&&(t=t.slice(),scaleFromCenter(t,this.ratio_));var o=getWidth(t)/e,a=getHeight(t)/e;return void 0!==this.url_?(o=this.getUrl(this.url_,this.params_,t,[o*i,a*i],r),(n=new ImageWrapper(t,e,i,o,this.crossOrigin_,this.imageLoadFunction_)).addEventListener(EventType.CHANGE,this.handleImageChange.bind(this))):n=null,this.image_=n,this.renderedRevision_=this.getRevision(),n},t.prototype.getImageLoadFunction=function(){return this.imageLoadFunction_},t.prototype.updateParams=function(t){assign(this.params_,t),this.changed()},t.prototype.getUrl=function(t,e,i,r,n){var o=getScale(i,r,this.metersPerUnit_,this.displayDpi_),i=getCenter(i),r={OPERATION:this.useOverlay_?"GETDYNAMICMAPOVERLAYIMAGE":"GETMAPIMAGE",VERSION:"2.0.0",LOCALE:"en",CLIENTAGENT:"ol/source/ImageMapGuide source",CLIP:"1",SETDISPLAYDPI:this.displayDpi_,SETDISPLAYWIDTH:Math.round(r[0]),SETDISPLAYHEIGHT:Math.round(r[1]),SETVIEWSCALE:o,SETVIEWCENTERX:i[0],SETVIEWCENTERY:i[1]};return assign(r,e),appendParams(t,r)},t.prototype.setImageLoadFunction=function(t){this.image_=null,this.imageLoadFunction_=t,this.changed()},t}(ImageSource);function getScale(t,e,i,r){var n=getWidth(t),t=getHeight(t),o=e[0],e=e[1],r=.0254/r;return o*t<e*n?n*i/(o*r):t*i/(e*r)}export default ImageMapGuide;