basemaps icon indicating copy to clipboard operation
basemaps copied to clipboard

Allow passing custom themes to create layers

Open Edefritz opened this issue 1 year ago • 1 comments

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 :)

Edefritz avatar Apr 08 '24 14:04 Edefritz

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

sonarqubecloud[bot] avatar Apr 09 '24 07:04 sonarqubecloud[bot]

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 avatar May 08 '24 06:05 bdon

Thanks!

bdon avatar May 10 '24 07:05 bdon