django-leaflet
django-leaflet copied to clipboard
map:init event never triggered
I have not done anything out of the ordinary and for some reason the map:init event is never triggered. Using the callback works as expected. Any ideas? Best way to debug?
for example:
window.addEventListener("map:init", function () { console.log("Init: 1"); }, false);
document.addEventListener("DOMContentLoaded", function () { console.log("Init: 2"); }, false);
Console shows only Init:2
My base map is showing.
Thanks for reporting !
Hum strange, the source is trivial:
https://github.com/makinacorpus/django-leaflet/blob/master/leaflet/static/leaflet/leaflet.extras.js#L209-L218
Do you have CustomEvent support ?
Can you try with / without jquery ?
Tried without jquery and then it tiggers. Some kind of conflict?
Ok, good news, it may come from missing api. Which jQuery version are you' using ?
jquery-1.10.2.min.js
Could you please try to run this snippet please, and see if event is triggered and received ?
$(window).on('bar:foo', function (e) { console.log('Notified o/ '); });
var target = window,
type = 'bar:foo',
data = {a: 1};
var evt = jQuery.Event(type);
for (var k in data)
evt[k] = data[k];
jQuery(target).trigger(evt);
Sorry for the late reply!
yes, I get a "Notified o/ " message in the console but only that. Should I be seeing anything else?
Sorry for re-opening this. I'm getting the exact same behaviour on Safari (10.9.4). Works as expected on Firefox.
Don't be sorry !
I don't have much time right now to investigate the issue :( If you want to contribute a fix, don't hesitate, I would be pleased to merge it !
This was an issue for me in Safari, breaking all the maps. It seems to be a bug in how the event is created. Here is how I had to fix it for now:
if (typeof window.CustomEvent == 'function'){
window.addEventListener("map:init", init_handler, false);
}else{
$(window).on("map:init", init_handler);
}
Time permitting, maybe I can find the source issue.
Thanks for this feedback !
It looks like it's simple as that : CustomEvent are not widely supported : https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent#Browser_compatibility
Which leads me to think that we should maybe rewrite this piece of code in static/leaflet.extras.js
.
If anyone feels like to do it, I would be pleased to review and merge a PR :)
Hi @demiurg
I have the same problem as yours, not working on Safari. It seems your solutions need a jquery ($(window).on("map:init", init_handler);
). Do you have any solution without jquery?
I asked this since that if else statement
will be place before loading any jquery.
You can extract relevant jquery event listening code applicable to safari, from jquery.