JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css">
<script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
<div id="map"></div> http://jsfiddle.net/#run
CSS
#map {
height: 400px;
}
JavaScript
var map = L.map('map').setView([36.83711,-2.464459], 5);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{maxZoom: 18}).addTo(map);
var marker = L.marker([36.83711, -2.464459]).addTo(map);
var myLines = [{
"type": "LineString",
"coordinates": [[-2.464459, 36.83711],[-2.46, 34]]
}, {
"type": "LineString",
"coordinates": [[-2.464459,36.83711],[2.46, 39]]
}, {
"type": "LineString",
"coordinates": [[-2.464459,36.83711],[-4, 40]]
}];
var myStyle = {
"color": "#ff7800",
"weight": 5,
"opacity": 0.65
};
var myLayer = L.geoJson(myLines, {
style: myStyle
}).addTo(map);
marker.on('contextmenu', function(e) {
e.target.dragging.enable();
window.if_start = [];
window.if_end = [];
myLayer.eachLayer(function(line) {
latlngs = line.getLatLngs();
if (latlngs[0].equals(e.target.getLatLng())) {
window.if_start[window.if_start.length] = line;
}
if (latlngs[latlngs.length-1].equals(e.target.getLatLng())) {
window.if_end[window.if_end.length] = line;
}
});
});
marker.on('drag', function(e) {
for (i in window.if_start) {
line = window.if_start[i];
line.spliceLatLngs(0,1,marker.getLatLng());
line.redraw();
}
for (i in window.if_end) {
line = window.if_end[i];
latlngs = line.getLatLngs();
line.spliceLatLngs(latlngs.length-1,1, marker.getLatLng());
line.redraw();
}
});