From fec2055fe4631bf869af351b55bc785e0d6cb25d Mon Sep 17 00:00:00 2001 From: jacob6838 Date: Wed, 15 May 2024 10:15:11 -0600 Subject: [PATCH] Fixing redux map control panel --- api/jpo-conflictmonitor | 2 +- gui/next.config.js | 1 + gui/src/components/map/map-component.tsx | 5 +- .../components/map/map-layer-style-slice.ts | 2 +- .../components/map/utilities/message-utils.ts | 124 +++++++++--------- keycloak/realm.json | 4 +- 6 files changed, 74 insertions(+), 64 deletions(-) diff --git a/api/jpo-conflictmonitor b/api/jpo-conflictmonitor index 7e3fc329..f0c6e669 160000 --- a/api/jpo-conflictmonitor +++ b/api/jpo-conflictmonitor @@ -1 +1 @@ -Subproject commit 7e3fc3290b5d16d962e83c8e211e5b05fa7da8fd +Subproject commit f0c6e669daca9392661824304a4fe2fe5248ef35 diff --git a/gui/next.config.js b/gui/next.config.js index 5a0a0f04..c389bb1e 100644 --- a/gui/next.config.js +++ b/gui/next.config.js @@ -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, diff --git a/gui/src/components/map/map-component.tsx b/gui/src/components/map/map-component.tsx index acee460e..2961c86b 100644 --- a/gui/src/components/map/map-component.tsx +++ b/gui/src/components/map/map-component.tsx @@ -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(); @@ -312,7 +313,9 @@ const MapTab = (props: MyProps) => { }} > - + + +
{ - 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, diff --git a/keycloak/realm.json b/keycloak/realm.json index 574654a2..6160c035 100644 --- a/keycloak/realm.json +++ b/keycloak/realm.json @@ -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,