feat(map): add five-source drainage styling

This commit is contained in:
2026-07-10 18:45:43 +08:00
parent 2258177726
commit 513c403017
19 changed files with 1303 additions and 182 deletions
+47 -27
View File
@@ -1,10 +1,15 @@
import type { Map as MapLibreMap } from "maplibre-gl";
import type { BaseLayerOption } from "@/features/map/core/components/base-layers-control";
import type { MapLayerControlItem } from "@/features/map/core/components/layer-control";
import type { MapLegendItem } from "@/features/map/core/components/legend";
import { DRAINAGE_SOURCE_COLORS } from "./map-colors";
import {
SOURCE_LAYERS,
WATER_NETWORK_SOURCE_IDS,
type WaterNetworkSourceId
} from "./sources";
export const WORKBENCH_LAYER_GROUPS: Record<string, string[]> = {
pipes: ["pipes-casing", "pipes-flow", "pipes-risk-glow", "pipes-hover"],
junctions: ["junctions-halo", "junctions", "junctions-hover"],
simulation: [
"simulation-impact-fill",
"simulation-impact-outline",
@@ -18,16 +23,28 @@ export const WORKBENCH_LAYER_GROUPS: Record<string, string[]> = {
};
export const INITIAL_LAYER_VISIBILITY: Record<string, boolean> = {
pipes: true,
conduits: true,
junctions: true,
orifices: true,
outfalls: true,
pumps: true,
simulation: false
};
const SOURCE_CONTROL_LABELS: Record<WaterNetworkSourceId, { label: string; description: string }> = {
conduits: { label: "管渠", description: `lingang:${SOURCE_LAYERS.conduits}` },
junctions: { label: "检查井", description: `lingang:${SOURCE_LAYERS.junctions}` },
orifices: { label: "孔口", description: `lingang:${SOURCE_LAYERS.orifices}` },
outfalls: { label: "排放口", description: `lingang:${SOURCE_LAYERS.outfalls}` },
pumps: { label: "泵", description: `lingang:${SOURCE_LAYERS.pumps}` }
};
export const MAP_LEGEND_ITEMS: MapLegendItem[] = [
{ id: "major-pipe", label: "DN600 及以上管线", color: "#0477bf", shape: "line" },
{ id: "medium-pipe", label: "DN300-DN600 管线", color: "#0aa6a6", shape: "line" },
{ id: "minor-pipe", label: "DN300 以下管线", color: "#3dbf7f", shape: "line" },
{ id: "junction-demand", label: "节点需水强度", color: "#f25f5c", shape: "dot" },
{ id: "conduit", label: "管渠(线宽表示口径)", color: DRAINAGE_SOURCE_COLORS.conduits, shape: "line" },
{ id: "junction", label: "检查井", color: DRAINAGE_SOURCE_COLORS.junctions, shape: "dot" },
{ id: "orifice", label: "孔口", color: DRAINAGE_SOURCE_COLORS.orifices, shape: "line" },
{ id: "pump", label: "", color: DRAINAGE_SOURCE_COLORS.pumps, shape: "line" },
{ id: "outfall", label: "排放口", color: DRAINAGE_SOURCE_COLORS.outfalls, shape: "dot" },
{ id: "impact-area", label: "影响范围", color: "#ef4444", shape: "square" }
];
@@ -55,24 +72,27 @@ export const BASE_LAYER_OPTIONS: BaseLayerOption[] = [
];
export function createLayerControlItems(layerVisibility: Record<string, boolean>): MapLayerControlItem[] {
return [
{
id: "pipes",
label: "管线",
description: "主干、支线与风险高亮",
visible: layerVisibility.pipes
},
{
id: "junctions",
label: "节点",
description: "用水节点与悬停反馈",
visible: layerVisibility.junctions
},
{
id: "simulation",
label: "模拟结果",
description: "影响范围与事故标注",
visible: layerVisibility.simulation
}
];
return WATER_NETWORK_SOURCE_IDS.map((sourceId) => ({
id: sourceId,
...SOURCE_CONTROL_LABELS[sourceId],
visible: layerVisibility[sourceId]
}));
}
export function getWorkbenchLayerIds(
map: Pick<MapLibreMap, "getStyle">,
layerControlId: string
) {
if (isWaterNetworkSourceId(layerControlId)) {
return map
.getStyle()
.layers.filter((layer) => "source" in layer && layer.source === layerControlId)
.map((layer) => layer.id);
}
return WORKBENCH_LAYER_GROUPS[layerControlId] ?? [];
}
function isWaterNetworkSourceId(value: string): value is WaterNetworkSourceId {
return (WATER_NETWORK_SOURCE_IDS as readonly string[]).includes(value);
}