question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Leaflet freezes in Bootstrap 3 modal after zooming, closing and reopening the map

See original GitHub issue

Hi,

I use Leaflet (master) to show the geolocation of different photos on a map in a modal dialog. When opening the modal with the map, everything works. But when I zoom in, close the modal dialog and click on another photo (with same or different lat and lng) the modal opens but the map does not respond to the mouse anymore. Everything except for the keyboard is frozen. If I move the view with the keyboard, it unfreezes. But I can’t change the zoom level with the mouse or move around, it does not respond to that…

Neither map.setView / map.setZoom nor map.invalidateSize() unfreeze the map. However, I found out that calling map.flyTo(map.getCenter()) and for example map.fire('moveend') unfreeze the map controls. But I’d rather not use those without understanding what the problem is. Do you have an idea, what the underlying problem could be?

Here my CoffeeScript code:

I call the following once with every page:load and page ready handler:

exports = this

# Create a global variable with the map object
exports.map = L.map('map-canvas')

# Add an OpenStreetMap tile layer
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(exports.map)

# Create a global variable with the marker object
exports.marker = L.marker([0, 0]).addTo(exports.map)

# Workaround for Bootstrap 3 modal dialog, resizes the map after the dialog is visible
$("#geoModal").on "shown.bs.modal", (e) ->
    exports.map.invalidateSize()

My click handler, which opens the modal dialog containing the map, looks like this:

exports = this

mapClickHandler = ->
    # Show on the map, where the photo was taken
    coords = L.latLng($("a#photo-maplink").data('latitude'), $("a#photo-maplink").data('longitude'))
    zoomlevel = $("a#photo-maplink").data('zoom-level') || 14
    # Change the position of our cached map object
    exports.map.setView(coords, zoomlevel)
    # Change the position of our cached marker object
    exports.marker.setLatLng(coords).update()
    # Open the modal dialog
    $('#geoModal').modal()

Is this a bug in Leaflet or did I get something wrong in my setup code / click handler?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
clemensgcommented, May 19, 2015

It looks like the shown.bs.modal event is not always fired and therefore invalidateSize does not get called every time the map container is shown. Calling invalidateSize both before I open the modal and after the shown.bs.modal event fired, does seem to fix the issue.

At the beginning of the click handler I call map.invalidateSize(), then I set the LatLng and the marker, then I open the modal and after shown.bs.modal fires, I call map.invalidateSize() again.

If I skip the first map.invalidateSize(), the bug reported in this issue happens: It works until I zoom, close and reopen the modal. On the other hand, if I skip the second map.invalidateSize() the map does not even get displayed correctly in the first place.

0reactions
anthonykeller79commented, May 19, 2015

I’m not using bootstrap so when I get a test case setup I’ll raise a new issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Leaflet map freezing in bootstrap 3.0 modal - Stack Overflow
I think what is happening is that, when the map is created, the container width/height for your `map-canvas' element has not yet been...
Read more >
Safari Technology Preview Release Notes - Apple Developer
Safari Technology Preview Release 147 is now available for download for macOS Monterey 12.3 or later and macOS Ventura beta. Updates to Safari...
Read more >
Untitled
Block para jardin, Huib petersen beading, Sirenia the 13th floor descargar, Problems in africa after independence, The beat magazine stockists, ...
Read more >
Untitled
Bootstrap 3 modal center vertically, Jampi maling, Rocbolt resins pty ltd, ... Providence bruins 2015 schedule, Map of ho chi minh city centre, ......
Read more >
Deep Freeze Ape ##,,, - COK GUZAL of Best Club crypto NFT ; Ape ...
... tropical vibe waves 1960 1970 2019 3 420 60s aestethic alex morgan alien aloha anatomy apples atlanta atlantis avocados awesome backgrounds basic...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found