diff --git a/src/routePlanner/map.tsx b/src/routePlanner/map.tsx index 6cd6145..d71bda0 100644 --- a/src/routePlanner/map.tsx +++ b/src/routePlanner/map.tsx @@ -29,7 +29,11 @@ export const MapComponent = ({ markers, onMapClick }: InternalMapProps) => { .addTo(map); mapRef.current = map; - }); + + return () => { + map.remove(); + }; + }, []); useEffect(() => { const map = mapRef.current; @@ -56,22 +60,39 @@ export const MapComponent = ({ markers, onMapClick }: InternalMapProps) => { for (let i = 0; i < markers.length; i++) { const thisMarker = markers[i]; const previousMarker = markers[i - 1]; - if (thisMarker) { - if (previousMarker) { - layers.push( - leaflet.polyline([ - previousMarker.coordinates, - thisMarker.coordinates, - ]), - ); - } + if (thisMarker && previousMarker) { layers.push( - leaflet.marker(thisMarker.coordinates, { - title: `${i + 1}`, - }), + leaflet.polyline([ + previousMarker.coordinates, + thisMarker.coordinates, + ]), ); } } + + layers.push( + ...markers.flatMap((marker, i) => { + const circle = leaflet.circleMarker(marker.coordinates, { + color: 'black', + fill: true, + fillOpacity: 100, + radius: 10, + }); + const tooltip = leaflet + .tooltip( + { + permanent: true, + direction: 'center', + className: 'text', + content: `${i + 1}`, + }, + circle, + ) + .setLatLng(marker.coordinates); + return [circle, tooltip]; + }), + ); + for (const layer of layers) { layer.addTo(map); } diff --git a/src/routePlanner/markers.tsx b/src/routePlanner/markers.tsx index 27e2a46..e5369fd 100644 --- a/src/routePlanner/markers.tsx +++ b/src/routePlanner/markers.tsx @@ -7,10 +7,8 @@ export const MarkersComponent = ({ markers }: InternalProps) => { <>