Skip to main content
What Travelogue Taught Me About Interactive Maps in Web Applications

What Travelogue Taught Me About Interactive Maps in Web Applications

December 28, 2024 3 min read Leaflet, OpenStreetMap, Geospatial, React, JavaScript, Frontend

What Travelogue Taught Me About Interactive Maps in Web Applications is a Developer Journal article by Ancel Ajanga on https://ancel.co.ke. Lessons from building Travelogue with React, Leaflet.js and OpenStreetMap: keeping the map from breaking the page, modelling places as GeoJSON, and handling touch scrolling on mobile. It focuses on: A map is one of the heaviest and least predictable parts of a page. Ancel Ajanga (Senior Software Engineer) authored this piece from production engineering work.

Lessons from building Travelogue with React, Leaflet.js and OpenStreetMap: keeping the map from breaking the page, modelling places as GeoJSON, and handling touch scrolling on mobile.

Who this is for

Web developers adding a map to a React application for the first time, and anyone curious how a travel-story site combines maps with content.

Problem

A map is one of the heaviest and least predictable parts of a page. It depends on a third-party tile service, it captures touch gestures, and when it fails it can take the rest of the page with it.

Business outcome

A travel storytelling site where visitors explore destinations on an interactive map and read the stories attached to them, without needing a paid map API.

Metrics

  • Maps rendered with Leaflet.js and OpenStreetMap tiles, with no paid map API required
  • Map or tile failures degrade to a message so stories and navigation keep working
  • Place data modelled as standard GeoJSON

A map can turn a list of places into a story. A line of text saying "Nairobi National Park, August" is information. The same place on a map, next to the photos and notes from the trip, is context. That was the idea behind Travelogue, and building it taught me how much a map adds to a page, and how much it can take away if you are not careful.

Travelogue is a React application that pairs an interactive world map with travel stories and destination pages. The map uses **Leaflet.js** with **OpenStreetMap** tiles. I chose them because they are small, well documented and need no paid map API. The trade-off is covered below.

Treat the map as the least reliable part of the page

A map depends on things you do not control. Tiles come from a third-party server, the connection may be slow, and a blocked request leaves grey squares where the map should be. My rule on Travelogue was that a map problem must never become a page problem. If tiles or data fail, the map area shows a message, and the stories, navigation and theme switch keep working.

It sounds obvious, but it changes how you structure components. The map lives in its own component with its own loading and error state. Nothing else on the page waits for it.

Model places as GeoJSON

Each destination is a place with coordinates, a title and a date. I kept that data in the standard GeoJSON shape rather than a custom format:

son
{
  "type": "Feature",
  "geometry": { "type": "Point", "coordinates": [36.8219, -1.2921] },
  "properties": { "title": "Nairobi National Park", "category": "Wildlife" }
}

Two details catch people out. GeoJSON puts longitude first and latitude second, while Leaflet's own API takes latitude first. Mixing them up puts your marker in the wrong ocean. And because GeoJSON is a standard, the same data works with Leaflet, with other map libraries and with spatial databases later, so the format choice costs nothing now and keeps options open.

Mobile touch is the real test

On a desktop the map is easy. On a phone, a full-width map can trap a scrolling thumb: the visitor tries to scroll past, the map starts to pan, and the page stops moving. Testing on a real phone shows this quickly, and it is worth designing for early. Give the map a bounded height and leave room around it so the page can still be scrolled past it.

The trade-off I accepted

Leaflet draws raster tiles, which are small images stitched together. Compared with WebGL vector-tile libraries, zooming is less fluid and the map's styling is harder to customise. For a content-led travel site with a modest number of destinations, I was happy to take simplicity, a small footprint and no API key. If a project needed heavy custom styling or thousands of live points, I would revisit that choice.

What I took from it

1. **Isolate the map.** Give it its own component and its own failure state, so a tile problem never breaks the page. 2. **Use standard data formats.** GeoJSON keeps your place data portable. Remember the longitude-first order. 3. **Test touch scrolling on a real phone.** It is the first thing that goes wrong with an embedded map. 4. **Choose the lighter tool when it is enough.** A simpler map library was the right fit for this kind of content.

Explore the Travelogue project or see my other [frontend and interactive projects](/projects).

Trade-offs

I chose Leaflet and OpenStreetMap over a vector-tile WebGL library. Leaflet is small and simple, and OpenStreetMap needs no paid key. The cost is raster tiles: zooming is less fluid than a WebGL map, and the visual style is harder to customise. For a content-led travel site that was the right trade.

Challenges faced

Keeping the page usable when tiles fail to load, and stopping the map from trapping touch scrolling on mobile.