reusing images in ol.style.Icon#clone
This commit is contained in:
@@ -176,24 +176,11 @@ ol.inherits(ol.style.Icon, ol.style.Image);
|
||||
|
||||
|
||||
/**
|
||||
* Clones the style.
|
||||
* Clones the style. The underlying Image/HTMLCanvasElement is not cloned.
|
||||
* @return {ol.style.Icon} The cloned style.
|
||||
* @api
|
||||
*/
|
||||
ol.style.Icon.prototype.clone = function() {
|
||||
var oldImage = this.getImage(1);
|
||||
var newImage;
|
||||
if (this.iconImage_.getImageState() === ol.ImageState.LOADED) {
|
||||
if (oldImage.tagName.toUpperCase() === 'IMG') {
|
||||
newImage = /** @type {Image} */ (oldImage.cloneNode(true));
|
||||
} else {
|
||||
newImage = /** @type {HTMLCanvasElement} */ (document.createElement('canvas'));
|
||||
var context = newImage.getContext('2d');
|
||||
newImage.width = oldImage.width;
|
||||
newImage.height = oldImage.height;
|
||||
context.drawImage(oldImage, 0, 0);
|
||||
}
|
||||
}
|
||||
return new ol.style.Icon({
|
||||
anchor: this.anchor_.slice(),
|
||||
anchorOrigin: this.anchorOrigin_,
|
||||
@@ -201,9 +188,7 @@ ol.style.Icon.prototype.clone = function() {
|
||||
anchorYUnits: this.anchorYUnits_,
|
||||
crossOrigin: this.crossOrigin_,
|
||||
color: (this.color_ && this.color_.slice) ? this.color_.slice() : this.color_ || undefined,
|
||||
img: newImage ? newImage : undefined,
|
||||
imgSize: newImage ? this.iconImage_.getSize().slice() : undefined,
|
||||
src: newImage ? undefined : this.getSrc(),
|
||||
src: this.getSrc(),
|
||||
offset: this.offset_.slice(),
|
||||
offsetOrigin: this.offsetOrigin_,
|
||||
size: this.size_ !== null ? this.size_.slice() : undefined,
|
||||
|
||||
Reference in New Issue
Block a user