How to Fill Country Polygons in OHM?

Hi all,

I’m using MapLibre GL JS with the OpenHistoricalMap style and trying to highlight entire countries — not just their borders — by filling the country polygons with a colour.

Right now, I’m successfully rendering the country boundary lines using the land_ohm_lines layer with this code:

map.addLayer({
  id: "country-boundaries",
  type: "line",
  source: "osm",
  "source-layer": "land_ohm_lines",
  filter: ["in", ["get", "admin_level"], ["literal", [1, 2]]],
  layout: {
    "line-join": "round",
    "line-cap": "round",
  },
  paint: {
    "line-color": "#FF0000",
    "line-width": 2,
  },
});

This works great for outlining countries, but I haven’t been able to find a layer that includes polygon features for entire countries, so I can fill them in (e.g. with a semi-transparent colour) on hover.

I’ve checked the style JSON and the full list of layers — tried a few landuse_areas_* and place_areas_* layers — but none seem to correspond to actual country-level fill polygons.

Does such a layer exist in the OHM layers list? Or is there another recommended approach for filling in countries based on the available data?

Thanks in advance!

Howdy @rbsam! :cowboy_hat_face: Welcome to the OHM Forum. Glad to see you here!

We switched from boundary polygons to boundary lines for a variety of performance reasons.

Can you share a little more of your workflow and use case? Are you doing this with time (I.e., using our vector tiles for all time) or just looking at specific points in time for a static rendering? And, are you code-savvy?

If this is for a zoom-constrained static display, the conversion from JSON lines to polygons seems pretty straightforward, although I haven’t used this in production myself…

Unfortunately, as @jeffmeyer mentioned, the vector tiles no longer contain boundaries as polygons. They only contain boundary edges as linear features, but without enough information to reconstruct polygons even manually.

On the bright side, the underlying data does have this information, and there are options for converting it to polygons. For example, if you want to highlight a country on click, you could query the Overpass API for the boundaries containing the clicked coordinates and convert the result to GeoJSON. There will be some lag while the query runs. You might want to cache the results to avoid running the same query multiple times.

If you need something that feels snappier on hover, you’d need to build your own low-resolution GeoJSON or vector tileset of country polygons. Tools like Planetiler and Tippecanoe can be useful for this purpose. The entire set of country boundaries in OHM is gigantic, but you could limit it to low admin_level=* values or certain countries of interest to make it more manageable. For completeness, I opened the following issue describing how we could facilitate your use case without you having to build anything custom:

1 Like