A MapLibre GL JS client application designed to visualize and inspect local UK postcode boundary datasets stored in the PMTiles format. It utilizes the OpenFreeMap Bright basemap.
Mark Longair's Open Data GB postcode unit boundaries.
https://github.com/mhl/postcodes-mapit.
https://github.com/mysociety/mapit
This project was built with the hope of one day discussing it with Mark Longair, whose open data postcode work was its direct inspiration. Sadly, Mark passed away in January 2026 before that conversation could happen. His legacy in open source and civic technology is evident in every project that builds on what he created.
PMTiles derived from this file of GeoJSON:
https://postcodes-mapit-static.s3.eu-west-2.amazonaws.com/data/gb-postcodes-v5.tar.bz2
Because PMTiles works by fetching specific byte ranges directly from the server on-demand (via HTTP Range Requests), you must host both the HTML page and the PMTiles files using a local web server that supports:
- HTTP Range Requests
- CORS (Cross-Origin Resource Sharing)
You can start a lightweight web server in this directory using npx:
npx serve --cors -p 8080 .After launching, open your browser and navigate to: http://localhost:8080
This repository includes helper scripts to build the GB postcode PMTiles files.
-
download.sh- Downloads the raw
gb-postcodes-v5dataset archive. - Use this first if you do not already have
gb-postcodes-v5/.
- Downloads the raw
-
clip_data.sh- Clips the raw postcode GeoJSON files to the Great Britain coastline.
- Outputs clipped GeoJSON into
gb-postcodes-v5-clipped/. - This is optional, but recommended if you want coastline-clean postcode boundaries.
-
create_pmtiles.sh- Generates MBTiles from
gb-postcodes-v5/, then converts them into PMTiles. - Use this when you do not need coastline clipping.
- Outputs:
gb_areas.pmtiles,gb_districts.pmtiles,gb_sectors.pmtiles,gb_units.pmtiles.
- Generates MBTiles from
-
create_pmtiles_clipped.sh- Generates MBTiles from
gb-postcodes-v5-clipped/, then converts them into PMTiles. - Use this after
clip_data.shif you want clipped boundaries in your PMTiles. - Outputs:
gb_areas.pmtiles,gb_districts.pmtiles,gb_sectors.pmtiles,gb_units.pmtiles.
- Generates MBTiles from
-
If you want raw PMTiles:
./download.sh(if needed)../create_pmtiles.sh.
-
If you want coastline-clipped PMTiles:
./download.sh(if needed)../clip_data.sh../create_pmtiles_clipped.sh.
If you already have gb-postcodes-v5/ and do not want clipped output, skip clip_data.sh.
- OpenFreeMap Integration: Uses OpenFreeMap's zero-key, high-speed Bright style vector basemap.
- Layer Visibility Toggles: Enable/disable each of the three dataset layers dynamically.
- Dynamic Styling Controls: Customize fill color, fill opacity, outline color, and outline thickness in real-time.
- Clicked Feature Inspector: Click on any postcode region to query and view its attributes in a clean key-value table.
- PMTiles Header Metadata: Parses and displays internal PMTiles metadata (bounding box, zoom level ranges, format, etc.) using range requests.
The PMTiles produced are available as a HuggingFace dataset at:
https://huggingface.co/datasets/markmclaren/mapit-postcode-pmtiles
You may use this data under the Open Government License v3.0, and must include the following copyright notices:
Contains OS data © Crown copyright and database right 2020.
Contains Royal Mail data © Royal Mail copyright and database right 2020.
Source: Office for National Statistics licensed under the Open Government Licence v.3.0.