diff --git a/src/ol/image.js b/src/ol/image.js
index 904f7bc095..e1881c0cae 100644
--- a/src/ol/image.js
+++ b/src/ol/image.js
@@ -20,9 +20,10 @@ goog.require('ol.extent');
* @param {Array.
} 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_);
}
};
diff --git a/src/ol/imageloadfunction.js b/src/ol/imageloadfunction.js
new file mode 100644
index 0000000000..0d4b74cda2
--- /dev/null
+++ b/src/ol/imageloadfunction.js
@@ -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;