Step 6 - Configure the Stylesheet
Now we'll update our Maplibre to load PMtiles support, and configure the stylesheet to match the Protomaps tiles we downloaded.
Configure the Stylesheet
We need to modify our stylesheet style.json to:
- Use the local PMTiles file
- Show the Protomaps basemap layers
- Also show your existing trail layer
View the Protomaps Stylesheet in Maputnik
Maputnik allows you to edit the style layers in a GUI, which is helpful since the stylesheet is otherwise over 12,000 lines of JSON when formatted in your text editor.
Maputnik also allows you to make changes and see the results live, without having to switch windows or refresh a browser pane. This is particularly helpful when you are developing a style layer from scratch.
Maputnik is maintained by Maplibre as a way of making it easier to understand available style parameters.
- Go to https://maplibre.org/maputnik/ to view the Maputnik style editor.
- Load the Protomaps Light style under Open > Gallery Styles > Protomaps Light.
- In the map panel on the right pan and zoom in on Auckland, then find Waiheke Island
- Change from Map to Inspect from the drop-down in the top bar, this will allow you to hover and see all of the tile layers and attributes
- Change back from Inspect to Map from the drop-down in the top bar
- Click on Expand in the top left corner to see all the map layers
You should now see the fully expanded list of layers defined in the Protomaps stylesheet. It is a lot!
Note: Maplibre renders these layers in order from top to bottom, so the last layer in the list will render on top.
The position a layer has in the render order is commonly referred to as the z-order
Observe the z-orders of various layers in this stylesheet. For any basemap the order will generally be:
- Landcover (areas) on the bottom
- Roads / Streams (lines) in the middle
- Labels and Icons (points) on the top
Add Te Ara Hura
We're going to use Maputnik to add the trail styles from style.json in Step 3 into the Protomaps style sheet here.
Here's the style.json from Step 3:
{
"version": 8,
"sources": {
"te-ara-hura": {
"type": "geojson",
"data": "sources/te_ara_hura.geojson"
}
},
"layers": [
{
"id": "trail-line",
"type": "line",
"source": "te-ara-hura",
"paint": {
"line-color": "#e41f18",
"line-width": 3,
"line-dasharray": [2, 2]
}
}
]
}
Important for everyone: Make sure Caddy is still running. If not, enter caddy run in the terminal.
Important for Codespaces users: You need to make your port public so Maputnik can access your server.
-
In the Codespaces "Ports" tab, right-click on port 1234 (or click the globe icon) and select "Port Visibility" → "Public". This allows Maputnik to access your GeoJSON and other files.
-
Allow Access when you get a browser prompt saying Maputnik is requesting access to your local server (or Codespaces server).
Add the GeoJSON Source
-
Click on Data Sources in the top bar of Maputnik. In the panel that pops up, you will see #protomaps listed under Active Sources
-
Add New Source at the bottom of the panel. Here you are going to input the fields from the
style.jsonwe introduced in Step 3.Source IDiste-ara-hura- Under
Source Typeuse the drop-down to select "GeoJSON (URL)" - Go to the browser tab where you are previewing your map either locally and in codespaces, and type
sources/te_ara_hura.geojsonat the end of the URL to verify you can see the GeoJSON file there. - If not, restart Caddy
- Ctrl+C or Cmd+C to copy the URL to your clipboard
- Under
URLpaste:- If using local Caddy: it will look like
http://127.0.0.1:1234/sources/te_ara_hura.geojson - If using GitHub Codespaces: it will look like
https://xxxxx-1234.preview.app.github.dev/sources/te_ara_hura.geojson)
- If using local Caddy: it will look like
Add a Trail Layer
-
Click "Add Layer" at the top of the list of layers
-
Input the id, type, and source as defined in the
style.jsonfrom Step 3 -
Input the color, width and dasharray as defined in the
style.jsonfrom Step 3 -
Scroll to the JSON Editor at the bottom of the Add Layer panel. Click the > to expand.
You should see a layer definition like this. If you don't, you can copy and paste this into the JSON box at the bottom of the new layer panel:
{
"id": "trail-line",
"type": "line",
"source": "te-ara-hura",
"paint": {
"line-color": "#e41f18",
"line-width": 3,
"line-dasharray": [2, 2]
}
}
You should also see the trail as a red dashed line circling Waiheke Island.
Adjust the Z-Order
Let's fix the fact that the red dashed trail line is currently rendering on top of all our labels, and bisecting the Waiheke Island Aerodrome.
-
Note the symbols at the start of each layer: diamond for area layers, squiggle for line layers, marker for point layers.
-
Find the layer you just created at the bottom of the list of layers. Note the squiggle next to it, because this is a line layer
-
Drag Te Ara Hura to group it as the last of the line layers, so that it renders on top of roads and rivers, but under the labels.
Scroll to the bottom of this page, what you see in Maputnik should match the image you see below.
Export, Save and Edit
Now we are going to save the stylesheet you created in Maputnik to your local copy of the workshop repo (e.g. not in Codespaces).
Important: If you're working locally and have made changes in Codespaces (or vice versa), update your local repository in VS Code before overwriting style.json:
- Using VS Code GUI: Open the Source Control panel (View → Source Control, or
Ctrl+Shift+G/Cmd+Shift+G), click the...menu, and select "Pull" - Using command line: Open the terminal (View → Terminal) and run
git pull
Now you're ready to save your stylesheet:
-
Click "Save" at the top to save this stylesheet back into the repo. You can name it
style.jsonand overwrite the earlier file at this point. -
Open
style.jsonas a text file and adjust the addresses for yoursources,glyphs, andfonts- Under
sources,protomapsdelete thetype,tilesandmaxzoomrows with"url": "pmtiles://sources/waiheke_island.pmtiles" - Retain the attribution for Protomaps and OpenStreetMap
- Under
sources, remove the server address (eitherhttp://127.0.0.1:1234/for local Caddy or your Codespaces forwarded URL) from the beginning of the url for the Te Ara Hura GeoJSON - (Optional/Recommended): Replace the
glyphsaddress withlib/fonts/{fontstack}/{range}.pbfto reference the fonts in your repo - (Optional/Recommended): Replace the
spriteaddress withhttps://YOUR-USERNAME.github.io/standalone_web_maps_foss4g2025/lib/sprite/lightwhereYOUR-USERNAMEis your github handle
- Under
-
Check the final result, it should look like the JSON below.
{
"version": 8,
"name": "style@4.3.0 theme@light lang@en",
"sources": {
"te-ara-hura": {
"type": "geojson",
"data": "sources/te_ara_hura.geojson"
},
"protomaps": {
"type": "vector",
"url": "pmtiles://sources/waiheke_island.pmtiles",
"attribution": "© <a href=\"https://openstreetmap.org\" target=\"_blank\" rel=\"noopener noreferrer\">OpenStreetMap</a>"
}
},
"sprite": "https://YOUR-USERNAME.github.io/standalone_web_maps_foss4g2025/lib/sprite/light",
"glyphs": "lib/fonts/{fontstack}/{range}.pbf",
"layers": [
...
],
}
- Save your changes in the project file on your hard drive.
Further instructions for Codespaces: You need to commit and push your local changes, then pull them in Codespaces:
-
In your local VS Code: Commit and push your
style.jsonchanges- Using VS Code GUI: Open Source Control panel, stage
style.json, enter a commit message, and click "Commit", then "Sync Changes" (or "Push") - Using command line: Run
git add style.json,git commit -m "Update style.json with Protomaps configuration", thengit push
- Using VS Code GUI: Open Source Control panel, stage
-
In Codespaces: Pull the latest changes
- Using VS Code GUI: Open Source Control panel, click the
...menu, and select "Pull" - Using command line: Run
git pull
- Using VS Code GUI: Open Source Control panel, click the
Test Your Map
-
Check to make sure your server is still running, if not type
caddy runin a terminal window (from your repository root directory). -
Refresh your browser:
- If using local Caddy: Go to
http://127.0.0.1:1234/index.html - If using GitHub Codespaces: Use your forwarded URL (e.g.,
https://xxxxx-1234.preview.app.github.dev/index.html)
- If using local Caddy: Go to
-
You should see no change yet! Verify you still see the trail line. We have to define the styles for the PMTiles Protomaps layers before they will show up.
Add PMTiles Support
Update your index.html to load PMTiles support.
- Add the
srclink for the PMTiles library stored inlib/. Add it to the<head>section, just below the local copies of Maplibre GL JS, and notice they are structured similarly.
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Te Ara Hura Trail Map</title>
<!-- Local copies of MapLibre GL JS -->
<script src="lib/maplibre-gl.5.10.0.js"></script>
<link href="lib/maplibre-gl.5.10.0.css" rel="stylesheet" />
<!-- PMTiles support -->
<script src="lib/pmtiles.4.3.0.js"></script>
- Activate the PMTiles protocol by adding these lines just above where the map is defined:
<script>
// Initialize PMTiles protocol
const protocol = new pmtiles.Protocol();
maplibregl.addProtocol("pmtiles", protocol.tile);
// Javascript to create a new map using Maplibre GL JS
const map = new maplibregl.Map({
...})
</script>
- Save your changes to your project file, either locally or in Codespaces.
Test Your Map
-
Check to make sure your server is still running, if not type
caddy runin a terminal window (from your repository root directory). -
Refresh your browser:
- If using local Caddy: Go to
http://127.0.0.1:1234/index.html - If using GitHub Codespaces: Use your forwarded URL (e.g.,
https://xxxxx-1234.preview.app.github.dev/index.html)
- If using local Caddy: Go to
-
You should see:
- The Protomaps basemap (roads, labels, landcover)
- Proper styling with icons and fonts
- The Te Ara Hura trail displayed on top
Troubleshooting
Map doesn't load?
- Check developer console for errors
- Verify
style.jsonexists in root directory - Verify file paths in stylesheet are correct
PMTiles not loading?
- Verify
sources/waiheke_island.pmtilesexists - Check that PMTiles protocol is initialized in
index.js - Verify the PMTiles URL in
style.jsonusespmtiles://protocol
Verify Your Directory Structure
You should now have all the files you need to render the map. Double-check it looks like this:
standalone_web_maps_foss4g2025/
├── README.md # This file
├── Makefile # Build and serve commands (uses Caddy)
├── index.html # Main HTML file for the web map (contains inline CSS and JavaScript)
├── style.json # Source and style for Te Ara Hura and the Protomaps tile layers, fonts and sprites
├── lib/ # Third-party libraries (self-contained)
└── sources/ # Source data files
├── waiheke_island.pmtiles # PMTiles archive for Waiheke Island basemap - added in later steps
└── te_ara_hura.geojson # GeoJSON file for Te Ara Hura trail
Commit Your Changes
Add, commit, and push your revised index.html and style.json to your remote fork, either from your hard drive or via Codespaces.
Verify that the map you see via your server (local or Codespaces) and the one you see via GitHub Pages match what you saw in Maputnik (image below).
What You Have Now
At the end of this step, you should have:
style.json- Protomaps basemap styles and your trail layer style- Map displaying Protomaps basemap with your trail layer
Your Map Preview
This is what your map should look like when you view it in Maputnik