我正在使用传单在 map 上显示我的几何位置。现在我的弹出窗口工作正常,但是当您将鼠标悬停在它们上方时,弹出窗口的位置例如位于行/字符串的中间,而不是在鼠标的位置上。是否可以将其更改为鼠标的位置,以便 map 不会突然移动到不同的位置?
我用来打开传单中弹出窗口的代码如下:
function addPopup(feature, layer) {
var popupContent = feature.properties.name;
layer.bindPopup(popupContent);
layer.on('mouseover', function (e) {
this.openPopup();
});
layer.on('mouseout', function (e) {
this.closePopup();
});
}
最佳答案
在 @Falke Design 指出您可以将 latlng 坐标提供给 openPopup 函数之后,我制作了代码的更简洁版本:
function addPopup(feature, layer) {
var popupContent = feature.properties.name;
layer.bindPopup(popupContent);
layer.on('mouseover', function (e) {
this.openPopup(e.latlng);
});
layer.on('mouseout', function (e) {
this.closePopup();
});
}
关于javascript - 传单在鼠标悬停时显示弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59193983/