Skip to content

Commit

Permalink
Fixing redux map control panel
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob6838 committed May 15, 2024
1 parent 61d2d66 commit fec2055
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 64 deletions.
2 changes: 1 addition & 1 deletion api/jpo-conflictmonitor
1 change: 1 addition & 0 deletions gui/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const nextConfig = {
// all visible runtime environment variables must be added here
publicRuntimeConfig: {
KEYCLOAK_REALM: process.env.KEYCLOAK_REALM,
KEYCLOAK_CLIENT_ID: process.env.KEYCLOAK_CLIENT_ID,
MAPBOX_TOKEN: process.env.MAPBOX_TOKEN,
MAPBOX_STYLE_URL: process.env.MAPBOX_STYLE_URL,
GUI_SERVER_URL: process.env.GUI_SERVER_URL,
Expand Down
5 changes: 4 additions & 1 deletion gui/src/components/map/map-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import {
import { addConnections, createMarkerForNotification } from "./utilities/message-utils";
import { AnyAction, ThunkDispatch } from "@reduxjs/toolkit";
import { RootState } from "../../store";
import ControlPanel from "./control-panel";

const { publicRuntimeConfig } = getConfig();

Expand Down Expand Up @@ -312,7 +313,9 @@ const MapTab = (props: MyProps) => {
}}
>
<Box style={{ position: "relative" }}>
<Paper sx={{ pt: 1, pb: 1, opacity: 0.85 }}></Paper>
<Paper sx={{ pt: 1, pb: 1, opacity: 0.85 }}>
<ControlPanel />
</Paper>
</Box>
</div>
<div
Expand Down
2 changes: 1 addition & 1 deletion gui/src/components/map/map-layer-style-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const signalStateLayer: LayerProps = {
"PRE_MOVEMENT",
"traffic-light-icon-yellow-red-1",
"PERMISSIVE_MOVEMENT_ALLOWED",
"traffic-light-icon-yellow-1",
"traffic-light-icon-green-1",
"PROTECTED_MOVEMENT_ALLOWED",
"traffic-light-icon-green-1",
"PERMISSIVE_CLEARANCE",
Expand Down
124 changes: 65 additions & 59 deletions gui/src/components/map/utilities/message-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ export const parseBsmToGeojson = (bsmData: OdeBsmData[]): BsmFeatureCollection =
}),
};
};

