feat(admin): 优化换乘设置与坐标绑定逻辑,自动识别同名换乘站
This commit is contained in:
@@ -86,6 +86,33 @@ const buildRouteGraph = (stations, lines, fares, cfg) => {
|
||||
});
|
||||
};
|
||||
|
||||
// Auto-link stations with the same name (Chinese or English)
|
||||
const stationsByName = new Map();
|
||||
const normKey = (s) => String(s || '').trim().toLowerCase().replace(/\s+/g, '');
|
||||
for (const s of (stations || [])) {
|
||||
const code = String(s?.code || '').trim();
|
||||
if (!code) continue;
|
||||
const cn = normKey(s?.name || s?.cn_name || s?.station_name);
|
||||
const en = normKey(s?.en_name || s?.en || s?.enName);
|
||||
if (cn) {
|
||||
if (!stationsByName.has(cn)) stationsByName.set(cn, []);
|
||||
stationsByName.get(cn).push(code);
|
||||
}
|
||||
if (en && en !== cn) {
|
||||
if (!stationsByName.has(en)) stationsByName.set(en, []);
|
||||
stationsByName.get(en).push(code);
|
||||
}
|
||||
}
|
||||
|
||||
for (const codes of stationsByName.values()) {
|
||||
if (codes.length < 2) continue;
|
||||
for (let i = 0; i < codes.length; i++) {
|
||||
for (let j = i + 1; j < codes.length; j++) {
|
||||
addTransferEdge(codes[i], codes[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const transfers = Array.isArray(cfg?.transfers) ? cfg.transfers : [];
|
||||
for (const p of transfers) {
|
||||
const u = String(p?.[0] || '').trim();
|
||||
|
||||
Reference in New Issue
Block a user