I’m starting leaflet.js with the quickstart but my map shows as grey… is there something I’m missing?
script.js:
JavaScript
x
10
10
1
var leafletMap = L.map('leafletMap').setView([51.505, -0.09], 13);
2
3
L.tileLayer('http://{s}.title.cloudmade.com/' + API_KEY + '/997/256/{z}/{x}/{y}.png', {
4
attribution: 'Map data © [...]',
5
maxZoom: 18
6
}).addTo(leafletMap);
7
8
// marker
9
var marker = L.marker([51.5, -0.09]).addTo(leafletMap);
10
style.css:
JavaScript
1
5
1
#leafletMap {
2
height: 200px;
3
width: 200px;
4
}
5
index.html:
JavaScript
1
26
26
1
<!DOCTYPE html>
2
<html>
3
<head>
4
<meta charset="utf-8">
5
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6
<title>My title</title>
7
8
<link rel='stylesheet' href='css/bootstrap.css'>
9
<link rel='stylesheet' href='css/leaflet.css'>
10
<!--[if lte IE 8]>
11
<link rel="stylesheet" href="leaflet.ie.css" />
12
<![endif]-->
13
<link rel="stylesheet" href="css/style.css">
14
</head>
15
<body>
16
17
<div id='leafletMap'></div>
18
19
<script src='js/libs/jquery-1.10.2.js'></script>
20
<script src='js/libs/bootstrap.js'></script>
21
<script src='js/libs/leaflet-src.js'></script>
22
<script src='js/config.js'></script>
23
<script src='js/script.js'></script>
24
</body>
25
</html>
26
Gives me:
Advertisement
Answer
You need to implement the next section of the Quick Start Guide: you’ve initialized the map, but haven’t added any tile layers to it, hence gray. So read on to the section beginning with Next we’ll add a tile layer to add to our map.