Lerry William S.

Quick Map Embed With a Single Liquid Tag

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.

How it works

Drop this anywhere in your markdown:

Merlion Park, Singapore — where it all started

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.

A few examples

Taller map for showing area context:

Taman Negara National Park — one of the oldest rainforests on Earth.

Sometimes you just want the view without a marker:

Tokyo area — no marker, just the view

The marker="false" part removes the pin. Useful when you want to show the region rather than a specific point.

Custom basemap? No problem:

London — CartoDB light basemap

Inset-sized for side-by-side with text:

Bintulu, Sarawak

All options

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.