gpt4 book ai didi

javascript - 传单中心弹出窗口和 map 标记

转载 作者:行者123 更新时间:2023-12-02 23:12:44 24 4
gpt4 key购买 nike

我希望将我的标记居中在打开的弹出窗口上..并且将 map 居中而不是在标记经纬度中,而是在标记和弹出窗口的中心!问题是弹出窗口具有动态内容(单击时加载)。

map 尺寸为移动设备上的完整显示尺寸!我只是在弹出窗口中使用了 autoPanPadding 选项,但还不够

引用下图:

popup centered in leaflet map

最佳答案

使用fitzpaddy的回答我能够使这段代码有效并且更加灵活。

map.on('popupopen', function(e) {
var px = map.project(e.target._popup._latlng); // find the pixel location on the map where the popup anchor is
px.y -= e.target._popup._container.clientHeight/2; // find the height of the popup container, divide by 2, subtract from the Y axis of marker location
map.panTo(map.unproject(px),{animate: true}); // pan to new center
});

关于javascript - 传单中心弹出窗口和 map 标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22538473/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com