From 7927708b405955895fbddac2c78e68b11214c2a6 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Thu, 25 Aug 2016 15:29:20 +0200 Subject: [PATCH] Allow to create and open a tooltip without source (fix #4827) (#4836) --- spec/suites/layer/TooltipSpec.js | 9 +++++++++ src/layer/Tooltip.js | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/spec/suites/layer/TooltipSpec.js b/spec/suites/layer/TooltipSpec.js index cc6ddaab..f32e3fe9 100644 --- a/spec/suites/layer/TooltipSpec.js +++ b/spec/suites/layer/TooltipSpec.js @@ -278,5 +278,14 @@ describe('Tooltip', function () { L.Browser.touch = oldTouch; }); + + it("opens with map.openTooltip", function (done) { + map.on('tooltipopen', function (e) { + expect(map.hasLayer(e.tooltip)).to.be(true); + done(); + }); + map.openTooltip('Tooltip', center); + }); + }); diff --git a/src/layer/Tooltip.js b/src/layer/Tooltip.js index dcbd82c6..662f28e0 100644 --- a/src/layer/Tooltip.js +++ b/src/layer/Tooltip.js @@ -174,7 +174,7 @@ L.Tooltip = L.DivOverlay.extend({ _getAnchor: function () { // Where should we anchor the tooltip on the source layer? - return L.point(this._source._getTooltipAnchor && !this.options.sticky ? this._source._getTooltipAnchor() : [0, 0]); + return L.point(this._source && this._source._getTooltipAnchor && !this.options.sticky ? this._source._getTooltipAnchor() : [0, 0]); } });