Merge pull request #1710 from bluewave-labs/feat/fe/du-map-theme

feat: fe/du map theme
This commit is contained in:
Alexander Holliday authored and GitHub committed 2025-02-06 14:01:23 -08:00
commit cb2f7e26ad
5 files changed
+232 -169

No files matched your search

+1
View File
@@ -3,3 +3,4 @@
*.sh *.sh
!uptime.sh !uptime.sh
*.idea *.idea
*.notes
@@ -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,33 @@
import baseStyle from "./DistributedUptimeMapStyle.json";
const buildStyle = (theme, mode) => {
const style = JSON.parse(JSON.stringify(baseStyle));
if (mode === "dark") {
return baseStyle;
}
if (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;
@@ -2,13 +2,18 @@ import "maplibre-gl/dist/maplibre-gl.css";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { useRef, useState, useEffect } from "react"; import { useRef, useState, useEffect } from "react";
import { useTheme } from "@mui/material/styles"; import { useTheme } from "@mui/material/styles";
import style from "./DistributedUptimeMapStyle.json";
import maplibregl from "maplibre-gl"; import maplibregl from "maplibre-gl";
import { useSelector } from "react-redux";
import buildStyle from "./buildStyle";
const DistributedUptimeMap = ({ width = "100%", height = "100%", checks }) => { const DistributedUptimeMap = ({ width = "100%", height = "100%", checks }) => {
const mapContainer = useRef(null); const mapContainer = useRef(null);
const map = useRef(null); const map = useRef(null);
const theme = useTheme(); const theme = useTheme();
const [mapLoaded, setMapLoaded] = useState(false); const [mapLoaded, setMapLoaded] = useState(false);
const mode = useSelector((state) => state.ui.mode);
const initialTheme = useRef(theme);
const initialMode = useRef(mode);
const colorLookup = (avgResponseTime) => { const colorLookup = (avgResponseTime) => {
if (avgResponseTime <= 150) { if (avgResponseTime <= 150) {
@@ -22,11 +27,13 @@ const DistributedUptimeMap = ({ width = "100%", height = "100%", checks }) => {
useEffect(() => { useEffect(() => {
if (mapContainer.current && !map.current) { if (mapContainer.current && !map.current) {
const initialStyle = buildStyle(initialTheme.current, initialMode.current);
map.current = new maplibregl.Map({ map.current = new maplibregl.Map({
container: mapContainer.current, container: mapContainer.current,
style, style: initialStyle,
center: [0, 20], center: [0, 20],
zoom: 0.8, zoom: 0.8,
attributionControl: false,
}); });
} }
map.current.on("load", () => { map.current.on("load", () => {
@@ -41,6 +48,13 @@ const DistributedUptimeMap = ({ width = "100%", height = "100%", checks }) => {
}; };
}, []); }, []);
useEffect(() => {
const style = buildStyle(theme, mode);
if (map.current && mapLoaded) {
map.current.setStyle(style);
}
}, [theme, mode, mapLoaded]);
useEffect(() => { useEffect(() => {
if (map.current && checks?.length > 0) { if (map.current && checks?.length > 0) {
// Convert dots to GeoJSON // Convert dots to GeoJSON
+15
View File
@@ -251,6 +251,21 @@ const newSemanticColors = {
dark: paletteColors.gray850, dark: paletteColors.gray850,
}, },
}, },
map: {
main: {
light: newColors.offWhite,
dark: undefined,
},
lowContrast: {
light: newColors.gray200,
dark: undefined,
},
highContrast: {
light: newColors.gray500,
dark: undefined,
},
},
}; };
export { typographyLevels, semanticColors as colors, newSemanticColors }; export { typographyLevels, semanticColors as colors, newSemanticColors };