Add utility for building theme based on default theme

This commit is contained in:
Alex Holliday committed 2025-02-06 13:47:21 -08:00
1 parent 5ba4be57b2
commit ffa307aa38
2 files changed
+202 -168

No files matched your search

@@ -1,169 +1,169 @@
{ {
"id": "43f36e14-e3f5-43c1-84c0-50a9c80dc5c7", "id": "43f36e14-e3f5-43c1-84c0-50a9c80dc5c7",
"name": "MapLibre", "name": "MapLibre",
"zoom": 0.861983335785597, "zoom": 0.861983335785597,
"pitch": 0, "pitch": 0,
"center": [17.6543171043124, 32.9541203267468], "center": [17.6543171043124, 32.9541203267468],
"glyphs": "https://demotiles.maplibre.org/font/{fontstack}/{range}.pbf", "glyphs": "https://demotiles.maplibre.org/font/{fontstack}/{range}.pbf",
"layers": [ "layers": [
{ {
"id": "background", "id": "background",
"type": "background", "type": "background",
"paint": { "paint": {
"background-color": "#121217" "background-color": "#121217"
}, },
"filter": ["all"], "filter": ["all"],
"layout": { "layout": {
"visibility": "visible" "visibility": "visible"
}, },
"maxzoom": 24 "maxzoom": 24
}, },
{ {
"id": "coastline", "id": "coastline",
"type": "line", "type": "line",
"paint": { "paint": {
"line-blur": 0.5, "line-blur": 0.5,
"line-color": "#000000", "line-color": "#000000",
"line-width": { "line-width": {
"stops": [ "stops": [
[0, 2], [0, 2],
[6, 6], [6, 6],
[14, 9], [14, 9],
[22, 18] [22, 18]
] ]
} }
}, },
"filter": ["all"], "filter": ["all"],
"layout": { "layout": {
"line-cap": "round", "line-cap": "round",
"line-join": "round", "line-join": "round",
"visibility": "visible" "visibility": "visible"
}, },
"source": "maplibre", "source": "maplibre",
"maxzoom": 24, "maxzoom": 24,
"minzoom": 0, "minzoom": 0,
"source-layer": "countries" "source-layer": "countries"
}, },
{ {
"id": "countries-fill", "id": "countries-fill",
"type": "fill", "type": "fill",
"paint": { "paint": {
"fill-color": "#292929" "fill-color": "#292929"
}, },
"filter": ["all"], "filter": ["all"],
"layout": { "layout": {
"visibility": "visible" "visibility": "visible"
}, },
"source": "maplibre", "source": "maplibre",
"maxzoom": 24, "maxzoom": 24,
"source-layer": "countries" "source-layer": "countries"
}, },
{ {
"id": "countries-boundary", "id": "countries-boundary",
"type": "line", "type": "line",
"paint": { "paint": {
"line-color": "#484848", "line-color": "#484848",
"line-width": { "line-width": {
"stops": [ "stops": [
[1, 1], [1, 1],
[6, 2], [6, 2],
[14, 6], [14, 6],
[22, 12] [22, 12]
] ]
}, },
"line-opacity": { "line-opacity": {
"stops": [ "stops": [
[3, 0.5], [3, 0.5],
[6, 1] [6, 1]
] ]
} }
}, },
"layout": { "layout": {
"line-cap": "round", "line-cap": "round",
"line-join": "round", "line-join": "round",
"visibility": "visible" "visibility": "visible"
}, },
"source": "maplibre", "source": "maplibre",
"maxzoom": 24, "maxzoom": 24,
"source-layer": "countries" "source-layer": "countries"
}, },
{ {
"id": "countries-label", "id": "countries-label",
"type": "symbol", "type": "symbol",
"paint": { "paint": {
"text-color": "rgba(8, 37, 77, 1)", "text-color": "rgba(8, 37, 77, 1)",
"text-halo-blur": { "text-halo-blur": {
"stops": [ "stops": [
[2, 0.2], [2, 0.2],
[6, 0] [6, 0]
] ]
}, },
"text-halo-color": "rgba(255, 255, 255, 1)", "text-halo-color": "rgba(255, 255, 255, 1)",
"text-halo-width": { "text-halo-width": {
"stops": [ "stops": [
[2, 1], [2, 1],
[6, 1.6] [6, 1.6]
] ]
} }
}, },
"filter": ["all"], "filter": ["all"],
"layout": { "layout": {
"text-font": ["Open Sans Semibold"], "text-font": ["Open Sans Semibold"],
"text-size": { "text-size": {
"stops": [ "stops": [
[2, 10], [2, 10],
[4, 12], [4, 12],
[6, 16] [6, 16]
] ]
}, },
"text-field": { "text-field": {
"stops": [ "stops": [
[2, "{ABBREV}"], [2, "{ABBREV}"],
[4, "{NAME}"] [4, "{NAME}"]
] ]
}, },
"visibility": "visible", "visibility": "visible",
"text-max-width": 10, "text-max-width": 10,
"text-transform": { "text-transform": {
"stops": [ "stops": [
[0, "uppercase"], [0, "uppercase"],
[2, "none"] [2, "none"]
] ]
} }
}, },
"source": "maplibre", "source": "maplibre",
"maxzoom": 24, "maxzoom": 24,
"minzoom": 2, "minzoom": 2,
"source-layer": "centroids" "source-layer": "centroids"
}, },
{ {
"id": "data-dots", "id": "data-dots",
"type": "circle", "type": "circle",
"source": "data-dots", "source": "data-dots",
"paint": { "paint": {
"circle-radius": 3, "circle-radius": 3,
"circle-color": ["get", "color"], "circle-color": ["get", "color"],
"circle-opacity": 0.5 "circle-opacity": 0.5
} }
} }
], ],
"bearing": 0, "bearing": 0,
"sources": { "sources": {
"maplibre": { "maplibre": {
"url": "https://demotiles.maplibre.org/tiles/tiles.json", "url": "https://demotiles.maplibre.org/tiles/tiles.json",
"type": "vector" "type": "vector"
}, },
"data-dots": { "data-dots": {
"type": "geojson", "type": "geojson",
"data": { "data": {
"type": "FeatureCollection", "type": "FeatureCollection",
"features": [] "features": []
} }
} }
}, },
"version": 8, "version": 8,
"metadata": { "metadata": {
"maptiler:copyright": "This style was generated on MapTiler Cloud. Usage is governed by the license terms in https://github.com/maplibre/demotiles/blob/gh-pages/LICENSE", "maptiler:copyright": "This style was generated on MapTiler Cloud. Usage is governed by the license terms in https://github.com/maplibre/demotiles/blob/gh-pages/LICENSE",
"openmaptiles:version": "3.x" "openmaptiles:version": "3.x"
} }
} }
@@ -0,0 +1,34 @@
import baseStyle from "./DistributedUptimeMapStyle.json";
const buildStyle = (theme, mode) => {
const style = JSON.parse(JSON.stringify(baseStyle));
if (mode === "dark") {
return baseStyle;
}
if (style.layers) {
console.log(style.layers);
const newLayers = style.layers.map((layer) => {
if (layer.id === "background") {
layer.paint["background-color"] = theme.palette.map.main;
}
if (layer.id === "countries-fill") {
layer.paint["fill-color"] = theme.palette.map.lowContrast;
}
if (layer.id === "coastline") {
layer.paint["line-color"] = theme.palette.map.highContrast;
}
if (layer.id === "countries-boundary") {
layer.paint["line-color"] = theme.palette.map.highContrast;
}
return layer;
});
style.layers = newLayers;
}
return style;
};
export default buildStyle;