Map container not found

13,134 views
Skip to first unread message

José Santos

unread,
Nov 26, 2014, 12:33:13 PM11/26/14
to leafl...@googlegroups.com
Hey all, 

I have this error every-time I try to initialize my map: Map container not found  

Could be a problem related with DOM and downloading the map? 

Thank you for your help. 

Regards,
José Santos 

Brendan Stone

unread,
Nov 28, 2014, 11:43:04 AM11/28/14
to leafl...@googlegroups.com
It sounds like your Javascript is running before the map container is created.
Try moving your Javascript code below your <div id='map'></div>

If that doesn't work, post you code and I'm sure someone will be able to help.

José Santos

unread,
Dec 1, 2014, 1:45:30 PM12/1/14
to leafl...@googlegroups.com
Hey, 

In fact that was the problem. Basic mistake. Thank you for your help. 

Regards,
José 

Prachi kshirsagar

unread,
Oct 21, 2016, 5:21:44 AM10/21/16
to Leaflet

Hello,

I have problem in map container not found give me help


<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        
        <link href='https://www.mapbox.com/base/latest/base.css' rel='stylesheet' />
        <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
        <script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
        
    </head>

<body>
  <div class='limiter'>
    <div class='col10 margin1 pad4y'>
      <div class='space-bottom'>
        <div id='map' class='col12 row10'></div>
      </div>
   
    </div>
  </div>

        <script>
            function map(div)
            {
                alert(div);
                var map = L.map('div', {
                fullscreenControl: {
                pseudoFullscreen: false
            }
        }).setView([37.8, -96], 4);
        
                            maxZoom: 18,
                            attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
                                    '<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
                                    'Imagery © <a href="http://mapbox.com">Mapbox</a>',
                            id: 'mapbox.streets'
                    }).addTo(map);
                
               
function onMapClick(e) {
popup
.setLatLng(e.latlng)
.setContent("You clicked the map at " + e.latlng.toString())
.openOn(map);
}

map.on('click', onMapClick);
</script>

              <div id="map"></div>
                <input type="button" value="test" onclick="map('map')"/>

    </body>
</html>
                
                

Reply all
Reply to author
Forward
0 new messages