April 04, 2016
Here is my solution for embedding a simple Leaflet map in a Jekyll post without all the boilerplate. Normally you would copy-paste a <div>, a <script>, and remember to load Leaflet somewhere on the page. It gets messy when you have more than one map.
So I wrote a {% map %} Liquid tag that handles everything.
Drop this anywhere in your markdown:
That one line gives you a map, a marker, and a caption. The tag loads Leaflet CSS and JS once per page, so you can stack as many maps as you want without worrying about duplicate script tags.
Taller map for showing area context:
Sometimes you just want the view without a marker:
The marker="false" part removes the pin. Useful when you want to show the region rather than a specific point.
Custom basemap? No problem:
Inset-sized for side-by-side with text:
| Option | Default | Notes |
|---|---|---|
lat | required | latitude, decimal degrees |
lon | required | longitude, decimal degrees |
zoom | 12 | higher is closer to ground |
height | 400px | any CSS value |
width | 100% | any CSS value |
caption | — | HTML below map, also the marker popup |
marker | true | set "false" to hide the pin |
basemap | OpenStreetMap | tile URL template like https://{s}.tile.../{z}/{x}/{y}.png |
attribution | OSM | tile attribution HTML |
All five maps above are on this one page. The tag tracks how many have been rendered and gives each one a unique ID — no conflicts.
If you write a GIS blog with Jekyll, this single tag covers most of the “show me where” moments. For story-driven narratives, I have another tag for that — but that is a different post.