問題描述
我正在使用 leaflet 開發一個新的應用程序.您可以在這里了解該應用.
I am using leaflet to develop a new application. You can have an idea of the app here.
我想在地圖邊界發生變化時觸發一個事件.我查看了文檔,但找不到與此相關的任何內容.
I would like to fire an event whenever the bounds of the map change. I looked at the doc but couldn't find anything related to that.
我找到了 getBounds() 方法,以及可能的 事件方法,但兩者都沒有結合.
I have found the getBounds() method, and the list of possible event methods, but nothing combining both.
我看到的唯一另一種可能性是檢查鼠標拖動和滾動事件并每次檢查邊界.但我希望有更好的事情可以做.
The only other possibility I see to do that is to check for mouse drag and scroll events and check the bounds every time. But I was hoping there would be something better to do.
你有更好的主意嗎?謝謝!
Would you have a better idea? Thanks!
推薦答案
每次移動地圖(通過平移或縮放)時都會更新地圖邊界.所以你可以使用 moveend 事件來達到你的目的
Map bounds are updated each time the map is moved (either by pan or zoom). So you can use moveend event for your purpose
map.on('moveend', function(e) {
var bounds = map.getBounds();
});
這篇關于Leaflet:當邊界改變時觸發一個事件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!