feat(workbench): stabilize junction tools workspace

This commit is contained in:
que01 committed 2026-09-04 09:46:19 +08:00
1 parent e6b822416d
commit f10a5da325
22 files changed
+1078 -53

No files matched your search

+25 -2
View File
@@ -9,6 +9,7 @@ import Fill from 'ol/style/Fill';
import RegularShape from 'ol/style/RegularShape';
import Stroke from 'ol/style/Stroke';
import Style from 'ol/style/Style';
import Text from 'ol/style/Text';
import { offsetCoordinate, type Coordinate } from '../edit/meters';
import type { Road, WorkbenchState } from '../types/state';
import type { JunctionDescriptor } from '../junction/hotspots';
@@ -54,6 +55,15 @@ export function createLayers(
color: f.get('road_id') === onRoad()?.id ? '#006e91' : '#263630',
width: f.get('road_id') === onRoad()?.id ? 5 : 2,
}),
text: f.get('road_label_visible')
? new Text({
text: String(f.get('road_label') || ''),
font: '600 12px sans-serif',
fill: new Fill({ color: '#f8fafc' }),
stroke: new Stroke({ color: '#17211f', width: 4 }),
overflow: true,
})
: undefined,
}),
}),
lanes: new VectorLayer({
@@ -185,7 +195,12 @@ function features(value: unknown) {
featureProjection: 'EPSG:3857',
});
}
export function updateLayers(layers: ReturnType<typeof createLayers>, state: WorkbenchState, selected: Road | null) {
export function updateLayers(
layers: ReturnType<typeof createLayers>,
state: WorkbenchState,
selected: Road | null,
showRoadLabels = false,
) {
const get = (name: LayerName) => layers[name].getSource()!;
const put = (name: LayerName, value: unknown) => {
const target = get(name);
@@ -195,9 +210,17 @@ export function updateLayers(layers: ReturnType<typeof createLayers>, state: Wor
put('native', state.layers.nativeRoadSurface);
get('native').addFeatures(features(state.layers.nativeIntersectionSurface));
put('sidewalks', state.layers.nativeSidewalkSurface);
const unnamedRoadNumber = new Map(
state.compiled.model.roads.filter((road) => !road.tags.name?.trim()).map((road, index) => [road.id, index + 1]),
);
const roads = state.compiled.model.roads.map(
(road) =>
new Feature({ geometry: new LineString(road.centerline).transform('EPSG:4326', 'EPSG:3857'), road_id: road.id }),
new Feature({
geometry: new LineString(road.centerline).transform('EPSG:4326', 'EPSG:3857'),
road_id: road.id,
road_label_visible: showRoadLabels,
road_label: road.tags.name?.trim() || `道路${unnamedRoadNumber.get(road.id) || 1}`,
}),
);
put('osm', { type: 'FeatureCollection', features: [] });
get('osm').addFeatures(roads);