I produce geospatial data in a content type with addressfield and geofield. I can display this data in a Leaflet map as field without any problem. But I have to use here a modal, therefore I render the map programmatically:

$map = leaflet_map_get_info('google-high-res');
$map['settings']['zoom'] = 15;


$features = array(
        'type' => 'point',
        'lon' => $lon,
        'lat' => $lat
print leaflet_render_map($map, $features, $height);

When I display this map as a field, everything is OK, visitors can see the map as intended (marker in the middle etc.) But if I place it in a modal, multiple issues appear (see in the attached screenshot): Only one map tile is generated and the marker is in the wrong place in the modal as well, it's in the top left corner. I have tried Bootstrap Modal and Colorbox, it doesn't make any difference.

Leaflet map in modal

1 Answer 1


I found similar issues either with Leaflet or Google maps, like this one here. So I have to reload or re-render the map after the modal window become visible. For this purpose I inserted this jQuery code which does the trick:

jQuery(function($) {
$(\'#myMap\').on(\'shown.bs.modal\', function(){
var map = Drupal.settings.leaflet[0].lMap;
', 'inline');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.