feat(junction): establish stable complex junction structure
This commit is contained in:
1 parent
bd8b55e58b
commit
0a5a229ce3
22 files changed
+1386
-125
No files matched your search
+93
-10
@@ -247,7 +247,38 @@ function state(area, junctionReference = null, debug = false) {
|
||||
const trafficRuntime = runtime(trafficSignals);
|
||||
const compiled = readCompiled(area);
|
||||
const layers = readWorkbenchLayers(nativeDir, osm2streetsRoadSurface);
|
||||
const junctionStructure = projectJunctionStructure({ model: compiled.model, layers, trafficSignals });
|
||||
const clusters = area.nativeRoad?.junctionTemplates?.clusters || [];
|
||||
const nodeSegments = new Map();
|
||||
const roadsById = new Map((compiled.model.roads || []).map((road) => [road.id, road]));
|
||||
for (const endpoint of compiled.model.endpoints || []) {
|
||||
const id = String(endpoint.nodeId);
|
||||
if (!nodeSegments.has(id)) nodeSegments.set(id, new Set());
|
||||
nodeSegments.get(id).add(roadsById.get(endpoint.roadId)?.segmentId || endpoint.roadId);
|
||||
}
|
||||
const refs = [
|
||||
...[...nodeSegments].filter(([, segments]) => segments.size >= 2).map(([id]) => ({ type: 'node', id })),
|
||||
...clusters.map((cluster) => ({ type: 'cluster', id: String(cluster.id) })),
|
||||
];
|
||||
const junctionStructures = Object.fromEntries(
|
||||
refs
|
||||
.map((junctionRef) => [
|
||||
`${junctionRef.type}:${junctionRef.id}`,
|
||||
projectJunctionStructure({
|
||||
model: compiled.model,
|
||||
layers: {
|
||||
...layers,
|
||||
roadSurface: layers.nativeRoadSurface,
|
||||
intersectionSurface: layers.nativeIntersectionSurface,
|
||||
sidewalkSurface: layers.nativeSidewalkSurface,
|
||||
},
|
||||
trafficSignals,
|
||||
junctionRef,
|
||||
clusters,
|
||||
}),
|
||||
])
|
||||
.filter(([, structure]) => structure !== null),
|
||||
);
|
||||
const junctionStructure = null;
|
||||
const junctionShapes = debug
|
||||
? (readLayer(path.join(nativeDir, 'layers', 'road_surface.geojson')).features || [])
|
||||
.filter((feature) => feature.properties?.kind === 'complex-core' && feature.properties?.cluster_id)
|
||||
@@ -276,9 +307,16 @@ function state(area, junctionReference = null, debug = false) {
|
||||
}
|
||||
: null,
|
||||
compiled,
|
||||
junctionStructures,
|
||||
junctionStructure,
|
||||
standardsProfile: { id: 'cn-urban-default', label: '中国城市道路(项目默认)' },
|
||||
standardsDiagnostics: standardsDiagnostics(junctionStructure),
|
||||
standardsDiagnostics: [
|
||||
...new Map(
|
||||
Object.values(junctionStructures)
|
||||
.flatMap((structure) => standardsDiagnostics(structure))
|
||||
.map((item) => [item.id, item]),
|
||||
).values(),
|
||||
],
|
||||
overrides: loadOverrides(area.outputs.nativeRoadOverrides),
|
||||
trafficSignals,
|
||||
trafficRuntime,
|
||||
@@ -323,11 +361,28 @@ function activeRevisionFields(area) {
|
||||
// while the map renders about six handles. Omitting it keeps the full manifest for
|
||||
// callers that want it.
|
||||
function selectionFrom(source) {
|
||||
if (!source) return null;
|
||||
const segment = source.segment ?? source.get?.('segment');
|
||||
if (segment) return { type: 'segment', id: String(segment) };
|
||||
const junction = source.junction ?? source.get?.('junction');
|
||||
if (junction) return { type: 'junction', id: String(junction) };
|
||||
if (source == null) return null;
|
||||
if (typeof source !== 'object' || Array.isArray(source)) throw new Error('selection must be an object.');
|
||||
const keys = ['segment', 'junction', 'cluster'];
|
||||
const entries = keys.flatMap((key) => {
|
||||
if (typeof source.getAll === 'function') return source.getAll(key).map((value) => [key, value]);
|
||||
return Object.hasOwn(source, key) ? [[key, source[key]]] : [];
|
||||
});
|
||||
if (entries.length > 1) throw new Error('selection must specify only one of segment, junction, or cluster.');
|
||||
if (!entries.length) return null;
|
||||
const [key, value] = entries[0];
|
||||
if (
|
||||
(typeof value !== 'string' && typeof value !== 'number') ||
|
||||
!String(value).trim() ||
|
||||
(typeof value === 'number' && !Number.isFinite(value))
|
||||
)
|
||||
throw new Error(`selection.${key} must be a non-empty ID.`);
|
||||
return { type: key, id: String(value).trim() };
|
||||
}
|
||||
|
||||
function junctionRefFromSelection(selection) {
|
||||
if (selection?.type === 'junction') return { type: 'node', id: selection.id };
|
||||
if (selection?.type === 'cluster') return { type: 'cluster', id: selection.id };
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -339,13 +394,21 @@ function editState(area, selection = null) {
|
||||
const resolution = resolveDirectEditConstraints(model, directEdits, {
|
||||
revisionId: initialized.active.activeRevisionId,
|
||||
compilerGeometryVersion: GEOMETRY_VERSION,
|
||||
junctionTemplates: area.nativeRoad?.junctionTemplates,
|
||||
selection,
|
||||
});
|
||||
const compiled = readCompiled(area);
|
||||
const layers = readWorkbenchLayers(area.outputs.nativeRoadDir, null);
|
||||
const junctionStructure = projectJunctionStructure({
|
||||
model: compiled.model,
|
||||
layers,
|
||||
junctionRef: junctionRefFromSelection(selection),
|
||||
clusters: area.nativeRoad?.junctionTemplates?.clusters || [],
|
||||
layers: {
|
||||
...layers,
|
||||
roadSurface: layers.nativeRoadSurface,
|
||||
intersectionSurface: layers.nativeIntersectionSurface,
|
||||
sidewalkSurface: layers.nativeSidewalkSurface,
|
||||
},
|
||||
trafficSignals: readJson(area.outputs.nativeTrafficSignals),
|
||||
});
|
||||
return {
|
||||
@@ -381,12 +444,14 @@ function editPreview(area, body = {}) {
|
||||
const activeState = readJson(activeStateFile);
|
||||
const persistedOverrides = loadOverrides(area.outputs.nativeRoadOverrides);
|
||||
const model = compileRoadModel(fs.readFileSync(area.input, 'utf8'), persistedOverrides);
|
||||
const selection = selectionFrom(body.selection);
|
||||
const previewSeq = Number.isInteger(body.previewSeq) ? body.previewSeq : 0;
|
||||
const resolution = resolveDirectEditConstraints(model, draft, {
|
||||
revisionId: activeState.activeRevisionId,
|
||||
previewSeq,
|
||||
compilerGeometryVersion: GEOMETRY_VERSION,
|
||||
selection: selectionFrom(body.selection),
|
||||
junctionTemplates: area.nativeRoad?.junctionTemplates,
|
||||
selection,
|
||||
});
|
||||
const compiled = compileGeometry(model, persistedOverrides, {
|
||||
edgeLines: area.nativeRoad.edgeLines,
|
||||
@@ -396,7 +461,14 @@ function editPreview(area, body = {}) {
|
||||
const diagnostics = [...compiled.diagnostics, ...resolution.diagnostics];
|
||||
const junctionStructure = projectJunctionStructure({
|
||||
model,
|
||||
junctionRef: junctionRefFromSelection(selection),
|
||||
clusters: area.nativeRoad?.junctionTemplates?.clusters || [],
|
||||
layers: {
|
||||
roadSurface: compiled.roadSurface,
|
||||
sidewalkSurface: compiled.sidewalkSurface,
|
||||
islands: compiled.intersectionSurface,
|
||||
medians: compiled.intersectionSurface,
|
||||
sidewalkTurns: compiled.sidewalkSurface,
|
||||
crosswalks: compiled.crosswalks,
|
||||
vehicleStopLines: compiled.vehicleStopLines,
|
||||
intersectionSurface: compiled.intersectionSurface,
|
||||
@@ -456,6 +528,7 @@ function saveEdits(area, body = {}) {
|
||||
const resolution = resolveDirectEditConstraints(model, candidate, {
|
||||
revisionId: initialized.active.activeRevisionId,
|
||||
compilerGeometryVersion: GEOMETRY_VERSION,
|
||||
junctionTemplates: area.nativeRoad?.junctionTemplates,
|
||||
});
|
||||
const blockingDiagnostic = resolution.diagnostics.find((item) => item.severity === 'error');
|
||||
if (blockingDiagnostic) {
|
||||
@@ -484,6 +557,7 @@ function rebaseEdits(area, revisionId) {
|
||||
const resolution = resolveDirectEditConstraints(model, revision.directEdits, {
|
||||
revisionId,
|
||||
compilerGeometryVersion: GEOMETRY_VERSION,
|
||||
junctionTemplates: area.nativeRoad?.junctionTemplates,
|
||||
replay: true,
|
||||
});
|
||||
const counts = Object.fromEntries(
|
||||
@@ -750,4 +824,13 @@ function sendJson(response, status, value) {
|
||||
response.writeHead(status, { 'Content-Type': 'application/json; charset=utf-8', 'Cache-Control': 'no-store' });
|
||||
response.end(`${JSON.stringify(value)}\n`);
|
||||
}
|
||||
module.exports = { startWorkbench, readMultipart, editState, editPreview, saveEdits, rebaseEdits };
|
||||
module.exports = {
|
||||
startWorkbench,
|
||||
readMultipart,
|
||||
state,
|
||||
selectionFrom,
|
||||
editState,
|
||||
editPreview,
|
||||
saveEdits,
|
||||
rebaseEdits,
|
||||
};
|
||||
Reference in new issue
Block a user