feat(workbench): add junction hotspot entry points
This commit is contained in:
1 parent
bd7b049930
commit
7d9b0f46d4
6 files changed
+288
-6
No files matched your search
@@ -11,6 +11,7 @@ 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';
|
||||
import type { JunctionDescriptor } from '../junction/hotspots';
|
||||
|
||||
const geojson = new GeoJSON();
|
||||
const source = () => new VectorSource();
|
||||
@@ -27,7 +28,8 @@ export type LayerName =
|
||||
| 'signals'
|
||||
| 'connectors'
|
||||
| 'diagnostics'
|
||||
| 'selectedRoad';
|
||||
| 'selectedRoad'
|
||||
| 'junctionHotspots';
|
||||
export function createLayers(
|
||||
onRoad: () => Road | null,
|
||||
scene: () => boolean,
|
||||
@@ -137,9 +139,46 @@ export function createLayers(
|
||||
source: source(),
|
||||
style: new Style({ stroke: new Stroke({ color: '#00a5cf', width: 8 }) }),
|
||||
}),
|
||||
junctionHotspots: new VectorLayer({
|
||||
source: source(),
|
||||
zIndex: 80,
|
||||
style: (feature) => {
|
||||
const status = feature.get('junction_status');
|
||||
const color = status === 'editable' ? '#0e7490' : status === 'candidate' ? '#d49318' : '#64748b';
|
||||
return new Style({
|
||||
image: new CircleStyle({
|
||||
radius: status === 'candidate' ? 9 : 8,
|
||||
fill: new Fill({ color: `${color}33` }),
|
||||
stroke: new Stroke({ color, width: 2 }),
|
||||
}),
|
||||
});
|
||||
},
|
||||
}),
|
||||
};
|
||||
return layers;
|
||||
}
|
||||
|
||||
export function updateJunctionHotspots(
|
||||
layers: ReturnType<typeof createLayers>,
|
||||
descriptors: JunctionDescriptor[],
|
||||
visible = true,
|
||||
) {
|
||||
const target = layers.junctionHotspots;
|
||||
target.setVisible(visible);
|
||||
const source = target.getSource()!;
|
||||
source.clear();
|
||||
source.addFeatures(
|
||||
descriptors.map(
|
||||
(descriptor) =>
|
||||
new Feature({
|
||||
geometry: new Point([descriptor.coordinate[0], descriptor.coordinate[1]]).transform('EPSG:4326', 'EPSG:3857'),
|
||||
junction_ref: descriptor.ref,
|
||||
junction_status: descriptor.status,
|
||||
junction_descriptor: descriptor,
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
function features(value: unknown) {
|
||||
return geojson.readFeatures((value || { type: 'FeatureCollection', features: [] }) as object, {
|
||||
dataProjection: 'EPSG:4326',
|
||||
|
||||
Reference in new issue
Block a user