Skip to content

Commit

Permalink
Issue #56: Fix map already initialized with AJAX, fix container ID un…
Browse files Browse the repository at this point in the history
…iqueness (#58)
  • Loading branch information
indigoxela authored Mar 10, 2024
1 parent 92867d4 commit 5d6778c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion js/leaflet.backdrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
$(backdropSettings.leaflet).each(function () {
// skip to the next iteration if the map already exists
var container = L.DomUtil.get(this.mapId);
if (!container || container._leaflet) {
if (!container || container._leaflet_id || container._leaflet) {
return;
}

Expand Down
5 changes: 4 additions & 1 deletion leaflet.module
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ function leaflet_library_info() {
* A renderable array.
*/
function leaflet_build_map(array $map, array $features = array(), $height = '400px') {
$map_id = backdrop_html_id('leaflet_map');
// Function backdrop_html_id() is unreliable when creating unique IDs.
// We attach a pseudo random number instead to make multiple maps on a page
// work properly with maps in blocks.
$map_id = 'leaflet-map-' . rand();
$build = array(
'#theme' => 'head_tag',
'#tag' => 'div',
Expand Down

0 comments on commit 5d6778c

Please sign in to comment.