Is there a simple way to shorten lines on a GeoJSON layer?
I have a line, it goes from point A to point B. I want the line to stop the radius of a marker short of it\'s
That can be done using the dashArray
and dashOffset
options:
var map = new L.Map('leaflet', {
center: [0, 0],
zoom: 0
});
new L.CircleMarker([0, 90], {radius: 30}).addTo(map);
new L.CircleMarker([0, -90], {radius: 30}).addTo(map);
var polyline = new L.Polyline([[0, -90], [0, 90]]).addTo(map);
// Get length of the line
var totalLength = polyline.getElement().getTotalLength();
polyline.setStyle({
// Set dashArray to the length of the line minus radius * 2
dashArray: totalLength - 60,
// Offset by radius
dashOffset: -30
});
body {
margin: 0;
}
html, body, #leaflet {
height: 100%;
}
Leaflet 1.2.0