I used the popupopen
and popupclose
events to manipulate the tooltip visibility.
This is a good generic solution that doesn't involve extending the standard classes and still respects all the standard configuration and options around popups and tooltips.
map.on('popupclose', function (e) {
// make the tooltip for this feature visible again
// but check first, not all features will have tooltips!
var tooltip = e.popup._source.getTooltip();
if (tooltip) tooltip.setOpacity(0.9);
});
map.on('popupopen', function (e) {
var tooltip = e.popup._source.getTooltip();
// not all features will have tooltips!
if (tooltip)
{
// close the open tooltip, if you have configured animations on the tooltip this looks snazzy
e.target.closeTooltip();
// use opacity to make the tooltip for this feature invisible while the popup is active.
e.popup._source.getTooltip().setOpacity(0);
}
});
NOTE: Took a bit of effort to track down the actual events this solution to a different issue pointed me in the right direction: https://stackoverflow.com/a/16707921/1690217
In my case I have bound the tooltip and the popup to have the same content, so I want to hide the tooltip to suppress the redundant information. In the following greenshot you can see the popup for one shape and the tooltip on hover over the other shapes, it looks messy when that tooltip tries to show under the existing popup when you hover over the feature that triggered the popup.
