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
+1
View File
@@ -4375,6 +4375,7 @@ olx.source.ImageVectorOptions.prototype.style;
* hidpi: (boolean|undefined), * hidpi: (boolean|undefined),
* serverType: (ol.source.wms.ServerType|string|undefined), * serverType: (ol.source.wms.ServerType|string|undefined),
* logo: (string|olx.LogoOptions|undefined), * logo: (string|olx.LogoOptions|undefined),
* imageLoadFunction: (ol.ImageLoadFunctionType|undefined),
* params: Object.<string,*>, * params: Object.<string,*>,
* projection: ol.proj.ProjectionLike, * projection: ol.proj.ProjectionLike,
* ratio: (number|undefined), * ratio: (number|undefined),
+9 -1
View File
@@ -8,6 +8,7 @@ goog.require('goog.string');
goog.require('goog.uri.utils'); goog.require('goog.uri.utils');
goog.require('ol'); goog.require('ol');
goog.require('ol.Image'); goog.require('ol.Image');
goog.require('ol.ImageLoadFunctionType');
goog.require('ol.extent'); goog.require('ol.extent');
goog.require('ol.proj'); goog.require('ol.proj');
goog.require('ol.source.Image'); goog.require('ol.source.Image');
@@ -49,6 +50,13 @@ ol.source.ImageWMS = function(opt_options) {
*/ */
this.url_ = options.url; this.url_ = options.url;
/**
* @private
* @type {ol.ImageLoadFunctionType}
*/
this.imageLoadFunction_ = goog.isDef(options.imageLoadFunction) ?
options.imageLoadFunction : ol.source.Image.defaultImageLoadFunction;
/** /**
* @private * @private
* @type {Object} * @type {Object}
@@ -235,7 +243,7 @@ ol.source.ImageWMS.prototype.getImage =
projection, params); projection, params);
this.image_ = new ol.Image(extent, resolution, pixelRatio, this.image_ = new ol.Image(extent, resolution, pixelRatio,
this.getAttributions(), url, this.crossOrigin_); this.getAttributions(), url, this.crossOrigin_, this.imageLoadFunction_);
this.renderedRevision_ = this.getRevision(); this.renderedRevision_ = this.getRevision();
@@ -134,6 +134,16 @@ describe('ol.source.ImageWMS', function() {
expect(queryData.get('DPI')).to.be('180'); 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() { describe('#getGetFeatureInfo', function() {