Skip to content

Commit

Permalink
start reading in debug edges
Browse files Browse the repository at this point in the history
  • Loading branch information
abhumbla committed Mar 9, 2024
1 parent 156955a commit df6236f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/components/BikehopperMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import MapGL, {
GeolocateControl,
NavigationControl,
} from 'react-map-gl/maplibre';
import { featureCollection } from '@turf/helpers';
import * as DropdownMenu from '@radix-ui/react-dropdown-menu';
import {
routesToGeoJSON,
edgeToGeoJSON,
EMPTY_GEOJSON,
BIKEABLE_HIGHWAYS,
} from '../lib/geometry';
Expand Down Expand Up @@ -387,6 +389,8 @@ const BikehopperMap = React.forwardRef((props, mapRef) => {
}, [routes, activePath, viewingDetails, viewingStep, mapRef]);

const features = routes ? routesToGeoJSON(routes) : EMPTY_GEOJSON;
const edges = routes ? routes[activePath].edges?.map(edgeToGeoJSON) : null;
const debugEdges = edges ? featureCollection(edges) : null;

const navigationControlStyle = {
visibility: mapRef.current?.getBearing() !== 0 ? 'visible' : 'hidden',
Expand Down Expand Up @@ -473,6 +477,14 @@ const BikehopperMap = React.forwardRef((props, mapRef) => {
<Layer {...getTransitLabelStyle(activePath)} />
<Layer {...getBikeLabelStyle(activePath)} />
</Source>
{debugEdges && (
<Source id="debug-edges" type="geojson" data={debugEdges}>
<Layer
beforeId="standardBikeLayer"
{...getDebugStyle(activePath)}
/>
</Source>
)}
{startCoords && (
<Marker
id="startMarker"
Expand Down Expand Up @@ -604,6 +616,19 @@ function getTransitionStyle(activePath) {
};
}

function getDebugStyle(activePath) {
return {
id: 'debugLayer',
type: 'line',
layout: {},
paint: {
'line-width': 3,
'line-color': 'red',
'line-dasharray': [1, 1],
},
};
}

function getTransitStyle(activePath) {
return {
id: 'transitLayer',
Expand Down
8 changes: 8 additions & 0 deletions src/lib/geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ export function routesToGeoJSON(paths) {
return turf.featureCollection(features);
}

export function edgeToGeoJSON(edge) {
const properties = { ...edge };
delete properties.points;
const returnFeature = { ...edge.points };
returnFeature.properties = properties;
return returnFeature;
}

/**
* From a details object, generates a coherent set of lines such that no lines overlap.
*
Expand Down

0 comments on commit df6236f

Please sign in to comment.