import { useEffect } from 'react';
import { CircleMarker, MapContainer, Polyline, TileLayer, Tooltip, useMap } from 'react-leaflet';
import { Box, Text } from '@mantine/core';
import type { RouteGeometry } from './route-geometry';
import { toLeafletLatLngs } from './route-geometry';
import { OSM_ATTRIBUTION, OSM_TILE_URL } from './osm';
import 'leaflet/dist/leaflet.css';
function FitRouteBounds({ positions }: { positions: Array<[number, number]> }) {
const map = useMap();
useEffect(() => {
if (positions.length === 0) return;
if (positions.length === 1) {
map.setView(positions[0], 14);
return;
}
map.fitBounds(positions, { padding: [24, 24] });
}, [map, positions]);
return null;
}
export interface RouteMapProps {
geometry?: RouteGeometry | null;
height?: number;
}
export function RouteMap({ geometry, height = 280 }: RouteMapProps) {
const positions = toLeafletLatLngs(geometry);
if (positions.length === 0) {
return (
No route geometry
);
}
return (
{positions.map((position, index) => (
{index + 1}
))}
);
}