-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow passing custom themes to create layers (#234)
* Allow passing custom themes to create layers 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 color theme to create layers, without interfering with the final style. Also passing partial themes is possible to override only a small set of properties. * Apply biome lint fixes
- Loading branch information
Showing
4 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
dist | ||
dist | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import assert from "node:assert"; | ||
import { test } from "node:test"; | ||
import { validateStyleMin } from "@maplibre/maplibre-gl-style-spec"; | ||
import { | ||
labelsWithCustomTheme, | ||
layersWithPartialCustomTheme, | ||
} from "../src/index"; | ||
import themes from "../src/themes"; | ||
|
||
const STUB = { | ||
version: 8, | ||
glyphs: "https://example.com/{fontstack}/{range}.pbf", | ||
sources: { | ||
sourcename: { | ||
type: "vector", | ||
}, | ||
}, | ||
}; | ||
|
||
test("validate custom themes", () => { | ||
const customTheme = themes.dark; | ||
STUB.layers = labelsWithCustomTheme("sourcename", customTheme); | ||
const errors = validateStyleMin(STUB); | ||
assert.deepStrictEqual([], errors); | ||
}); | ||
|
||
test("validate layers with partial custom theme overrides", () => { | ||
const customBackgroundColor = "#fff"; | ||
const partialTheme = { background: customBackgroundColor }; | ||
STUB.layers = layersWithPartialCustomTheme( | ||
"sourcename", | ||
"dark", | ||
partialTheme, | ||
); | ||
const errors = validateStyleMin(STUB); | ||
assert.deepStrictEqual([], errors); | ||
assert.deepStrictEqual(STUB.layers.find((l) => l.id === "background").paint, { | ||
"background-color": customBackgroundColor, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters