parent
99ce0d97e1
commit
aec4d090f3
@ -0,0 +1,43 @@ |
||||
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]; |
||||
}), |
||||
]; |
Loading…
Reference in new issue