feat(map): add five-source drainage styling
This commit is contained in:
@@ -1,27 +1,68 @@
|
||||
import type { MapGeoJSONFeature } from "maplibre-gl";
|
||||
import type { DetailFeature } from "../types";
|
||||
import { formatValue } from "../utils/format-value";
|
||||
import { SOURCE_LAYERS } from "./sources";
|
||||
import { SOURCE_LAYERS, type WaterNetworkSourceId } from "./sources";
|
||||
|
||||
export function getFeatureId(feature: MapGeoJSONFeature) {
|
||||
const raw = feature.properties?.id ?? feature.id;
|
||||
return raw === undefined || raw === null ? "" : String(raw);
|
||||
}
|
||||
|
||||
export function getWaterNetworkSourceId(feature: MapGeoJSONFeature): WaterNetworkSourceId | null {
|
||||
const entry = Object.entries(SOURCE_LAYERS).find(([, sourceLayer]) => sourceLayer === feature.sourceLayer);
|
||||
return (entry?.[0] as WaterNetworkSourceId | undefined) ?? null;
|
||||
}
|
||||
|
||||
export function toDetailFeature(feature: MapGeoJSONFeature): DetailFeature {
|
||||
const isPipe = feature.sourceLayer === SOURCE_LAYERS.pipes;
|
||||
const layer = getWaterNetworkSourceId(feature);
|
||||
if (!layer) {
|
||||
throw new Error(`Unsupported water network source layer: ${feature.sourceLayer ?? "unknown"}`);
|
||||
}
|
||||
|
||||
const id = getFeatureId(feature);
|
||||
const diameter = feature.properties?.diameter;
|
||||
const length = feature.properties?.length;
|
||||
const demand = feature.properties?.demand;
|
||||
const properties = feature.properties ?? {};
|
||||
const presentation = getFeaturePresentation(layer, id, properties);
|
||||
|
||||
return {
|
||||
id,
|
||||
layer: isPipe ? "pipes" : "junctions",
|
||||
title: isPipe ? `管线 ${id || "未命名"}` : `节点 ${id || "未命名"}`,
|
||||
subtitle: isPipe
|
||||
? `DN${formatValue(diameter)} · ${formatValue(length)} m`
|
||||
: `需水量 ${formatValue(demand)} · 高程 ${formatValue(feature.properties?.elevation)} m`,
|
||||
properties: feature.properties ?? {}
|
||||
layer,
|
||||
...presentation,
|
||||
properties
|
||||
};
|
||||
}
|
||||
|
||||
function getFeaturePresentation(
|
||||
layer: WaterNetworkSourceId,
|
||||
id: string,
|
||||
properties: Record<string, unknown>
|
||||
) {
|
||||
const displayId = id || "未命名";
|
||||
|
||||
switch (layer) {
|
||||
case "conduits":
|
||||
return {
|
||||
title: `管渠 ${displayId}`,
|
||||
subtitle: `DN${formatValue(properties.diameter)} · ${formatValue(properties.length)} m`
|
||||
};
|
||||
case "junctions":
|
||||
return {
|
||||
title: `检查井 ${displayId}`,
|
||||
subtitle: `最大深度 ${formatValue(properties.max_depth)} m · 井底高程 ${formatValue(properties.invert_elevation)} m`
|
||||
};
|
||||
case "orifices":
|
||||
return {
|
||||
title: `孔口 ${displayId}`,
|
||||
subtitle: `类型 ${formatValue(properties.orifice_type)} · 断面 ${formatValue(properties.shape)}`
|
||||
};
|
||||
case "pumps":
|
||||
return {
|
||||
title: `泵 ${displayId}`,
|
||||
subtitle: `状态 ${formatValue(properties.status)} · 曲线 ${formatValue(properties.pump_curve)}`
|
||||
};
|
||||
case "outfalls":
|
||||
return {
|
||||
title: `排放口 ${displayId}`,
|
||||
subtitle: `类型 ${formatValue(properties.outfall_type)} · 井底高程 ${formatValue(properties.invert_elevation)} m`
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user