Give ol.Image an imageLoadFunction argument

This commit is contained in:
Andreas Hocevar
2014-10-29 20:07:00 +01:00
parent 87a06c0086
commit 46eb14dc96
2 changed files with 32 additions and 3 deletions

View File

@@ -20,9 +20,10 @@ goog.require('ol.extent');
* @param {Array.<ol.Attribution>} attributions Attributions.
* @param {string} src Image source URI.
* @param {?string} crossOrigin Cross origin.
* @param {ol.ImageLoadFunctionType} imageLoadFunction Image load function.
*/
ol.Image =
function(extent, resolution, pixelRatio, attributions, src, crossOrigin) {
ol.Image = function(extent, resolution, pixelRatio, attributions, src,
crossOrigin, imageLoadFunction) {
goog.base(this, extent, resolution, pixelRatio, ol.ImageState.IDLE,
attributions);
@@ -59,6 +60,13 @@ ol.Image =
* @type {ol.ImageState}
*/
this.state = ol.ImageState.IDLE;
/**
* @private
* @type {ol.ImageLoadFunctionType}
*/
this.imageLoadFunction_ = imageLoadFunction;
};
goog.inherits(ol.Image, ol.ImageBase);
@@ -127,7 +135,7 @@ ol.Image.prototype.load = function() {
goog.events.listenOnce(this.image_, goog.events.EventType.LOAD,
this.handleImageLoad_, false, this)
];
this.image_.src = this.src_;
this.imageLoadFunction_(this, this.src_);
}
};

View File

@@ -0,0 +1,21 @@
goog.provide('ol.ImageLoadFunctionType');
/**
* A function that takes an {@link ol.Image} for the image and a `{string}` for
* the src as arguments. It is supposed to make it so the underlying image
* {@link ol.Image#getImage} is assigned the content specified by the src. If
* not specified, the default is
*
* function(image, src) {
* image.getImage().src = src;
* }
*
* Providing a custom `imageLoadFunction` can be useful to load images with
* post requests or - in general - through XHR requests, where the src of the
* image element would be set to a data URI when the content is loaded.
*
* @typedef {function(ol.Image, string)}
* @api
*/
ol.ImageLoadFunctionType;