Why is the map not showing when load my html? beginner in javascript Here is my code
<!DOCTYPE html>
<html>
<head>
<title>Leaflet Web Map</title>
<style type="text/css">
#map {
width: 960px;
height: 500px;
}
</style>
<link rel="stylesheet" href="css/leaflet.css" />
<script src="js/leaflet.js"> </script>
</head>
<body>
<script>
var map = L.map('map',{
center: [43.64701, -79.39425],
zoom: 15
});
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href =
"http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
</script>
<div id="map">
</div>
</body>
</html>
the css source and the script source comes from my teacher
You should try moving your script to the bottom of your page:
<!DOCTYPE html>
<html>
<head>
<title>Leaflet Web Map</title>
<style type="text/css">
#map {
width: 960px;
height: 500px;
}
</style>
<link rel="stylesheet" href="css/leaflet.css" />
<script src="js/leaflet.js"> </script>
</head>
<body>
<div id="map"></div>
<script>
var map = L.map('map',{
center: [43.64701, -79.39425],
zoom: 15
});
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href = "http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
</script>
</body>
</html>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.