Tech notes for leafletjs



  1. Quick introduction leaflet.js

Quick introduction leaflet.js

Let's create a HTML file:

<link rel="stylesheet" href="" />
  #mapid { height: 380px;
           width: 380px;
<script src=""></script>
<div id="mapid"></div>

We're fetching leaflet.js from the internet somewhere, and we have a mapid div, along with explicit hight on that div, which leaflet demands.

Now in the script tag, let's create a leaflet object, with a zoom level and lat lon:

var mymap ='mapid').setView([51.379959, -1.144644], 13);

Let's now create a tile layer, using mapbox's streets layer, passing in a max zoom level, attribution, id of layer and token.

L.tileLayer('{id}/{z}/{x}/{y}.png?access_token={token}', {
  maxZoom: 18,
  attribution: '',
  id: 'mapbox.streets',
  token: 'pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpandmbXliNDBjZWd2M2x6bDk3c2ZtOTkifQ._QA7i5Mpkd_m30IGElHziw'

Finally let's create a marker, and give it a name.

var marker = L.marker([51.379959, -1.144644]).addTo(mymap);
marker.bindPopup("Some company here").openPopup();

And that's as simple as it gets.

leafletjs javascript

Page 1 of 1
Click me