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 () {
var img = this._image = DomUtil.create('img',
'leaflet-image-layer ' + (this._zoomAnimated ? 'leaflet-zoom-animated ' : '') +
(this.options.className || ''));
var wasElementSupplied = this._url.tagName === 'IMG';
var img = this._image = wasElementSupplied ? this._url : DomUtil.create('img');
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.onmousemove = Util.falseFn;
@ -199,6 +202,11 @@ export var ImageOverlay = Layer.extend({
this._updateZIndex();
}
if (wasElementSupplied) {
this._url = img.src;
return;
}
img.src = this._url;
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
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]; }