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 { GEOSERVER_WORKSPACE } from "../../../lib/config"; import { MAP_STYLE_TOKENS } from "./map-colors"; import { SOURCE_LAYERS, WATER_NETWORK_SOURCE_IDS, type WaterNetworkSourceId } from "./sources"; export const WORKBENCH_LAYER_GROUPS: Record = { simulation: [ "simulation-impact-fill", "simulation-impact-outline", "simulation-burst-halo", "simulation-burst-point", "simulation-pipe-label", "simulation-impact-label", "simulation-district-label", "simulation-burst-label" ] }; export const INITIAL_LAYER_VISIBILITY: Record = { conduits: true, junctions: true, orifices: true, outfalls: true, pumps: true, scada: true, simulation: false }; const SOURCE_CONTROL_LABELS: Record = { conduits: { label: "管渠", description: `${GEOSERVER_WORKSPACE}:${SOURCE_LAYERS.conduits}` }, junctions: { label: "检查井", description: `${GEOSERVER_WORKSPACE}:${SOURCE_LAYERS.junctions}` }, orifices: { label: "孔口", description: `${GEOSERVER_WORKSPACE}:${SOURCE_LAYERS.orifices}` }, outfalls: { label: "排放口", description: `${GEOSERVER_WORKSPACE}:${SOURCE_LAYERS.outfalls}` }, pumps: { label: "泵", description: `${GEOSERVER_WORKSPACE}:${SOURCE_LAYERS.pumps}` }, scada: { label: "综合监测点", description: `${GEOSERVER_WORKSPACE}:${SOURCE_LAYERS.scada}` } }; export const MAP_LEGEND_ITEMS: MapLegendItem[] = [ { id: "conduit", label: "管渠(线宽表示口径)", color: MAP_STYLE_TOKENS.asset.conduit, shape: "line" }, { id: "junction", label: "检查井", color: MAP_STYLE_TOKENS.asset.junction, shape: "dot" }, { id: "orifice", label: "孔口", color: MAP_STYLE_TOKENS.asset.orifice, shape: "dashed-line" }, { id: "pump", label: "泵", color: MAP_STYLE_TOKENS.asset.pump, shape: "dash-dot-line" }, { id: "outfall", label: "排放口", color: MAP_STYLE_TOKENS.asset.outfall, shape: "ring" }, { id: "scada-integrated", label: "综合监测点", color: "#0E7490", imageSrc: "/icons/scada-integrated-monitoring.svg" }, { id: "inactive", label: "停用 / 关闭", color: MAP_STYLE_TOKENS.state.inactive, shape: "line" }, { id: "impact-area", label: "风险影响范围", color: MAP_STYLE_TOKENS.state.risk, shape: "square" }, { id: "incident", label: "事故 / 爆管", color: MAP_STYLE_TOKENS.state.incident, shape: "dot" }, { id: "agent", label: "Agent 推断", color: MAP_STYLE_TOKENS.state.agent, shape: "dot" }, { id: "selected", label: "当前选中", color: MAP_STYLE_TOKENS.state.selected, shape: "ring" } ]; export const BASE_LAYER_IDS = ["mapbox-light", "mapbox-satellite"] as const; export const BASE_LAYER_OPTIONS: BaseLayerOption[] = [ { id: "mapbox-light", label: "浅色", description: "道路底图", swatchClassName: "bg-gradient-to-br from-slate-50 via-slate-100 to-blue-100" }, { id: "mapbox-satellite", label: "影像", description: "卫星街道", swatchClassName: "bg-gradient-to-br from-emerald-950 via-emerald-700 to-yellow-200" }, { id: "none", label: "无底图", description: "仅业务图层", swatchClassName: "bg-slate-100" } ]; export function createLayerControlItems(layerVisibility: Record): MapLayerControlItem[] { return WATER_NETWORK_SOURCE_IDS.map((sourceId) => ({ id: sourceId, ...SOURCE_CONTROL_LABELS[sourceId], visible: layerVisibility[sourceId] })); } export function getWorkbenchLayerIds( map: Pick, 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); }