feat(workbench): improve traffic signal editing
This commit is contained in:
1 parent
00d5f7650f
commit
cf5bc0602b
3 files changed
+152
-23
No files matched your search
@@ -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 { offsetCoordinate, type Coordinate } from '../edit/meters';
|
||||
import type { Road, WorkbenchState } from '../types/state';
|
||||
|
||||
const geojson = new GeoJSON();
|
||||
@@ -93,15 +94,29 @@ export function createLayers(
|
||||
}),
|
||||
signals: new VectorLayer({
|
||||
source: source(),
|
||||
style: new Style({
|
||||
image: new RegularShape({
|
||||
points: 4,
|
||||
radius: 6,
|
||||
angle: Math.PI / 4,
|
||||
fill: new Fill({ color: '#263630' }),
|
||||
stroke: new Stroke({ color: '#fff', width: 2 }),
|
||||
}),
|
||||
}),
|
||||
style: (feature) =>
|
||||
feature.get('signal_component') === 'mast'
|
||||
? new Style({ stroke: new Stroke({ color: '#263630', width: 3 }) })
|
||||
: feature.get('signal_component') === 'face'
|
||||
? new Style({ stroke: new Stroke({ color: '#d49318', width: 2, lineDash: [5, 4] }) })
|
||||
: feature.get('signal_component') === 'face-tip'
|
||||
? new Style({
|
||||
image: new RegularShape({
|
||||
points: 3,
|
||||
radius: 5,
|
||||
rotation: (Number(feature.get('signal_heading') || 0) * Math.PI) / 180,
|
||||
fill: new Fill({ color: '#d49318' }),
|
||||
}),
|
||||
})
|
||||
: new Style({
|
||||
image: new RegularShape({
|
||||
points: 4,
|
||||
radius: 6,
|
||||
angle: Math.PI / 4,
|
||||
fill: new Fill({ color: '#263630' }),
|
||||
stroke: new Stroke({ color: '#fff', width: 2 }),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
connectors: new VectorLayer({
|
||||
source: source(),
|
||||
@@ -155,7 +170,39 @@ export function updateLayers(layers: ReturnType<typeof createLayers>, state: Wor
|
||||
put('centerLines', state.layers.centerLines);
|
||||
put('controls', state.layers.crosswalks);
|
||||
get('controls').addFeatures(features(state.layers.vehicleStopLines));
|
||||
put('signals', state.trafficSignals.assemblies);
|
||||
const signalFeatures = state.trafficSignals.assemblies.features.flatMap((feature) => {
|
||||
const point =
|
||||
feature.geometry?.type === 'Point' && Array.isArray(feature.geometry.coordinates)
|
||||
? (feature.geometry.coordinates as Coordinate)
|
||||
: null;
|
||||
if (!point || point.length < 2) return [feature];
|
||||
const properties = feature.properties || {};
|
||||
const mastHeading = Number(properties.mast_heading_deg);
|
||||
const faceHeading = Number(properties.face_heading_deg);
|
||||
const reach = Number(properties.mast_reach_m);
|
||||
if (![mastHeading, faceHeading, reach].every(Number.isFinite)) return [feature];
|
||||
const mastEnd = offsetCoordinate(point, mastHeading, reach);
|
||||
const faceEnd = offsetCoordinate(mastEnd, faceHeading, Math.min(1.2, reach * 0.2));
|
||||
return [
|
||||
feature,
|
||||
{
|
||||
type: 'Feature' as const,
|
||||
geometry: { type: 'LineString', coordinates: [point, mastEnd] },
|
||||
properties: { ...properties, signal_component: 'mast' },
|
||||
},
|
||||
{
|
||||
type: 'Feature' as const,
|
||||
geometry: { type: 'LineString', coordinates: [mastEnd, faceEnd] },
|
||||
properties: { ...properties, signal_component: 'face' },
|
||||
},
|
||||
{
|
||||
type: 'Feature' as const,
|
||||
geometry: { type: 'Point', coordinates: faceEnd },
|
||||
properties: { ...properties, signal_component: 'face-tip', signal_heading: faceHeading },
|
||||
},
|
||||
];
|
||||
});
|
||||
put('signals', { type: 'FeatureCollection', features: signalFeatures });
|
||||
put('connectors', state.layers.connectors);
|
||||
put('diagnostics', {
|
||||
type: 'FeatureCollection',
|
||||
|
||||
Reference in new issue
Block a user