protomaps / basemaps

Basemap PMTiles generation and cartographic styles for OpenStreetMap data and more
https://maps.protomaps.com/
Other
347 stars 44 forks source link

Allow passing custom themes to create layers #234

Closed Edefritz closed 4 months ago

Edefritz commented 5 months ago

So far it was only possible to generate styles based on a set of fixed themes maintained by the protomaps project.

With this change, it is possible to pass a custom colour theme to create layers, without interfering with the final style. Also passing partial themes is possible to override only a small set of properties.

Example:

const myCustomTheme: Theme = {...}
const style = layersWithCustomTheme("protomaps", myCustomTheme)

or

const partialTheme: Partial<Theme> = { background: "#fff" };
const style = layersWithPartialCustomTheme(
    "protomaps",
    "dark", // use dark theme as base
    partialTheme
);

Related issue: https://github.com/protomaps/basemaps/issues/224

This is just my take on addressing this problem. Please let me know if you have any suggestions or if you think some of these changes aren't necessary. And feel free to edit or rename anything.

Thanks :)

sonarcloud[bot] commented 5 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

bdon commented 4 months ago

I like the partial theme solution, though I'm trying to imagine the use case where you want to change only one color - it seems more likely we will want a way to selectively remove a layer completely instead of just change the color values. Is the partial theme solution as implemented here enough for your use case?

bdon commented 4 months ago

Thanks!