Make icon size optional
This commit is contained in:
+14
-3
@@ -5,12 +5,23 @@ goog.require('ol.style.Image');
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} src Image source URI.
|
* @param {string} src Image source URI.
|
||||||
* @param {ol.Size} size Image size.
|
* @param {ol.Size=} opt_size Image size.
|
||||||
* @return {ol.style.Image} Image.
|
* @return {ol.style.Image} Image.
|
||||||
*/
|
*/
|
||||||
ol.icon.renderIcon = function(src, size) {
|
ol.icon.renderIcon = function(src, opt_size) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {ol.Size}
|
||||||
|
*/
|
||||||
|
var size = goog.isDef(opt_size) ? opt_size : null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {ol.Pixel}
|
||||||
|
*/
|
||||||
|
var anchor = !goog.isNull(size) ? [size[0] / 2, size[1] / 2] : null;
|
||||||
|
|
||||||
return new ol.style.Image({
|
return new ol.style.Image({
|
||||||
anchor: [size[0] / 2, size[1] / 2],
|
anchor: anchor,
|
||||||
size: size,
|
size: size,
|
||||||
src: src,
|
src: src,
|
||||||
rotation: 0,
|
rotation: 0,
|
||||||
|
|||||||
@@ -114,6 +114,12 @@ ol.style.Image.prototype.handleImageError_ = function() {
|
|||||||
*/
|
*/
|
||||||
ol.style.Image.prototype.handleImageLoad_ = function() {
|
ol.style.Image.prototype.handleImageLoad_ = function() {
|
||||||
this.imageState = ol.style.ImageState.LOADED;
|
this.imageState = ol.style.ImageState.LOADED;
|
||||||
|
if (goog.isNull(this.size)) {
|
||||||
|
this.size = [this.image.width, this.image.height];
|
||||||
|
}
|
||||||
|
if (goog.isNull(this.anchor)) {
|
||||||
|
this.anchor = [this.size[0] / 2, this.size[1] / 2];
|
||||||
|
}
|
||||||
this.unlistenImage_();
|
this.unlistenImage_();
|
||||||
this.dispatchChangeEvent_();
|
this.dispatchChangeEvent_();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user