DEV Community

Giorgos Sarigiannidis
Giorgos Sarigiannidis

Posted on

Building an OpenStreetMap Gutenberg block for WordPress and rethinking the UX of adding locations

Google Maps is great and the free quota is more than enough, but having to ask your clients to register, and provide a valid credit card to use the API, can cause some inconvenience and even cost you a few extra hours of work just to provide support, making sure that the setup is successful.

So, I thought I'd build a map block for Gutenberg that uses OpenStreetMap and Leaflet.js. It needs no API keys and works out of the box (or, out of the Block, if you prefer). Benefiting from Gutenberg's potential, the plugin tries a different take on how to add your locations on the map and rethinks a few things, UX-wise.

Instead of manually adding coordinates for each marker, just click-and-drop them directly on the map, and drag to adjust their position. Instead of filling-in custom fields to set each marker's popup content, just open that popup and start writing in it, the Gutenberg way (it supports WYSIWYG editing, with links, images, and all). It can also store the map's zoom level as you use it so that you don't have to set it by hand.

Features

  • No need for API keys. Just install and use it.
  • Support for multiple markers.
  • Dead-simple interface. Don't search for coordinates and don't get overwhelmed by too many fields when using multiple markers. Just point and click on the map to add your marker where you want it and edit it's popup content directly from there.
  • Remembers the zoom that you set when adding the markers and stores it so that you don't set it by hand (which you can do anyway if you prefer).
  • Adjust the map height.
  • Change the default marker icon with a custom one.
  • Enable or disable map dragging.
  • Enable or disable touch zoom.
  • Enable or disable double-click zoom.
  • Enable or disable scroll wheel zoom.
  • Set a minimum and maximum limit that the user can zoom on the frontend. Setting the same value to both fields will lock the zoom at that level.

If you are interested to give it a try, you can find it here:

PS: For those who would like to read a few more details, I've also written an article regarding a few interesting UX challenges that I've came across during its development. As I explain there, I believe that the location search with autocomplete capabilities is an essential tool for the plugin’s UI to be complete. It’s a big feature, though, which needs some good thinking and careful implementation to make it as user-friendly as possible. So, I thought I’d release that basic version first, so that people start using it, and fix possible bugs before continuing to implement new features.

Top comments (0)