export const addConnections = (
connectingLanes: ConnectingLanesFeatureCollection,
signalGroups: SpatSignalGroup[],
Expand All @@ -197,73 +196,80 @@ export const addConnections = (
var bbox = turf.bbox(connectingLanes);

//for each connecting lane, fetch its ingress and egress lanes
connectingLanes.features?.forEach((connectionFeature: ConnectingLanesFeature) => {
var ingressLaneId = connectionFeature.properties.ingressLaneId;
var egressLaneId = connectionFeature.properties.egressLaneId;
var ingressLane = mapFeatures.features.find((feature) => feature.id === ingressLaneId);
var egressLane = mapFeatures.features.find((feature) => feature.id === egressLaneId);
connectingLanes = {
...connectingLanes,
features: connectingLanes.features
?.map((connectionFeature: ConnectingLanesFeature) => {
var ingressLaneId = connectionFeature.properties.ingressLaneId;
var egressLaneId = connectionFeature.properties.egressLaneId;
var ingressLane = mapFeatures.features.find((feature) => feature.id === ingressLaneId);
var egressLane = mapFeatures.features.find((feature) => feature.id === egressLaneId);

if (ingressLane && egressLane) {
var ingressCoords = ingressLane.geometry.coordinates;
var egressCoords = egressLane.geometry.coordinates;
if (ingressLane && egressLane) {
var ingressCoords = ingressLane.geometry.coordinates;
var egressCoords = egressLane.geometry.coordinates;

var ingressBearing = turf.bearing(ingressCoords[1], ingressCoords[0]);
var egressBearing = turf.bearing(egressCoords[1], egressCoords[0]);
var ingressBearing = turf.bearing(ingressCoords[1], ingressCoords[0]);
var egressBearing = turf.bearing(egressCoords[1], egressCoords[0]);

//project the ingress/egress lanes through the intersection to the edge of the bbox
var ingressLine = turf.lineString([
ingressCoords[0],
turf.destination(ingressCoords[0], 0.05, ingressBearing).geometry.coordinates,
]);
var egressLine = turf.lineString([
egressCoords[0],
turf.destination(egressCoords[0], 0.05, egressBearing).geometry.coordinates,
]);
var clippedIngress = turf.bboxClip(ingressLine, bbox);
var clippedEgress = turf.bboxClip(egressLine, bbox);
//project the ingress/egress lanes through the intersection to the edge of the bbox
var ingressLine = turf.lineString([
ingressCoords[0],
turf.destination(ingressCoords[0], 0.05, ingressBearing).geometry.coordinates,
]);
var egressLine = turf.lineString([
egressCoords[0],
turf.destination(egressCoords[0], 0.05, egressBearing).geometry.coordinates,
]);
var clippedIngress = turf.bboxClip(ingressLine, bbox);
var clippedEgress = turf.bboxClip(egressLine, bbox);

//find the intersection point of the projected lanes, if it exists
var intersect = turf.lineIntersect(clippedIngress.geometry, clippedEgress.geometry);
//find the intersection point of the projected lanes, if it exists
var intersect = turf.lineIntersect(clippedIngress.geometry, clippedEgress.geometry);

//if the lanes intersect within the intersection, this is a ~90 degree turn and we add 1 more point to round the curve
if (intersect.features.length > 0) {
var intersectPoint = intersect.features[0].geometry.coordinates;
//the intersection would overshoot the curve, so curveMidpoint is a weighted average the intersection and connectingLanes edges
var curveMidpoint = turf.centroid(
turf.points([ingressCoords[0], egressCoords[0], intersectPoint, intersectPoint, intersectPoint])
);
//if the lanes intersect within the intersection, this is a ~90 degree turn and we add 1 more point to round the curve
if (intersect.features.length > 0) {
var intersectPoint = intersect.features[0].geometry.coordinates;
//the intersection would overshoot the curve, so curveMidpoint is a weighted average the intersection and connectingLanes edges
var curveMidpoint = turf.centroid(
turf.points([ingressCoords[0], egressCoords[0], intersectPoint, intersectPoint, intersectPoint])
);

var connectingLaneLine = turf.lineString([
ingressCoords[0],
curveMidpoint.geometry.coordinates,
egressCoords[0],
]);
var curve = turf.bezierSpline(connectingLaneLine);
connectionFeature.geometry = curve.geometry;
}
var connectingLaneLine = turf.lineString([
ingressCoords[0],
curveMidpoint.geometry.coordinates,
egressCoords[0],
]);
var curve = turf.bezierSpline(connectingLaneLine);
connectionFeature = { ...connectionFeature, geometry: curve.geometry };
}

//If the ingress and egress lanes are going in generally opposite directions and didn't intersect, use the U-turn calculations
else if (Math.abs(ingressBearing - egressBearing) < 45) {
//this formula was found experimentally to give a round curve and allow parallel curving lanes to not intersect
var leadupLength = Math.min(turf.distance(ingressCoords[0], egressCoords[0]) * -7 + 0.045, -0.02);
//If the ingress and egress lanes are going in generally opposite directions and didn't intersect, use the U-turn calculations
else if (Math.abs(ingressBearing - egressBearing) < 45) {
//this formula was found experimentally to give a round curve and allow parallel curving lanes to not intersect
var leadupLength = Math.min(turf.distance(ingressCoords[0], egressCoords[0]) * -7 + 0.045, -0.02);

var normalizedIngressPoint = turf.destination(ingressCoords[0], leadupLength, ingressBearing);
var normalizedEgressPoint = turf.destination(egressCoords[0], leadupLength, egressBearing);
var connectingLaneLine = turf.lineString([
normalizedIngressPoint.geometry.coordinates,
ingressCoords[0],
egressCoords[0],
normalizedEgressPoint.geometry.coordinates,
]);
var normalizedIngressPoint = turf.destination(ingressCoords[0], leadupLength, ingressBearing);
var normalizedEgressPoint = turf.destination(egressCoords[0], leadupLength, egressBearing);
var connectingLaneLine = turf.lineString([
normalizedIngressPoint.geometry.coordinates,
ingressCoords[0],
egressCoords[0],
normalizedEgressPoint.geometry.coordinates,
]);

var rawCurve = turf.bezierSpline(connectingLaneLine);
//slice the curve back to remove the redundant ends
var curve = turf.lineSlice(ingressCoords[0], egressCoords[0], rawCurve);
connectionFeature.geometry = curve.geometry;
}
//anything else is mostly straight and doesn't require a bezier curve
}
});
var rawCurve = turf.bezierSpline(connectingLaneLine);
//slice the curve back to remove the redundant ends
var curve = turf.lineSlice(ingressCoords[0], egressCoords[0], rawCurve);
connectionFeature = { ...connectionFeature, geometry: curve.geometry };
}
//anything else is mostly straight and doesn't require a bezier curve
return connectionFeature;
}
return null;
})
.filter((feature) => feature !== null) as ConnectingLanesFeature[],
};

return {
...connectingLanes,
Expand Down
4 changes: 2 additions & 2 deletions keycloak/realm.json
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,8 @@
"enabled" : true,
"alwaysDisplayInConsole" : false,
"clientAuthenticatorType" : "client-secret",
"redirectUris" : [ "${API_SERVER_URL}/*" ],
"webOrigins" : [ "${API_SERVER_URL}" ],
"redirectUris" : [ "${API_SERVER_URL}/*", "http://localhost:3000/*" ],
"webOrigins" : [ "${API_SERVER_URL}", "http://localhost:3000" ],
"notBefore" : 0,
"bearerOnly" : false,
"consentRequired" : false,
Expand Down

0 comments on commit fec2055

Please sign in to comment.