feat(junction): add reference geometry comparison layer

This commit is contained in:
que01 committed 2026-09-07 16:45:37 +08:00
1 parent 4519cad562
commit 92ab2edd96
11 files changed
+107 -5

No files matched your search

@@ -0,0 +1,2 @@
{"file":".trellis/spec/frontend/quality-guidelines.md","reason":"Run frontend quality gates."}
{"file":".trellis/spec/backend/direct-edit-api.md","reason":"Verify reference data does not alter save/preview contracts."}
@@ -0,0 +1,5 @@
# 技术设计
服务端继续在启动时调用 `readJunctionReference()`,将转换后的 GeoJSON 作为可选只读字段返回;不把参考 `properties.type` 投影为业务对象。客户端在 `MapCanvas` 图层工厂中新增独立 reference layer,使用 `state.junctionReference.converted` 更新,显示状态由 App 本地开关控制。
比较指标优先复用 `comparison.json` 和 `junctionReference` 已有字段;缺失时显示“暂无匹配”,不执行客户端空间推断。参考层只参与渲染,不进入 `EditSession`、preview 或 save payload。
@@ -0,0 +1,3 @@
{"file":".trellis/spec/frontend/quality-guidelines.md","reason":"Follow frontend component and validation conventions."}
{"file":".trellis/spec/frontend/direct-edit-client.md","reason":"Keep reference rendering outside edit baseline and preview ownership."}
{"file":".trellis/spec/guides/cross-layer-thinking-guide.md","reason":"Trace reference data without changing native output."}
@@ -0,0 +1,6 @@
# 实施清单
1. 扩展客户端图层类型和更新逻辑,接入参考 GeoJSON。
2. 在 App 增加参考层开关、透明度和状态摘要。
3. 增加参考层转换/缺失兼容测试或类型覆盖。
4. 运行完整质量门禁并归档阶段任务。
@@ -0,0 +1,18 @@
# JunctionTools Stage 4:参考几何对照
## 目标
将已有参考 GeoJSON 以只读叠加层接入工作台,展示原始/转换状态和空间比较指标,同时保证参考数据不会影响 native 编译、草稿或保存。
## 范围
- 复用 `convertGeoJson` 和现有 `junctionReference` 数据流。
- 客户端提供参考层显示开关和透明度控制。
- 状态提供来源、坐标系、转换状态及比较指标;关闭、缺失或匹配失败时安全降级。
## 验收标准
1. 参考层可显示/隐藏并调整透明度,不改变 native 图层和保存请求。
2. UI 显示参考来源、GCJ-02 到 WGS84 转换状态和 bbox/中心差异(若已有比较结果)。
3. 无参考文件、转换失败或无匹配时 native 输出和现有编辑流程保持不变。
4. 客户端类型检查、单测、构建、格式检查和后端回归通过。
@@ -0,0 +1,26 @@
{
"id": "junctiontools-stage4-reference-comparison",
"name": "junctiontools-stage4-reference-comparison",
"title": "JunctionTools Stage 4 参考几何对照",
"description": "",
"status": "in_progress",
"dev_type": null,
"scope": null,
"package": null,
"priority": "P2",
"creator": "dingkang",
"assignee": "dingkang",
"createdAt": "2026-09-07",
"completedAt": null,
"branch": null,
"base_branch": "main",
"worktree_path": null,
"commit": null,
"pr_url": null,
"subtasks": [],
"children": [],
"parent": null,
"relatedFiles": [],
"notes": "",
"meta": {}
}
+19 -4
View File
@@ -67,6 +67,7 @@ import {
const layerLabels: Array<[LayerName, string]> = [
['osm', '方向道路参考线'],
['reference', '参考几何叠加'],
['native', '自研道路与路口面'],
['sidewalks', '路缘与步行带'],
['lanes', '车道与转向路径'],
@@ -78,10 +79,9 @@ const layerLabels: Array<[LayerName, string]> = [
['signals', '红绿灯设施'],
['junctionHotspots', '路口编辑热区'],
];
const defaultLayers = Object.fromEntries(layerLabels.map(([key]) => [key, key !== 'edgeLines'])) as Record<
LayerName,
boolean
>;
const defaultLayers = Object.fromEntries(
layerLabels.map(([key]) => [key, key !== 'edgeLines' && key !== 'reference']),
) as Record<LayerName, boolean>;
const direction = (road: Road) => (road.direction === 'forward' ? '沿 OSM 方向' : '逆 OSM 方向');
const label = (road: Road) => road.tags.name || `${road.highway}(OSM ${road.osmWayIds.join(', ')})`;
const laneIndex = (id: string) => Number(id.split(':').at(-1));
@@ -89,6 +89,7 @@ function App() {
const [state, setState] = useState<WorkbenchState>();
const [selected, setSelected] = useState<Road | null>(null);
const [layers, setLayers] = useState(defaultLayers);
const [referenceOpacity, setReferenceOpacity] = useState(0.55);
const [scene, setScene] = useState(false);
const [junctionHotspots, setJunctionHotspots] = useState(true);
const [status, setStatus] = useState('正在加载工作台...');
@@ -1003,6 +1004,19 @@ function App() {
</label>
);
})}
{state.junctionReference ? (
<label>
参考透明度
<input
type="range"
min="0.1"
max="1"
step="0.05"
value={referenceOpacity}
onChange={(event) => setReferenceOpacity(Number(event.target.value))}
/>
</label>
) : null}
<hr />
<hr />
<details className="issues-details">
@@ -1051,6 +1065,7 @@ function App() {
scene={scene}
junctionHotspots={junctionHotspots}
junctionNodeMarkers={junctionNodeMarkers}
referenceOpacity={referenceOpacity}
onJunctionHotspot={(ref: JunctionRef, _coordinate, descriptor) => {
openJunction(ref);
const approachRoad = descriptor.approachRoadIds
@@ -78,6 +78,7 @@ interface Props {
junctionHotspots?: boolean;
onJunctionHotspot?: (ref: JunctionRef, coordinate: Coordinate, descriptor: JunctionDescriptor) => void;
junctionNodeMarkers?: Array<{ coordinate: Coordinate; label: string; selected: boolean }>;
referenceOpacity?: number;
}
export function MapCanvas({
state,
@@ -114,6 +115,7 @@ export function MapCanvas({
junctionHotspots = true,
onJunctionHotspot,
junctionNodeMarkers = [],
referenceOpacity = 0.55,
}: Props) {
const target = useRef<HTMLDivElement>(null);
const mapRef = useRef<Map | null>(null);
@@ -611,5 +613,8 @@ export function MapCanvas({
layers.native.changed();
layers.sidewalks.changed();
}, [visible, scene]);
useEffect(() => {
layersRef.current?.reference.setOpacity(referenceOpacity);
}, [referenceOpacity]);
return <div className="map" ref={target} aria-label="道路地图" />;
}
@@ -230,6 +230,12 @@ export function JunctionWorkspace({
{state?.standardsProfile?.label || '项目默认标准'} · {structure.shape.label} ·{' '}
{structure.shape.effectiveArmCount} 条有效道路臂
</p>
{state?.junctionReference ? (
<p className="junction-workspace__reference-summary">
参考层:{state.junctionReference.coordinateSystem || 'GCJ-02'} → WGS84 ·{' '}
{state.junctionReference.source || '已加载参考文件'}
</p>
) : null}
<dl>
<dt>道路臂</dt>
<dd>
+11
View File
@@ -20,6 +20,7 @@ export type LayerName =
| 'native'
| 'sidewalks'
| 'osm'
| 'reference'
| 'lanes'
| 'edgeLines'
| 'directionArrows'
@@ -66,6 +67,15 @@ export function createLayers(
: undefined,
}),
}),
reference: new VectorLayer({
source: source(),
visible: false,
opacity: 0.55,
style: new Style({
fill: new Fill({ color: '#7c3aed22' }),
stroke: new Stroke({ color: '#7c3aed', width: 2, lineDash: [6, 4] }),
}),
}),
lanes: new VectorLayer({
source: source(),
style: new Style({ stroke: new Stroke({ color: '#f5f6ee', width: 1.5, lineDash: [5, 4] }) }),
@@ -224,6 +234,7 @@ export function updateLayers(
);
put('osm', { type: 'FeatureCollection', features: [] });
get('osm').addFeatures(roads);
put('reference', state.junctionReference?.converted);
put('lanes', state.layers.laneCenterlines);
put('edgeLines', state.layers.edgeLines);
put('directionArrows', state.layers.directionArrows);
+6 -1
View File
@@ -121,7 +121,12 @@ export interface WorkbenchState {
trafficRuntime: { signals: unknown[] };
comparison: Record<string, unknown>;
layers: Record<string, GeoJson | null>;
junctionReference?: { converted: GeoJson };
junctionReference?: {
source?: string;
coordinateSystem?: string;
converted: GeoJson;
comparison?: Record<string, unknown>;
};
debug?: {
junctionCandidates: JunctionCandidate[];
junctionClusters?: JunctionClusterConfig[];