admin管理员组文章数量:1392081
I'm trying to do a business logic on a map whenever some events are done by a user.
I'm able to get working drag , dblclick and zoomstart events.
But load event is not getting fired for me. (On Browser load initially)
My sample code below :
var map = L.map('map').setView([34.7320,-86.5966], 14);
map.on('load drag dblclick zoomstart', function() {
// My business logic goes here.
});
I'm trying to do a business logic on a map whenever some events are done by a user.
I'm able to get working drag , dblclick and zoomstart events.
But load event is not getting fired for me. (On Browser load initially)
My sample code below :
var map = L.map('map').setView([34.7320,-86.5966], 14);
map.on('load drag dblclick zoomstart', function() {
// My business logic goes here.
});
Share
Improve this question
edited Jun 25, 2015 at 6:38
ram
2,3434 gold badges29 silver badges39 bronze badges
asked Jun 25, 2015 at 6:24
Arun KumarArun Kumar
1292 silver badges13 bronze badges
3 Answers
Reset to default 5Make sure .on
occurs before .setView
This can be done when you call setView, that makes the map fire the load event.
var map = L.map('map').on('load', function(){
// Your business logic here...
}).setView([34.7320,-86.5966], 14);
(OR)
https://github./Leaflet/Leaflet/issues/3560
http://jsfiddle/QUGyr/1/
Use map.whenReady(fn)
if you just want to do something when the map is ready:
map.whenReady(function(){
console.log('Map Loaded!');
});
Longer explanation: I'm having the same issue (with LeafletJS 1.6 and 1.7.1) with 'idle' and 'load' not triggering unless I define it before setting setView.
Digging through the source I discovered there's also map.whenReady(function(){});
which is working for me and also works if the map is already loaded.
So instead of:
map.on('load', function(){
console.log('Map Loaded!');
});
Use:
map.whenReady(function(){
console.log('Map Loaded!');
});
As from here you can use the event
'idle'
instead of
'load'
本文标签: javascriptload event not firing in leafletStack Overflow
版权声明:本文标题:javascript - load event not firing in leaflet - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744781172a2624721.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论