Leaflet Demo Tutorial

Demo Tutorial Part 1

Leaflet is an open-source JavaScript library for mobile-friendly interactive maps. This documentation will help you to create your first map with Leaflet and you will learn some basic mapping principles. Basic usage:

Lets begin with the most basic HTML page:


			  
<html>
  <head>
  </head>
     
  <body>
  </body>
</html>

Include these Leaflet CSS and JS files in head tag:


			  <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>

Add the map div on the page where you want to display the map and set the height/width for this div


<div id="map" class="map" style="height: 500px; width: 500px;"></div>

Use the following minimal JavaScript code inside the <script> tag to initialize the Map.


			  var map = L.map('map', {
	center: [34,-88],
	zoom: 4
});
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);

Putting It All Together



			  
			  <!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
</head>
<body>
<div id="map" class="map" style="height: 500px; width: 500px;"></div>
<script>
var map = L.map('map', {
	center: [34,-88],
	zoom: 4
});
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
</script>
</body>
</html>
	

 

Up Next: Leaflet Demo Tutorial Part 2

Leaflet Demo Tutorial 2