Hugo Story Theme
Archives Slides Talks

Maps with Leaflet.js

Published Aug 19, 2018 by Lionel VICTOR in Demo at https://story-customized.tchinchow.net/leaflet/

Story integrates Hugo Leaflet and allow you to embed maps and GPX trails in your blog posts.

This article demonstrates a handfull of the possibilities offered by this powerful combination.

Map only

Once the feature-leaflet class have been added to your article, embedding a simple map merely requires using the leaflet-map hugo shortcode. And you don’t have to take my word for it ; Just take a look at the following code:

{{< leaflet-map mapId="first_map" mapHeight="500px" mapWidth="100%" mapLat="43.2500000" mapLon="5.4500000" />}}

This is rendered as follows:

Here follows a list of parameters that can be used with the leaflet-map shortcode (Except for the caption parameters that have been added for Story, this list come directly from the Hugo Leaflet site).

Story’s specific parameters:

ParameterDescriptionMandatoryDefaultPossible values
captionText to be displayed below the mapno""any string

Parameters from the original Hugo Leaflet project

ParameterDescriptionMandatoryDefaultPossible values
mapHeightMap height sizeno“400px”any number in px
mapWidthMap width sizeno“100%”any number in px or %
mapLatLatitude where to center the mapyes""any valid coords number
mapLonLongitude where to center the mapyes""any valid coords number
mapIdUnique id. Useful for add multiple map in the post with same longitude and latitudenomd5(mapLat,mapLon)any string
zoomThe zoom level. If set, it must be parsable as int.no“13”any number
scrollWheelZoomEnable or disable zoom with mouse scroll wheelno“true”"true" or "false"

Map’s unique identifier

Maps MUST be distinguished by a unique identifier. As you can see in the above parameters list, a default identifier is computed from the digest of the coordinates that are provided to the leaflet-map.

If you plan on re-using the same map with identical coordinates, then this computed identifier will be the same for all your maps and this will viloate the unicity constrain.

In that case, you shall provide unique mapId values and make sure that they are indeed different from each other. You must do that in each and every map that may be duplicated in your page.

Direct links to your maps

In most cases, leaving MapId to its default value is a good idea. However, because it is based on cryptographic primitives, it is not always easy to guess what this default value will be.

When you fix the mapId, then you can create leverage on this knowledge to forge direct links to your maps as follows:

[a link to my map](#mapid_<your_id_here>)

Map with GPX track

You can share your hikes, motorcycle rides, snowshoeing trails, etc… by adding a GPX track to your map (You don’t need to provide coordinates, leaflet will center the track for you but be careful that your map has a unique id):

{{< leaflet-map mapHeight="400px" mapWidth="100%" ... >}}
    {{< leaflet-track trackPath="les_bories_de_tallagard.gpx" downloadIcon=true caption="Discover shepherd shelters in Provence" />}}
{{< /leaflet-map >}}

As an exemple, the GPX trail from the above snippet comes from a nice one hour walk in Provence (a region of southeastern France). Leaflet will add the elevation profile as follows:

Discover shepherd shelters in Provence

Story’s specific parameters:

ParameterDescriptionMandatoryDefaultPossible values
downloadIconwhether we shall display the download icon and provide a download link for the GPX trailnofalsetrue of false
captionA caption for the trackno""any string
graphThemeElevation graph theme _(in addition to leaflet existing themes)no“story-theme”"story-theme" or any theme from the original library

Parameters from the original Hugo Leaflet project

ParameterDescriptionMandatoryDefaultPossible values
trackPathYour GPX file. You must place in static/gpx folder.yes""any filename like "my_track.gpx"
lineColorLine track colorno“#006EFF”any valid hex color
lineWeightLine track weight on the mapno“3”any number
lineOpacityLine track opacity on the mapno“1”decimal range from 0 to 1
graphPositionElevation graph position on the map. Not valid if you use graphDetachedno“topright”"myLocation"
graphThemeElevation graph theme already presentno“steelblue-theme”"steelblue-theme", "lime-theme" or "purple-theme"
graphWidthElevation graph width. Not valid if you use graphDetachedno“500”any number
graphHeightElevation graph heightno“150”any number
graphFollowMarkerAuto zoom on the mouse movement over the mapnofalsetrue or false
graphCollapsedHide elevation graph below the buttonnofalsetrue or false
graphDetachedDetach elevation graph outside mapnotruetrue or false
markerIconWaypoint Fontawesome icon nameno“fa-thumb-tack”"fa-thumb-tack" (see fontawesome documentation)
markerIconColorWaypoint icon colorno“cyan”"red", "orange-dark", "orange", "yellow", "blue-dark", "cyan", "purple", "violet", "pink", "green-dark", "green", "green-light", "black", "white"
markerIconShapeWaypoint icon shapeno“penta”"circle", square, penta or star
markerIconClassesExtra classes for extends icon cssno“fa-icon-marker”"my-class my-second-class"
markerStartIconStart Waypoint Fontawesome icon nameno“fa-play”"fa-play" (see fontawesome documentation)
markerStartIconColorStart Waypoint icon colorno“green-light”"red", "orange-dark", "orange", "yellow", "blue-dark", "cyan", "purple", "violet", "pink", "green-dark", "green", "green-light", "black", "white"
markerStartIconShapeStart Waypoint icon shapeno“circle”"circle", square, penta or star
markerStartIconClassExtra classes for extends start icon cssno“fa-icon-marker fa-icon-start-stop”"my-class my-second-class"
markerEndIconEnd Waypoint Fontawesome icon nameno“fa-flag-checkered”"fa-flag-checkered" (see fontawesome documentation)
markerEndIconColorEnd Waypoint icon colorno“red”"red", "orange-dark", "orange", "yellow", "blue-dark", "cyan", "purple", "violet", "pink", "green-dark", "green", "green-light", "black", "white"
markerEndIconShapeEnd Waypoint icon shapeno“circle”"circle", square, penta or star
markerEndIconClassesExtra classes for extends end icon cssno“fa-icon-marker fa-icon-start-stop”"my-class my-second-class"

Map with one marker

You can showcase one particular place with a single marker:

{{< leaflet-map mapHeight="300px" mapWidth="100%" mapLat="44.9178069" mapLon="4.8852736" zoom=18 >}}
    {{< leaflet-marker markerLat="44.9175319" markerLon="4.8855297" markerContent="Gastronomic restaurant <em>(3 Michelin Star)</em>" >}}
{{< /leaflet-map >}}

or many places at once (by the way notice the use of the “caption” parameter):

Starred Michelin guide restaurants in Valence

Just like other sub-shortcodes, leaflet-marker takes a number of arguments that we repeat below as they come directly from the Hugo Leaflet site:

ParameterDescriptionMandatoryDefaultPossible values
markerLatLatitude where to place the markeryes""any valid coords number
markerLonLongitude where to place the markeryes""any valid coords number
markerContentPopup content textno""any text, html accepted

Read next: Story’s Embedded Screencasts and Videos.

Lionel

Lionel VICTOR is an applied cryptography engineer and an enthusiastic Story user. He started augmenting the original Hugo’s Story theme with his own derivative called “Story-Customized”.

Find out more about Lionel on LinkedIn.

Story logo

© 2025 Baron Schwartz / Lionel VICTOR