Add imageLoadFunction option for ol.source.ImageWMS

This commit is contained in:
Andreas Hocevar
2014-10-29 20:10:00 +01:00
parent a1e19b4905
commit fed6376e26
3 changed files with 20 additions and 1 deletions

View File

@@ -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.<string,*>,
* projection: ol.proj.ProjectionLike,
* ratio: (number|undefined),

View File

@@ -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();

View File

@@ -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() {