Merge pull request #1710 from bluewave-labs/feat/fe/du-map-theme
feat: fe/du map theme
This commit is contained in:
4 files changed
+65
-2
No files matched your search
@@ -3,3 +3,4 @@
|
|||||||
*.sh
|
*.sh
|
||||||
!uptime.sh
|
!uptime.sh
|
||||||
*.idea
|
*.idea
|
||||||
|
*.notes
|
||||||
+33
@@ -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;
|
||||||
+16
-2
@@ -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
|
||||||
|
|||||||
@@ -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 };
|
||||||
Reference in new issue
Block a user