Skip to content

feat: added custom layer editor to tiles panel#354

Merged
nilsnolde merged 8 commits intovalhalla:masterfrom
s4chinjha:feature/custom-layer-viz
Mar 12, 2026
Merged

feat: added custom layer editor to tiles panel#354
nilsnolde merged 8 commits intovalhalla:masterfrom
s4chinjha:feature/custom-layer-viz

Conversation

@s4chinjha
Copy link
Contributor

@s4chinjha s4chinjha commented Mar 6, 2026

🛠️ Fixes Issue

Closes #323


👨‍💻 Changes proposed

  • Added a store to keep track of custom layers the user adds
  • Added a dialog with a JSON text area where users can paste a MapLibre layer definition and add it to the map
  • The dialog validates the input before adding,checks for valid JSON, a string id field, and that the id is not already on the map
  • Custom layers show up in their own section at the bottom of the Tiles panel with a visibility toggle and a remove button
  • Custom layers survive map style reloads, they get re-applied automatically
  • Custom layers referencing valhalla-tiles survive the Valhalla source being toggled off and back on
  • Fixed a bug where custom layers were showing up inside standard layer groups as well as the Custom Layers section
  • Added accessible labels so screen readers can identify the toggle and remove buttons for each layer
  • Added 47 new tests, 836 passing in total

📷 Screenshots

Before (standard tiles)

Screenshot From 2026-03-07 19-11-03

After (custom layer added)

Screenshot From 2026-03-07 19-10-59

Layer definition used above:

{
  "id": "edges-highlight",
  "type": "line",
  "source": "valhalla-tiles",
  "source-layer": "edges",
  "paint": {
    "line-color": "#ff0000",
    "line-width": 2
  }
}

This highlights all the edges in red.


📄 Note to reviewers

  • Layers are lost on page refresh, no persistent storage yet

AI Contribution:
I've used AI assistance to help me write most of the code & for debugging the code.
I've reviewed every change, ran all the tests myself, and manually verified the feature works properly.

@ghost
Copy link

ghost commented Mar 6, 2026

Preview is ready! 🚀 You can view it here: https://valhalla-app-tests.gis-ops.com/354

@nilsnolde
Copy link
Member

remember to un-draft PRs when you want to be reviewed! if it is ready, then we're missing a real proof, e.g. providing a style.json for some custom layer.

@s4chinjha s4chinjha marked this pull request as ready for review March 7, 2026 13:52
Copy link
Member

@nilsnolde nilsnolde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is really cool! cc @chrstnbwnkl

one change: unless "Append Valhalla layers" is active, the new button shouldn't be active IMO, bcs that's a no-op.


export const CustomLayerEditor = () => {
const { mainMap } = useMap();
const addLayer = useCustomLayersStore((state) => state.addLayer);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to introduce new stores to the project, the old "directions", "isochrone" stores are artifacts from redux.

Usage of zustand stores in this component is totally unnecessary.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This store shouldn't be exist at all.

const addLayer = useCustomLayersStore((state) => state.addLayer);
const layers = useCustomLayersStore((state) => state.layers);
const [open, setOpen] = useState(false);
const [json, setJson] = useState('');
Copy link
Collaborator

@mustaphaturhan mustaphaturhan Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's call it value or jsonValue

};

return (
<div className="pb-1">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this div is in the correct place. Where we are adding the padding? To the content of dialog, or to the trigger?

@s4chinjha
Copy link
Contributor Author

@nilsnolde @mustaphaturhan here i have tried to implement the changes suggested
In the first commit i've renamed json to jsonValue, removed the extra div wrapper and disabled the add Custom Layer button when Append Valhalla layers is off.
And in the second commit i've removed the custom-layers-store.

Also i've updated the tests accordingly.

nilsnolde
nilsnolde previously approved these changes Mar 10, 2026
Copy link
Member

@nilsnolde nilsnolde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, thanks!

tiny nit: once I add a custom layer and disable Valhalla layers, the "add" button is still active. that's just a small nit, meaning if it's quick to do, pls do, but if it's more than 2 lines of code, just don't:)

@s4chinjha
Copy link
Contributor Author

nice, thanks!

tiny nit: once I add a custom layer and disable Valhalla layers, the "add" button is still active. that's just a small nit, meaning if it's quick to do, pls do, but if it's more than 2 lines of code, just don't:)

Thanks for the nit! I went ahead and fixed it.

Copy link
Member

@nilsnolde nilsnolde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great, thanks!

@nilsnolde nilsnolde enabled auto-merge (squash) March 12, 2026 12:56
@nilsnolde nilsnolde disabled auto-merge March 12, 2026 18:50
@nilsnolde nilsnolde merged commit ab5bf08 into valhalla:master Mar 12, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable customizing tile viz

3 participants