Add className option for ImageOverlay (#5555)

This commit is contained in:
Per Liedman 2017-06-22 16:25:15 +02:00 committed by Iván Sánchez Ortega
parent 6bfa764cb0
commit a3ec8047b3
2 changed files with 15 additions and 3 deletions

View File

@ -30,7 +30,8 @@ describe('ImageOverlay', function () {
map.setView(new L.LatLng(55.8, 37.6), 6); // view needs to be set so when layer is added it is initilized map.setView(new L.LatLng(55.8, 37.6), 6); // view needs to be set so when layer is added it is initilized
overlay = L.imageOverlay(blankUrl, [[40.712216, -74.22655], [40.773941, -74.12544]], { overlay = L.imageOverlay(blankUrl, [[40.712216, -74.22655], [40.773941, -74.12544]], {
errorOverlayUrl: errorUrl errorOverlayUrl: errorUrl,
className: 'my-custom-image-class'
}); });
map.addLayer(overlay); map.addLayer(overlay);
@ -76,6 +77,12 @@ describe('ImageOverlay', function () {
expect(overlay._image.src).to.be(errorUrl); expect(overlay._image.src).to.be(errorUrl);
}); });
}); });
describe('className', function () {
it('should set image\'s class', function () {
expect(L.DomUtil.hasClass(overlay._image, 'my-custom-image-class')).to.be(true);
});
});
}); });
describe('#setZIndex', function () { describe('#setZIndex', function () {

View File

@ -47,7 +47,11 @@ export var ImageOverlay = Layer.extend({
// @option zIndex: Number = 1 // @option zIndex: Number = 1
// The explicit [zIndex](https://developer.mozilla.org/docs/Web/CSS/CSS_Positioning/Understanding_z_index) of the tile layer. // The explicit [zIndex](https://developer.mozilla.org/docs/Web/CSS/CSS_Positioning/Understanding_z_index) of the tile layer.
zIndex: 1 zIndex: 1,
// @option className: String = ''
// A custom class name to assign to the image. Empty by default.
className: '',
}, },
initialize: function (url, bounds, options) { // (String, LatLngBounds, Object) initialize: function (url, bounds, options) { // (String, LatLngBounds, Object)
@ -176,7 +180,8 @@ export var ImageOverlay = Layer.extend({
_initImage: function () { _initImage: function () {
var img = this._image = DomUtil.create('img', var img = this._image = DomUtil.create('img',
'leaflet-image-layer ' + (this._zoomAnimated ? 'leaflet-zoom-animated' : '')); 'leaflet-image-layer ' + (this._zoomAnimated ? 'leaflet-zoom-animated' : '') +
(this.options.className || ''));
img.onselectstart = Util.falseFn; img.onselectstart = Util.falseFn;
img.onmousemove = Util.falseFn; img.onmousemove = Util.falseFn;