improved design, fixed HMR

main
Inga 🏳‍🌈 1 year ago
parent 173315bfbb
commit 34eea5d8f0
  1. 47
      src/routePlanner/map.tsx
  2. 6
      src/routePlanner/markers.tsx
  3. 8
      src/routePlanner/style.css

@ -29,7 +29,11 @@ export const MapComponent = ({ markers, onMapClick }: InternalMapProps) => {
.addTo(map); .addTo(map);
mapRef.current = map; mapRef.current = map;
});
return () => {
map.remove();
};
}, []);
useEffect(() => { useEffect(() => {
const map = mapRef.current; const map = mapRef.current;
@ -56,22 +60,39 @@ export const MapComponent = ({ markers, onMapClick }: InternalMapProps) => {
for (let i = 0; i < markers.length; i++) { for (let i = 0; i < markers.length; i++) {
const thisMarker = markers[i]; const thisMarker = markers[i];
const previousMarker = markers[i - 1]; const previousMarker = markers[i - 1];
if (thisMarker) { if (thisMarker && previousMarker) {
if (previousMarker) {
layers.push(
leaflet.polyline([
previousMarker.coordinates,
thisMarker.coordinates,
]),
);
}
layers.push( layers.push(
leaflet.marker(thisMarker.coordinates, { leaflet.polyline([
title: `${i + 1}`, 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) { for (const layer of layers) {
layer.addTo(map); layer.addTo(map);
} }

@ -7,10 +7,8 @@ export const MarkersComponent = ({ markers }: InternalProps) => {
<> <>
<h3>Markers</h3> <h3>Markers</h3>
<ol> <ol>
{markers.map(({ key, coordinates }) => ( {markers.map(({ key }, i) => (
<li key={key}> <li key={key}>{`Waypoint ${i + 1}`}</li>
{coordinates.lat}, {coordinates.lng}
</li>
))} ))}
</ol> </ol>
</> </>

@ -19,6 +19,14 @@ section.route-planner .map-container {
height: 500px; height: 500px;
} }
section.route-planner .map-container .leaflet-tooltip-pane .text {
background: transparent;
border:0;
box-shadow: none;
color: white;
font-weight: bold;
}
@media (max-width: 639px) { @media (max-width: 639px) {
section.route-planner { section.route-planner {
grid-template-columns: 1fr; grid-template-columns: 1fr;

Loading…
Cancel
Save