Small preact-based (like React.js) project https://inga-lovinde.github.io/static/komoot-demo/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

43 lines
1.2 KiB

import leaflet from 'leaflet';
import { Marker } from '../../types';
export const getLayersForMarkers = (markers: Marker[]) => [
// lines
...markers.flatMap((thisMarker, i) => {
const previousMarker = markers[i - 1];
if (!previousMarker) {
return [];
}
return [
leaflet.polyline([
previousMarker.coordinates,
thisMarker.coordinates,
]),
];
}),
// circles and labels
...markers.flatMap((marker) => {
const circle = leaflet.circleMarker(marker.coordinates, {
bubblingMouseEvents: false,
color: 'black',
fill: true,
fillOpacity: 100,
radius: 10,
});
const tooltip = leaflet
.tooltip(
{
permanent: true,
direction: 'center',
className: 'text',
content: marker.shortLabel,
},
circle,
)
.setLatLng(marker.coordinates);
circle.on('click', marker.remove);
return [circle, tooltip];
}),
];