fix(rail): the selected train's line draws over every network loaded before it again

Each route was a primitive added when it was drawn, so it sat over the
networks of feeds loaded until then. Its draw set was made once and kept
the slot of the first route, so a feed's network loaded after that drew
over later routes. Each route is drawn in a set made for it.
This commit is contained in:
Sameh Khamis committed 2026-11-14 01:40:41 -08:00
1 parent 0287ddb9be
commit f4beb676ae
2 files changed
+18 -2

No files matched your search

+8 -2
View File
@@ -83,6 +83,8 @@ export function createRouteDisplay({
let releaseTimer = null;
/** The selected line's set and the stop dots' set, made on first use. */
let routeSet = null;
/** Route sets made, for ids of their own. */
let routeBuilds = 0;
let stopSet = null;
/** The stop dots drawn now, as pushed to their set. */
let stopItems = [];
@@ -285,7 +287,11 @@ export function createRouteDisplay({
function dropRoute() {
if (!state._route) return;
routeSet?.clear();
// Let the set go: the next route's is made anew, on top of every line
// drawn before it (a feed's network loaded since), as each route's
// primitive was added when it was drawn.
routeSet?.dispose();
routeSet = null;
state._route = null;
}
@@ -326,7 +332,7 @@ export function createRouteDisplay({
}
}
if (positions.length < 2) return;
routeSet ||= lineSet(`rail:${instance}:route`);
routeSet ||= lineSet(`rail:${instance}:route:${++routeBuilds}`);
if (!routeSet) return;
routeSet.show = true;
const ahead = categoryColor(entry.category, 1);
+10
View File
@@ -227,6 +227,7 @@ test('the selected train’s line is its trip’s shape, else its route’s long
train('T2', LAT + 0.01, -71.07, { routeId: 'R2' }),
]);
await app.enable();
const routeSets = new Set();
for (const [id, shapeIndex, vertices] of [
['T1', 0, 31],
['T2', 1, 2],
@@ -242,7 +243,16 @@ ${shapeIndex}`,
id,
);
assert.equal(route.vertices, vertices, id);
// Each route is drawn in a set made for it, on top of every line set
// made before it, as its primitive was added when it was drawn.
const lines = [...app.draw.sets.values()].filter(
(set) => set.kind === 'lines' && !set.disposed,
);
assert.match(lines.at(-1).spec.id, /:route:\d+$/, id);
assert.equal(lines.filter((set) => /:route:/.test(set.spec.id)).length, 1);
routeSets.add(lines.at(-1).spec.id);
}
assert.equal(routeSets.size, 2, 'a set of its own for each route');
});
/** A one-shape Boston pack for mbta-rail. */