Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

map:init event never triggered #27

Open
ScottEAdams opened this issue Aug 29, 2013 · 13 comments
Open

map:init event never triggered #27

ScottEAdams opened this issue Aug 29, 2013 · 13 comments
Labels

Comments

@ScottEAdams
Copy link

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?

@ScottEAdams
Copy link
Author

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.

@leplatrem
Copy link
Collaborator

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 ?

@ScottEAdams
Copy link
Author

Tried without jquery and then it tiggers. Some kind of conflict?

@leplatrem
Copy link
Collaborator

Ok, good news, it may come from missing api. Which jQuery version are you' using ?

@ScottEAdams
Copy link
Author

jquery-1.10.2.min.js

@leplatrem
Copy link
Collaborator

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);

@ScottEAdams
Copy link
Author

Sorry for the late reply!

yes, I get a "Notified o/ " message in the console but only that. Should I be seeing anything else?

@joaoponceleao
Copy link

Sorry for re-opening this.
I'm getting the exact same behaviour on Safari (10.9.4). Works as expected on Firefox.

@leplatrem leplatrem reopened this Jul 21, 2014
@leplatrem
Copy link
Collaborator

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 !

@demiurg
Copy link

demiurg commented Aug 17, 2014

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.

@leplatrem
Copy link
Collaborator

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 :)

@ismailsunni
Copy link

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.

@demiurg
Copy link

demiurg commented Jun 7, 2016

You can extract relevant jquery event listening code applicable to safari, from jquery.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants