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 = { 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, simulation: false }; const SOURCE_CONTROL_LABELS: Record = { 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: "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" } ]; 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); }