我正在使用传单在地图上显示我的几何位置。现在,我的弹出窗口可以正常工作,但是当您将鼠标悬停在它们上方时,弹出窗口的位置例如位于行/字符串的中间,而不位于鼠标的位置。是否可以将其更改为鼠标的位置,以便地图不会突然移动到其他位置?
我用来在传单中打开弹出窗口的代码如下:
double to_pow(int zahl, int potenz){
potenz--;
if(potenz!=0){
zahl = zahl * to_pow(zahl, potenz);
}
return zahl;
}
int main(){
double res = to_pow(9,3);
printf("%.lf\n", res);
}
答案 0 :(得分:1)
您可以将鼠标指针转换为latlng并在那里设置弹出窗口。
layer.on('mouseover', function (e) {
var p = L.point([e.originalEvent.clientX,e.originalEvent.clientY])
var latlng = mymap.containerPointToLatLng(p);
this.openPopup(latlng)
});
layer.on('mousemove', function(e){
var p = L.point([e.originalEvent.clientX,e.originalEvent.clientY])
var latlng = mymap.containerPointToLatLng(p);
this.openPopup(latlng)
})
layer.on('mouseout', function (e) {
答案 1 :(得分:0)
@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();
});
}