feat: add complex junction selection markers
This commit is contained in:
1 parent
57248f1aa4
commit
38ea779d9b
18 files changed
+685
-48
No files matched your search
+42
-7
@@ -249,7 +249,17 @@ function state(area, junctionReference = null, debug = false) {
|
||||
areaId: area.id,
|
||||
activeRevisionId: revisionStore.active.activeRevisionId,
|
||||
documentVersion: revisionStore.active.documentVersion,
|
||||
debug: debug ? { junctionCandidates: junctionCandidates(compiled) } : null,
|
||||
debug: debug
|
||||
? {
|
||||
junctionCandidates: junctionCandidates(compiled),
|
||||
junctionClusters: (area.nativeRoad?.junctionTemplates?.clusters || []).map((cluster) => ({
|
||||
id: cluster.id,
|
||||
template: cluster.template,
|
||||
nodeIds: (cluster.nodeIds || []).map(String),
|
||||
coreRadiusMeters: cluster.coreRadiusMeters,
|
||||
})),
|
||||
}
|
||||
: null,
|
||||
compiled,
|
||||
overrides: loadOverrides(area.outputs.nativeRoadOverrides),
|
||||
trafficSignals,
|
||||
@@ -434,24 +444,49 @@ function rebaseEdits(area, revisionId) {
|
||||
// write a cluster that no longer exists. The external config remains untouched;
|
||||
// the response carries a copyable snippet while future compiles use the snapshot.
|
||||
function addJunctionCluster(body, compiled, options) {
|
||||
const clusterId = typeof body?.clusterId === 'string' ? body.clusterId : null;
|
||||
if (clusterId) {
|
||||
const templates = options?.junctionTemplates;
|
||||
const clusters = Array.isArray(templates?.clusters) ? templates.clusters : [];
|
||||
const current = clusters.find((cluster) => cluster.id === clusterId);
|
||||
if (!current) throw new Error('当前复杂路口配置已不存在,请刷新页面后重试。');
|
||||
const nodeIds = [...new Set(Array.isArray(body?.nodeIds) ? body.nodeIds.map(String) : [])];
|
||||
const allowed = new Set((current.nodeIds || []).map(String));
|
||||
if (nodeIds.length < 2 || nodeIds.some((nodeId) => !allowed.has(nodeId)))
|
||||
throw new Error('参与合并的路口点必须是当前复杂路口中的至少两个节点。');
|
||||
const nextClusters = clusters.map((cluster) => (cluster.id === clusterId ? { ...cluster, nodeIds } : cluster));
|
||||
const nextOptions = {
|
||||
...options,
|
||||
junctionTemplates: { ...templates, enabled: true, clusters: nextClusters },
|
||||
};
|
||||
return { cluster: { ...current, nodeIds }, options: nextOptions };
|
||||
}
|
||||
const candidateId = typeof body?.candidateId === 'string' ? body.candidateId : null;
|
||||
const index = Number(body?.index);
|
||||
if (!Number.isInteger(index)) throw new Error('请求缺少候选编号 index。');
|
||||
const candidate = junctionCandidates(compiled).find((item) => item.index === index);
|
||||
if (!candidate) throw new Error(`候选 #${index} 不在最新一次编译结果里,请刷新页面后重试。`);
|
||||
if (!candidateId && !Number.isInteger(index)) throw new Error('请求缺少复杂路口候选标识。');
|
||||
const candidate = junctionCandidates(compiled).find((item) =>
|
||||
candidateId ? item.id === candidateId : item.index === index,
|
||||
);
|
||||
if (!candidate) throw new Error('当前路口候选已不在最新编译结果里,请刷新页面后重试。');
|
||||
const requestedNodeIds = Array.isArray(body?.nodeIds) ? body.nodeIds.map(String) : candidate.nodeIds.map(String);
|
||||
const candidateNodeSet = new Set(candidate.nodeIds.map(String));
|
||||
const nodeIds = [...new Set(requestedNodeIds)];
|
||||
if (nodeIds.length < 2 || nodeIds.some((nodeId) => !candidateNodeSet.has(nodeId)))
|
||||
throw new Error('参与合并的路口点必须是当前候选中的至少两个节点。');
|
||||
const templates = options?.junctionTemplates;
|
||||
if (!templates) throw new Error('区域配置缺少 nativeRoad.junctionTemplates,请先手工建立该节点。');
|
||||
const clusters = Array.isArray(templates.clusters) ? templates.clusters : [];
|
||||
const taken = new Set(clusters.flatMap((cluster) => (cluster.nodeIds || []).map(String)));
|
||||
const clash = candidate.nodeIds.filter((nodeId) => taken.has(String(nodeId)));
|
||||
const clash = nodeIds.filter((nodeId) => taken.has(String(nodeId)));
|
||||
if (clash.length) throw new Error(`节点 ${clash.join('、')} 已属于其他复杂路口配置。`);
|
||||
const id = uniqueClusterId(`cluster-${candidate.nodeIds[0]}`, new Set(clusters.map((cluster) => cluster.id)));
|
||||
const id = uniqueClusterId(`cluster-${nodeIds[0]}`, new Set(clusters.map((cluster) => cluster.id)));
|
||||
const cluster = {
|
||||
id,
|
||||
template: candidate.template,
|
||||
coreRadiusMeters: candidate.coreRadiusMeters,
|
||||
cornerRadiusMeters: 12,
|
||||
outerRadiusExtraMeters: 18,
|
||||
nodeIds: candidate.nodeIds.map(String),
|
||||
nodeIds,
|
||||
};
|
||||
const nextOptions = {
|
||||
...options,
|
||||
|
||||
Reference in new issue
Block a user