All files / applications/go-by-transit/src/view/nearby/util/mapbox walkingRoute.ts

100% Statements 10/10
100% Branches 0/0
100% Functions 3/3
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37        9x           1x             1x 1x 1x 3x   1x 1x                 1x 1x      
import { Feature, LineString } from "geojson";
import { LngLatBounds, Map } from "mapbox-gl";
import { addMapboxLayer, removeRoutes } from "./routeLines";
 
const WALKING_ROUTE = "walking-access-route";
 
export function showWalkingRoute(
  map: Map,
  feature: Feature<LineString>
): () => void {
  addMapboxLayer(map, feature, WALKING_ROUTE, {
    "line-color": "#198754",
    "line-dasharray": [1, 2],
    "line-emissive-strength": 1,
    "line-opacity": 1,
    "line-width": 4,
  });
  const first = feature.geometry.coordinates[0];
  const bounds = new LngLatBounds([first[0], first[1]], [first[0], first[1]]);
  feature.geometry.coordinates.forEach((point) =>
    bounds.extend([point[0], point[1]])
  );
  const container = map.getContainer();
  map.fitBounds(bounds, {
    duration: 500,
    maxZoom: 16,
    padding: Math.min(
      40,
      container.clientWidth / 5,
      container.clientHeight / 5
    ),
  });
  return () => {
    removeRoutes(map, [WALKING_ROUTE]);
  };
}