Give ol.Image an imageLoadFunction argument
This commit is contained in:
+11
-3
@@ -20,9 +20,10 @@ goog.require('ol.extent');
|
|||||||
* @param {Array.<ol.Attribution>} attributions Attributions.
|
* @param {Array.<ol.Attribution>} attributions Attributions.
|
||||||
* @param {string} src Image source URI.
|
* @param {string} src Image source URI.
|
||||||
* @param {?string} crossOrigin Cross origin.
|
* @param {?string} crossOrigin Cross origin.
|
||||||
|
* @param {ol.ImageLoadFunctionType} imageLoadFunction Image load function.
|
||||||
*/
|
*/
|
||||||
ol.Image =
|
ol.Image = function(extent, resolution, pixelRatio, attributions, src,
|
||||||
function(extent, resolution, pixelRatio, attributions, src, crossOrigin) {
|
crossOrigin, imageLoadFunction) {
|
||||||
|
|
||||||
goog.base(this, extent, resolution, pixelRatio, ol.ImageState.IDLE,
|
goog.base(this, extent, resolution, pixelRatio, ol.ImageState.IDLE,
|
||||||
attributions);
|
attributions);
|
||||||
@@ -59,6 +60,13 @@ ol.Image =
|
|||||||
* @type {ol.ImageState}
|
* @type {ol.ImageState}
|
||||||
*/
|
*/
|
||||||
this.state = ol.ImageState.IDLE;
|
this.state = ol.ImageState.IDLE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {ol.ImageLoadFunctionType}
|
||||||
|
*/
|
||||||
|
this.imageLoadFunction_ = imageLoadFunction;
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.Image, ol.ImageBase);
|
goog.inherits(ol.Image, ol.ImageBase);
|
||||||
|
|
||||||
@@ -127,7 +135,7 @@ ol.Image.prototype.load = function() {
|
|||||||
goog.events.listenOnce(this.image_, goog.events.EventType.LOAD,
|
goog.events.listenOnce(this.image_, goog.events.EventType.LOAD,
|
||||||
this.handleImageLoad_, false, this)
|
this.handleImageLoad_, false, this)
|
||||||
];
|
];
|
||||||
this.image_.src = this.src_;
|
this.imageLoadFunction_(this, this.src_);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
Reference in New Issue
Block a user