September 13th, 2024

I Added SVG Maps to My Travel Posts

Josh Erb enhanced his travel blog by adding SVG maps using 11ty and d3-geo, focusing on performance and consistency, with plans for future geographical details and interactivity.

Read original articleLink Icon
I Added SVG Maps to My Travel Posts

Josh Erb recently enhanced his travel blog by adding maps to the top of his posts, motivated by a personal affinity for maps and nostalgia from his early blogging experiences. He outlined three main requirements for this feature: avoiding third-party platforms, generating maps at build time for performance, and ensuring consistent appearance across devices. To implement this, he utilized the 11ty static site generator and created a shortcode to integrate maps into his blog's template. He chose to generate maps as SVGs using the d3-geo library, which allowed him to convert geographic data into SVG paths. He also organized location data in a JSON file to streamline the mapping process. The final implementation includes styled SVG elements that adapt to different screen sizes. Looking ahead, Erb considers adding more geographical details, an overview map of all locations, and potential interactivity to the maps. He reflects on the evolution of his blogging journey and the enduring nature of the internet.

- Josh Erb added maps to his travel blog for personal and nostalgic reasons.

- He established requirements to avoid third-party dependencies and ensure performance.

- The implementation involved using 11ty and d3-geo to generate SVG maps.

- Future enhancements may include more geographical data and interactivity.

- Erb appreciates the longevity of his early blogging platform and the evolving nature of online content.

Link Icon 9 comments
By @kylehotchkiss - 5 months
I love this Josh! I recently discovered Protomaps (https://protomaps.com) and have been having a lot of fun doing mapping without paying Google or Mapbox a small fortune for the privilege. I found the the basemaps look much better than the protomaps site makes them appear (they're super zoomed out in the samples where the styles don't come together as well as they do when zoomed in)
By @lelandfe - 5 months
Super neat, the end result looks great and adds a lot to the posts. On the downside, inlining the map causes the HTML to balloon up to ~500kB/~180kB gzipped, compared to 30kB/10kB on this post (which lacks a map). The site is already insanely fast, but you could pull the map SVG into an actual file, so it's cached between pages, and becomes a lower-priority resource (which will ~halve First Contentful Paint). Then you'd just position the circle on top of that generic map file!
By @mbforbes - 5 months
Really impressive! I've implemented a few kinds of maps on my blog, and I fail all of their requirements:

- I use a 3rd party platform

- My maps are generated at runtime

- They looks... let's say vaguely consistent on mobile & desktop

Maps were the most painful and time-consuming part of building a travel blog, but also perhaps the most satisfying.

By @throw0101c - 5 months
It would be cool if OpenStreetMap (OSM) could do something like a 'print/export to SVG' for whatever is on currently the screen.
By @kymikz - 5 months
Great post!

I had myself this itch to scratch and ended up making an overly over-engineered tool to do just that: https://cartosvg.com/

I think it might interest you as it covers all your use cases (except the responsiveness part maybe), and personally I thin it can lead to quite beautiful results :)

Cheers!

By @loremm - 5 months
Also if the author views this, would love an rss feed. Can use the github pretty easily but maybe commits have updates, not new blog posts
By @djangelic - 5 months
Great post, love the amount of thought that went into this! I look forward to keeping up with your posts.
By @apsurd - 5 months
what a great looking website.

love the craft. now I need to set aside some time to read the post… !

By @bebna - 5 months
I like it, thanks.