diff --git a/externs/olx.js b/externs/olx.js index de26d5c6cd..9dc376aae0 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -4375,6 +4375,7 @@ olx.source.ImageVectorOptions.prototype.style; * hidpi: (boolean|undefined), * serverType: (ol.source.wms.ServerType|string|undefined), * logo: (string|olx.LogoOptions|undefined), + * imageLoadFunction: (ol.ImageLoadFunctionType|undefined), * params: Object., * projection: ol.proj.ProjectionLike, * ratio: (number|undefined), diff --git a/src/ol/source/imagewmssource.js b/src/ol/source/imagewmssource.js index 05c162a141..4ba801d895 100644 --- a/src/ol/source/imagewmssource.js +++ b/src/ol/source/imagewmssource.js @@ -8,6 +8,7 @@ goog.require('goog.string'); goog.require('goog.uri.utils'); goog.require('ol'); goog.require('ol.Image'); +goog.require('ol.ImageLoadFunctionType'); goog.require('ol.extent'); goog.require('ol.proj'); goog.require('ol.source.Image'); @@ -49,6 +50,13 @@ ol.source.ImageWMS = function(opt_options) { */ this.url_ = options.url; + /** + * @private + * @type {ol.ImageLoadFunctionType} + */ + this.imageLoadFunction_ = goog.isDef(options.imageLoadFunction) ? + options.imageLoadFunction : ol.source.Image.defaultImageLoadFunction; + /** * @private * @type {Object} @@ -235,7 +243,7 @@ ol.source.ImageWMS.prototype.getImage = projection, params); this.image_ = new ol.Image(extent, resolution, pixelRatio, - this.getAttributions(), url, this.crossOrigin_); + this.getAttributions(), url, this.crossOrigin_, this.imageLoadFunction_); this.renderedRevision_ = this.getRevision(); diff --git a/test/spec/ol/source/imagewmssource.test.js b/test/spec/ol/source/imagewmssource.test.js index b407a27913..5031017338 100644 --- a/test/spec/ol/source/imagewmssource.test.js +++ b/test/spec/ol/source/imagewmssource.test.js @@ -134,6 +134,16 @@ describe('ol.source.ImageWMS', function() { expect(queryData.get('DPI')).to.be('180'); }); + it('creates an image with a custom imageLoadFunction', function() { + var imageLoadFunction = sinon.spy(); + options.imageLoadFunction = imageLoadFunction; + var source = new ol.source.ImageWMS(options); + var image = source.getImage(extent, resolution, pixelRatio, projection); + image.load(); + expect(imageLoadFunction).to.be.called(); + expect(imageLoadFunction.calledWith(image, image.src_)).to.be(true); + }); + }); describe('#getGetFeatureInfo', function() {