Skip to content

Commit 5d6778c

Browse files
authored
Issue #56: Fix map already initialized with AJAX, fix container ID uniqueness (#58)
1 parent 92867d4 commit 5d6778c

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

js/leaflet.backdrop.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
$(backdropSettings.leaflet).each(function () {
8484
// skip to the next iteration if the map already exists
8585
var container = L.DomUtil.get(this.mapId);
86-
if (!container || container._leaflet) {
86+
if (!container || container._leaflet_id || container._leaflet) {
8787
return;
8888
}
8989

leaflet.module

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ function leaflet_library_info() {
110110
* A renderable array.
111111
*/
112112
function leaflet_build_map(array $map, array $features = array(), $height = '400px') {
113-
$map_id = backdrop_html_id('leaflet_map');
113+
// Function backdrop_html_id() is unreliable when creating unique IDs.
114+
// We attach a pseudo random number instead to make multiple maps on a page
115+
// work properly with maps in blocks.
116+
$map_id = 'leaflet-map-' . rand();
114117
$build = array(
115118
'#theme' => 'head_tag',
116119
'#tag' => 'div',

0 commit comments

Comments
 (0)