Do not fail when closing an interactive tooltip not yet added to the map (#4937)

This commit is contained in:
Yohan Boniface 2016-09-26 15:40:51 +02:00 committed by Vladimir Agafonkin
parent 79d8837b1f
commit e28f7ae984
2 changed files with 7 additions and 1 deletions

View File

@ -287,5 +287,11 @@ describe('Tooltip', function () {
map.openTooltip('Tooltip', center); map.openTooltip('Tooltip', center);
}); });
it("can call closeTooltip while not on the map", function () {
var layer = new L.Marker(center);
layer.bindTooltip('Tooltip', {interactive: true});
layer.closeTooltip();
});
}); });

View File

@ -121,7 +121,7 @@ L.Layer.include({
closeTooltip: function () { closeTooltip: function () {
if (this._tooltip) { if (this._tooltip) {
this._tooltip._close(); this._tooltip._close();
if (this._tooltip.options.interactive) { if (this._tooltip.options.interactive && this._tooltip._container) {
L.DomUtil.removeClass(this._tooltip._container, 'leaflet-clickable'); L.DomUtil.removeClass(this._tooltip._container, 'leaflet-clickable');
this.removeInteractiveTarget(this._tooltip._container); this.removeInteractiveTarget(this._tooltip._container);
} }