feat(junction): preserve known traffic island regions

This commit is contained in:
que01 committed 2026-09-09 09:43:55 +08:00
1 parent b6f4dfeb0c
commit 4b8f37a219
3 files changed
+36 -4

No files matched your search

+20 -3
View File
@@ -91,17 +91,26 @@ function parseOsmRoads(xml) {
crossingNodes.push({ id, coordinate, tags });
}
const ways = [];
const exclusionRegions = [];
for (const match of xml.matchAll(/<way\b([^>]*)>([\s\S]*?)<\/way>/g)) {
const attrs = xmlAttrs(match[1]);
const body = match[2];
const tags = parseTags(body);
if (attrs.action === 'delete' || !MOTOR_HIGHWAYS.has(tags.highway || '')) continue;
const refs = [...body.matchAll(/<nd\b([^>]*)\/?\s*>/g)].map((item) => xmlAttrs(item[1]).ref).filter(Boolean);
const coords = refs.map((ref) => nodes.get(String(ref))).filter(Boolean);
if (
attrs.action !== 'delete' &&
refs.length >= 4 &&
refs[0] === refs.at(-1) &&
coords.length === refs.length &&
(tags.highway === 'traffic_island' || tags.traffic_calming === 'island')
)
exclusionRegions.push({ id: String(attrs.id), source: 'osm-traffic-island', ring: coords, tags });
if (attrs.action === 'delete' || !MOTOR_HIGHWAYS.has(tags.highway || '')) continue;
if (coords.length < 2 || coords.length !== refs.length) continue;
ways.push({ id: String(attrs.id), refs: refs.map(String), coords, tags });
}
return { nodes, ways, crossingNodes };
return { nodes, ways, crossingNodes, exclusionRegions };
}
function compileRoadModel(xml, overrides) {
@@ -182,7 +191,15 @@ function compileRoadModel(xml, overrides) {
...crossing,
osmWayIds: parsed.ways.filter((way) => way.refs.includes(crossing.id)).map((way) => way.id),
}));
return { schema: 'native-road-model/v1', roads, endpoints, connections, crossings, diagnostics };
return {
schema: 'native-road-model/v1',
roads,
endpoints,
connections,
crossings,
exclusionRegions: parsed.exclusionRegions,
diagnostics,
};
}
function splitWayAtSharedNodes(way, sharedNodeWayIds) {