Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions frontend/calpoly-map/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function MapScreen({
routeRequested,
routeStartIsCurrentLocation,
setActivePath,
setRoute,
setRouteError,
} = useMapContext();
const { graph, error } = usePathGraph();
Expand All @@ -75,8 +76,11 @@ function MapScreen({
useEffect(() => {
if (!routingActive || !routeRequested || !routeStart || !routeEnd || !graph) {
setActivePath(null);
setRoute(null);
if (routingActive && routeRequested && routeStart && routeEnd && !graph) {
setRouteError("Loading paths data...");
} else if (routingActive && routeRequested && (!routeStart || !routeEnd)) {
setRouteError("Select a start and destination");
} else {
setRouteError(null);
}
Expand All @@ -96,6 +100,7 @@ function MapScreen({
}
if (!result) {
setActivePath(null);
setRoute(null);
setRouteError(
routeStartIsCurrentLocation
? "Current location isn't on the path network. Choose a start point."
Expand All @@ -106,13 +111,19 @@ function MapScreen({

setRouteError(null);
setActivePath(result);
setRoute({
nodes: [],
totalDistance: result.distance,
coordinates: result.path,
});
}, [
graph,
routeStart,
routeEnd,
routingActive,
routeRequested,
setActivePath,
setRoute,
setRouteError,
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function SearchPanel({ cameraMove }: Props) {
userLocation,
routeStart,
routeEnd,
activePath,
activeRoute,
routeError,
routingActive,
routeRequested,
Expand Down Expand Up @@ -332,9 +332,9 @@ export function SearchPanel({ cameraMove }: Props) {
<Text style={styles.statusText}>
End: {routeEnd ? "set" : "not set"}
</Text>
{activePath && (
{activeRoute && (
<Text style={styles.statusText}>
Distance: {Math.round(activePath.distance)}m
Distance: {Math.round(activeRoute.totalDistance)}m
</Text>
)}
{routeError && <Text style={styles.errorText}>{routeError}</Text>}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { CircleLayer, LineLayer, ShapeSource } from "@maplibre/maplibre-react-na
import { useMapContext } from "../../../context/MapContext";

export function RouteLineLayer() {
const { activePath, routeStart, routeEnd } = useMapContext();
const { activeRoute, routeStart, routeEnd } = useMapContext();

const lineCollection = useMemo<FeatureCollection<LineString> | null>(() => {
if (!activePath || activePath.path.length < 2) {
if (!activeRoute || activeRoute.coordinates.length < 2) {
return null;
}
return {
Expand All @@ -17,13 +17,13 @@ export function RouteLineLayer() {
type: "Feature",
geometry: {
type: "LineString",
coordinates: activePath.path,
coordinates: activeRoute.coordinates,
},
properties: {},
},
],
};
}, [activePath]);
}, [activeRoute]);

const pointCollection = useMemo<FeatureCollection<Point> | null>(() => {
if (!routeStart && !routeEnd) {
Expand Down
1 change: 1 addition & 0 deletions frontend/calpoly-map/src/context/MapContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export function MapProvider({ children }: { children: React.ReactNode }) {
setRouteStart(null);
setRouteEnd(null);
setActivePath(null);
setActiveRoute(null);
setRouteError(null);
setRouteRequested(false);
setRouteStartIsCurrentLocation(false);
Expand Down