minor refactoring

main
Inga 🏳‍🌈 1 year ago
parent 4940a5f5df
commit 28401a26b2
  1. 2
      README.md
  2. 23
      src/routePlanner/map.tsx

@ -47,7 +47,7 @@ For development: `npm run dev`.
For release build that does not require any interactivity on server, `npm run start-release` For release build that does not require any interactivity on server, `npm run start-release`
(which lints and typechecks and tests everything, builds the project into static bundles in `dist/`, and serves static files from `dist` directory). (which lints and typechecks and tests everything, builds the project into static bundles in `dist/`, and serves static files from `dist` directory).
2
### Limitations, notes ### Limitations, notes
While the original task didn't mention it, it seemed like a good idea to make markers draggable (in order to be able to change the position of an existing marker). While the original task didn't mention it, it seemed like a good idea to make markers draggable (in order to be able to change the position of an existing marker).

@ -56,21 +56,22 @@ export const MapComponent = ({ markers, onMapClick }: MapProps) => {
return; return;
} }
const layers: leaflet.Layer[] = []; const layers = [
for (let i = 0; i < markers.length; i++) { // lines
const thisMarker = markers[i]; ...markers.flatMap((thisMarker, i) => {
const previousMarker = markers[i - 1]; const previousMarker = markers[i - 1];
if (thisMarker && previousMarker) { if (!previousMarker) {
layers.push( return [];
}
return [
leaflet.polyline([ leaflet.polyline([
previousMarker.coordinates, previousMarker.coordinates,
thisMarker.coordinates, thisMarker.coordinates,
]), ]),
); ];
} }),
} // circles and labels
layers.push(
...markers.flatMap((marker) => { ...markers.flatMap((marker) => {
const circle = leaflet.circleMarker(marker.coordinates, { const circle = leaflet.circleMarker(marker.coordinates, {
bubblingMouseEvents: false, bubblingMouseEvents: false,
@ -94,7 +95,7 @@ export const MapComponent = ({ markers, onMapClick }: MapProps) => {
circle.on('click', marker.remove); circle.on('click', marker.remove);
return [circle, tooltip]; return [circle, tooltip];
}), }),
); ];
for (const layer of layers) { for (const layer of layers) {
layer.addTo(map); layer.addTo(map);

Loading…
Cancel
Save