Merge pull request #5948 from ronikar/master

ImageOverlay accept ImageElement
This commit is contained in:
Andrew 2017-12-21 13:50:48 +01:00 committed by GitHub
commit 572938c741
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 4 deletions

View File

@ -179,9 +179,12 @@ export var ImageOverlay = Layer.extend({
}, },
_initImage: function () { _initImage: function () {
var img = this._image = DomUtil.create('img', var wasElementSupplied = this._url.tagName === 'IMG';
'leaflet-image-layer ' + (this._zoomAnimated ? 'leaflet-zoom-animated ' : '') + var img = this._image = wasElementSupplied ? this._url : DomUtil.create('img');
(this.options.className || ''));
DomUtil.addClass(img, 'leaflet-image-layer');
if (this._zoomAnimated) { DomUtil.addClass(img, 'leaflet-zoom-animated'); }
if (this.options.className) { DomUtil.addClass(img, this.options.className); }
img.onselectstart = Util.falseFn; img.onselectstart = Util.falseFn;
img.onmousemove = Util.falseFn; img.onmousemove = Util.falseFn;
@ -199,6 +202,11 @@ export var ImageOverlay = Layer.extend({
this._updateZIndex(); this._updateZIndex();
} }
if (wasElementSupplied) {
this._url = img.src;
return;
}
img.src = this._url; img.src = this._url;
img.alt = this.options.alt; img.alt = this.options.alt;
}, },

View File

@ -49,7 +49,16 @@ export var VideoOverlay = ImageOverlay.extend({
// Fired when the video has finished loading the first frame // Fired when the video has finished loading the first frame
vid.onloadeddata = Util.bind(this.fire, this, 'load'); vid.onloadeddata = Util.bind(this.fire, this, 'load');
if (wasElementSupplied) { return; } if (wasElementSupplied) {
var sourceElements = vid.getElementsByTagName('source');
var sources = [];
for (var j = 0; j < sourceElements.length; j++) {
sources.push(sourceElements[j].src);
}
this._url = (sourceElements.length > 0) ? sources : [vid.src];
return;
}
if (!Util.isArray(this._url)) { this._url = [this._url]; } if (!Util.isArray(this._url)) { this._url = [this._url]; }