Making Leaflet tooltip clickable(使传单工具提示可点击)
问题描述
我想在 Leaflet 地图(不带标记)上添加 工具提示 并使其可点击.以下代码添加了一个工具提示,但它不可点击:
I want to add tooltips on a Leaflet map (without markers) and make them clickable. The following code adds a tooltip but it's not clickable:
我怎样才能让它工作?
推荐答案
要接收对 L.Tooltip
对象的点击,您需要:
To receive clicks on a L.Tooltip
object, you'll need to :
在关联的 DOM 对象上设置监听器:
set up a listener on the associated DOM object :
删除 pointer-events: none
在该元素上设置的属性:
remove the pointer-events: none
property set on that element:
到目前为止的演示
如果您想创建组件或直接监听工具提示对象,您可以扩展 L.Tooltip
以将这些更改直接烘焙到定义中:
If you want to create a component or listen directly to a tooltip object, you can extend L.Tooltip
to bake those alterations directly into the definition:
还有一个演示
这篇关于使传单工具提示可点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!