首页 > 解决方案 > 仅当未显示弹出窗口时才在悬停时显示传单工具提示

问题描述

我有一个带有简短文本描述的工具提示和一个带有较长格式描述的弹出窗口,该描述绑定到传单地图上的标记。

悬停时显示工具提示,单击位置标记时显示弹出窗口。当较大的弹出窗口可见时,无需显示工具提示。当弹出窗口可见时,我可以禁用工具提示吗?我该怎么做?

这是我到目前为止的代码:

var marker = L.marker(location);
marker.bindPopup("Long description with extra formatting ...");
marker.bindTooltip("Short description");

标签: javascriptleaflet

解决方案


您可以为工具提示和弹出窗口添加自定义处理程序。使用返回 true 或 false 的传单方法isPopupOpen(),您可以决定是否打开工具提示。

function customTip() {
    this.unbindTooltip();
    if(!this.isPopupOpen()) this.bindTooltip('Short description').openTooltip();
}

function customPop() {
    this.unbindTooltip();
}

var marker = L.marker(location);
marker.bindPopup('Long description with extra formatting ...');
marker.on('mouseover', customTip);
marker.on('click', customPop);

推荐阅读