Active
Project:
Leaflet
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
14 Feb 2013 at 06:44 UTC
Updated:
20 Jul 2019 at 19:41 UTC
Jump to comment: Most recent
If I load a map inside a piece of tabbed content (loaded in a hidden div to start), the map does not display properly when the tab is opened.
I'm thinking this has something to do with the resize part of the js file? I found this, but I still can't get it to work with Drupal -
http://stackoverflow.com/questions/10762984/leaflet-map-not-displayed-pr...
Am using Leaflet in conjunction with MapBox.
Thanks for any ideas!
Comments
Comment #1
randallknutson commentedI'm having the same issue when using fieldgroups with tabs. Found the same stackoverflow issue.
Comment #2
randallknutson commentedFYI, here's the code I used to fix it. I targeted the tab on the page for a click event. Probably not the most elegant but it works for now.
Comment #3
juc1 commented@ randallknutson - I tried your code here (bottom of page) but so far it is not working for me - any ideas please what I am missing?
Thank you...
Comment #4
marc.groth commentedHey @Juc1 not sure if you are still having issues but I too couldn't get @randallknutson's code to work. However when I implemented the code suggested in the original StackOverflow issue it worked!
Instead of:
Drupal.settings.leaflet[0].lMap.invalidateSize(false);Implement:
Works well for me; hopefully it will for you too :)
Cheers,
Marc
Comment #5
juc1 commented@ marc.groth - thanks for your reply - I am just getting back to this. I have updated the code but it is still not working Does my code look ok?
Thanks...
Comment #6
socialnicheguru commentedJust want to note that this is a problem with alot of other modules when placed into a tab whether it's quicktab or panels_tab or panels_ajax_tab. The hidden div issue seems to be the general cause.
Comment #7
marc.groth commentedHey @Juc1,
I looked at your code and I see no call to requestAnimFrame() as per my first response. This code needs to be executed (ideally) when you click on the new tab (and ideally only the first time, if possible). So on click in my js I have made a call to that code and it's forced a refresh of the map.
Where is the code to do that in your example/site?
Cheers,
Marc
Comment #8
juc1 commented@ marc.groth sorry I was doing something else and messed up my js file - please look again here.
Thanks...
Comment #9
marc.groth commentedHey @Juc1,
Sorry it took me a while to respond. I think the problem you're encountering isn't the same as the issue posted here. This is stating that a map IS displaying, just not quite correctly. In your case, there is no map at all... So I think you have a different issue.
I did notice that you are trying to load the same map on one page in two different places (with the same ID). I don't think you are able to do that, which I think is where your problem lies. Are you wanting to show the exact same map in the new tab? If so, how come? If not, perhaps try specifying a different ID? I reckon that will work.
Sorry I can't be much more help... Hopefully if you get at least a partial map displaying you will then be able to implement the fix specified in this ticket (if it's even necessary, maybe it'll just work for you!).
Best of luck.
Cheers,
Marc
P.S. as @SocialNicheGuru suggested, this problem isn't specific to Leaflet and is apparent due to the use of hidden divs.
Comment #10
juc1 commented@ marc.groth no I did not want to show the same map in each tab - they were just meant to be random maps and I did not realise that the same map would cause a problem. I have now changed the maps and I think everything is ok = awesome, thanks.
Comment #11
froboyGetting back to the original issue, this does seem to be something that should be able to be fixed with a patch to the Leaflet module, I'm just not sure exactly where... I'm seeing this on Horizontal tabs made with fieldgroup module, so I'm assuming it's going to be any time the map is hidden on pageload. Is there any way we could select for this globally? Maybe some selector like
*[class*="hidden"] .leaflet-container("any element which has 'hidden' in a class name and contains a leaflet container")? Where would the fix go in the module? leaflet.drupal.js? Elsewhere?Let's squash this. Thanks!
Comment #12
morsokI have the same issue with the collapsible fieldset, a fix for this would be great !
Comment #13
anybodyWorkaround:
Comment #14
megan_m commentedFor Drupal 8, use this line to regenerate the map:
drupalSettings.leaflet['leaflet-map'].lMap.invalidateSize(false);Comment #15
socialnicheguru commented@meagan_m where do would I put that line?
Comment #16
FloGe commentedWith field group tabs I got it working with this
Comment #17
kenton.r commentedI found that the key for the leaflet object changes based on the ID of the node.
like: leaflet-map-node-series-1-field-geolocation (where the number 1 is the node ID)
So the following would not work:
drupalSettings.leaflet['leaflet-map'].lMap.invalidateSize(false);I had to retrieve the first key in the leaflet object. The following works:
Comment #18
iyyappan.govind#1 Facing same problem here. I tired #16 but not working at all. Thanks