Problems with leaflet.js

I have used leaflet.js a few times without problems but have a site where when the page is loaded initially the leaflet map does not show. When I resize the window, it shows fine again. This occurs no matter the initial size.

I have added the stylesheet link…

         <link rel="stylesheet" href=""

And added the div for the map…

  <div id="mapid"></div>

Then at the bottom of the page added this code…

<script src=""
        var mymap ='mapid').setView([55.70926, -3.87980], 10);
        L.tileLayer('{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
        attribution: 'Map data &copy; <a href="">OpenStreetMap</a> contributors, <a href="">CC-BY-SA</a>,          
Imagery © <a href="">Mapbox</a>',
        id: 'mapbox.streets',
        accessToken: 'My access token was added here.'

Can anyone advise how I get around this problem please?

After 2 days of trying to get a solution to this and trying all the workarounds and hacks online, I’ve finally got it working.
I simple added this, hope it helps someone else. …

1 Like

Hi @Hlforr, there would certainly be a proper solution other than this workaround… just a shot in the dark, but did you maybe forget to set an initial height for the map (that would later be set with JS on resize)? Other than that, your code works fine for me…

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.