I have setup a view with a list of nodes. The title is a link that opens the full node which contains a leaflet map. When it loads the map I get the following error in the console:
Uncaught Error: Map container is already initialized.
If i close the Ajax modal (colorbox node or auto-dialog) I can not reload / open that particular link without a full refresh of the page. I can remove the map from the display of the node and it loads and reloads fine (also the map loads fine on a normal page).
About a third of the time when a modal window is opened the error message will rapidly repeat to well over 200 time within a few seconds.
The center and bounds are not reset for each map. (marker is sometime loaded outside of the map window with only a portion of tiles showing)
I am using the leaflet 1.0 version.
Is there a way to get this working?
Comment | File | Size | Author |
---|---|---|---|
#14 | leaflet-ajax-error-2808957-14.patch | 466 bytes | blasoliva |
#12 | Capture-geofield.PNG | 7.26 KB | ldwyer |
#6 | leaflet-ajax-error-2808957-6.patch | 441 bytes | elimw |
Comments
Comment #2
kenton.r CreditAttribution: kenton.r commentedI have found some references to AJAX calling multiple calls for the one page load. Therefore JSs can be processed multiple times and cause errors. This might be why the "map container is already being initialized."
This is what I found at http://codekarate.com/blog/drupal-7-prevent-duplicating-javascript-behav...:
where can I add this to the leaflet.drupal.js
$("#leaflet-map").once('map', function() {
Any help with this?
Comment #3
kenton.r CreditAttribution: kenton.r commentedAny help with understanding what is happening with this error?
Comment #4
aprogs CreditAttribution: aprogs commentedConfirming the bug. I have the page with the map and some links that make AJAX requests. The error appears when the user clicks the link. It seems that the map gets initialized multiple times when AJAX framework attaches Drupal behaviours.
Tested with Leaflet 1.0.1.
Comment #5
facettenreich CreditAttribution: facettenreich commentedHad same issue. The change of container._leaflet in container.leaflet_id in file leaflet_markercluster.drupal.js (same lines are used in leaflet.drupal.js) worked for me.
Maybe it helps you, too.
Comment #6
elimw CreditAttribution: elimw commentedHi guys,
I've just created a patch for this issue and it works for me.
Can somebody please review it?
Comment #7
aprogs CreditAttribution: aprogs commented@ewong-dh, thanks for the patch, it has been successfully applied and the bug was solved for me.
Comment #8
ericdsd CreditAttribution: ericdsd commentedI had the same issue when re submitting exposed filter on my leaflet view,
the patch leaflet-ajax-error-2808957-6.patch + manually applying the same modifications to leaflet_markercluster.drupal.js fixed the issue
Thanks a lot
Comment #9
RdeBoerThis patch is already part of 7.x-1.x-dev.
It was applied 13 Jan: https://www.drupal.org/node/1222714/commits
It is also in Leaflet Markercluster 7.x-1.x-dev
Comment #10
RdeBoerComment #12
ldwyer CreditAttribution: ldwyer as a volunteer commentedHello - this appears to still be an issue even with the patch.
I have a calendar view that opens events in a colorbox. The colorbox displays the [rendered_entity] of the event content type.
I get two of these errors: Uncaught Error: Map container is already initialized.
Once when the calendar view loads and once when I try to open an event in the colorbox.
I am using Drupal 7.5.6, Libraries Leaflet 1.0.2 and Leaflet Marker Cluster 1.1.0 and the latest modules of both Leaflet and Leaflet Marker Cluster (patch is already there).
Attached is how the map renders on first load.
Any light anyone can shed on this would be greatly appreciated. Thanks in advance.
Comment #13
zoraxI have the same error message.
I have two views in the same page.
When I change a contextual filter in my first view here is the console error message :
leaflet.js?p3w10x:6 Uncaught Error: Map container is already initialized.
at e._initContainer (leaflet.js?p3w10x:6)
at e.initialize (leaflet.js?p3w10x:6)
at new e (leaflet.js?p3w10x:6)
at Object. (leaflet.drupal.js?p3w10x:20)
at Function.each (jquery.js?v=1.8.3:611)
at $.fn.init.each (jquery.js?v=1.8.3:241)
at Object.attach (leaflet.drupal.js?p3w10x:6)
at Object. (drupal.js?p3w10x:76)
at Function.each (jquery.js?v=1.8.3:605)
at Object.Drupal.attachBehaviors (drupal.js?p3w10x:74)
_initContainer @ leaflet.js?p3w10x:6
initialize @ leaflet.js?p3w10x:6
e @ leaflet.js?p3w10x:6
(anonymous) @ leaflet.drupal.js?p3w10x:20
each @ jquery.js?v=1.8.3:611
each @ jquery.js?v=1.8.3:241
attach @ leaflet.drupal.js?p3w10x:6
(anonymous) @ drupal.js?p3w10x:76
each @ jquery.js?v=1.8.3:605
Drupal.attachBehaviors @ drupal.js?p3w10x:74
insert @ ajax.js?v=7.56:570
Drupal.ajax.success @ ajax.js?v=7.56:428
success @ ajax.js?v=7.56:189
options.success @ jquery.form.js?v=4.2.1:267
fire @ jquery.js?v=1.8.3:974
fireWith @ jquery.js?v=1.8.3:1084
done @ jquery.js?v=1.8.3:7803
callback @ jquery.js?v=1.8.3:8518
XMLHttpRequest.send (async)
send @ jquery.js?v=1.8.3:8434
ajax @ jquery.js?v=1.8.3:7986
$.fn.ajaxSubmit @ jquery.form.js?v=4.2.1:326
Drupal.ajax.eventResponse @ ajax.js?v=7.56:279
(anonymous) @ ajax.js?v=7.56:206
dispatch @ jquery.js?v=1.8.3:3058
eventHandle @ jquery.js?v=1.8.3:2676
trigger @ jquery.js?v=1.8.3:2941
(anonymous) @ jquery.js?v=1.8.3:3599
each @ jquery.js?v=1.8.3:611
each @ jquery.js?v=1.8.3:241
trigger @ jquery.js?v=1.8.3:3598
jQuery.fn.(anonymous function) @ jquery.js?v=1.8.3:3652
triggerSubmit @ auto-submit.js?p3w10x:42
(anonymous) @ auto-submit.js?p3w10x:55
dispatch @ jquery.js?v=1.8.3:3058
eventHandle @ jquery.js?v=1.8.3:2676
ListPicker._handleMouseUp
I just install the dev version....
Comment #14
blasoliva CreditAttribution: blasoliva commentedLast patch does not work for me and the page is still not redirecting. I added a third condition for the iteration when the map already exists.