Intro to Leaflet  |  Basic Leaflet Map

This is a basic map, <pre style="display:inline;">var map = L.map('map');</pre> where ‘map’ is both the variable and the name of the div id where we want to place the map. The scale and layer control are built-in Leaflet functions. The hash is a simple plugin which puts the current mouse location in the browser url bar. This comes in handy for troubleshooting as well as sharing the exact map location. The view can be set as an option when calling the map, or by using the setView function.

The full code of all the examples can be seen below the map.

Click here to download a fullpage html template.

« Outline Adding Basemaps (Tile Layers) »

Full Map Code

      
var map = L.map("map");

map.setView([40.3,-96.6], 5);

L.hash(map);

L.control.scale().addTo(map);

var layerControl = new L.control.layers(null, null).addTo(map);