Leaflet is an open source JavaScript library used to visualize maps. Like many map visualization systems, it works with superimposed layers. Each layer can be a different type. In this section, we will only use two of them:
- The Tile layer displays square PNG images. Depending on the layer, it can contain streets, toponymy, or even points of interest. In our case, we will only use the default Open Street Map tile layer.
- The GeoJSON layer displays data with the GeoJSON format. So far, we have only seen geometries stored as WKT. GeoJSON is another human-readable representation of geometries. The following code shows the WKT and GeoJSON representations of the same shape:
WKT:
LINESTRING(-73.9879285 40.7597869,-73.9878847 40.759847)
GeoJSON:
{"type":"LineString","coordinates":[[-73.9879285,40.7597869],[-73.9878847,40.759847]]}
Let's get started and build our map. Creating a leaflet map is as simple as executing the following command...