|
|
|
@ -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); |
|
|
|
|
} |
|
|
|
|