From 34eea5d8f06bc7bd308baac5b9e5831a0a6ec1cf Mon Sep 17 00:00:00 2001 From: Inga Date: Thu, 16 Nov 2023 18:50:10 +0000 Subject: [PATCH] improved design, fixed HMR --- src/routePlanner/map.tsx | 47 ++++++++++++++++++++++++++---------- src/routePlanner/markers.tsx | 6 ++--- src/routePlanner/style.css | 8 ++++++ 3 files changed, 44 insertions(+), 17 deletions(-) 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) => { <>

Markers

    - {markers.map(({ key, coordinates }) => ( -
  1. - {coordinates.lat}, {coordinates.lng} -
  2. + {markers.map(({ key }, i) => ( +
  3. {`Waypoint ${i + 1}`}
  4. ))}
diff --git a/src/routePlanner/style.css b/src/routePlanner/style.css index 317a55b..2662279 100644 --- a/src/routePlanner/style.css +++ b/src/routePlanner/style.css @@ -19,6 +19,14 @@ section.route-planner .map-container { 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) { section.route-planner { grid-template-columns: 1fr;