Created
January 5, 2021 07:08
-
-
Save sinky/08e1127d62b3def85d49d41b28a4fd75 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/ronudux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
<style id="jsbin-css"> | |
#mapid { height: 500px; } | |
</style> | |
</head> | |
<body> | |
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" | |
integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A==" | |
crossorigin=""/> | |
<!-- Make sure you put this AFTER Leaflet's CSS --> | |
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js" | |
integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA==" | |
crossorigin=""></script> | |
<div id="mapid"></div> | |
<script id="jsbin-javascript"> | |
var map = L.map('mapid').setView([51.505, 7.09], 4); | |
var markers = [] | |
var polylines = [] | |
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { | |
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' | |
}).addTo(map); | |
function addMarker(e){ | |
var newMarker = new L.marker(e.latlng,{ | |
draggable: true | |
}).addTo(map); | |
markers.push(newMarker) | |
newMarker.bindPopup('test', { //prompt("Beschriftung für den Marker"), { | |
closeOnClick: false, | |
autoClose: false | |
}).openPopup(); | |
newMarker.on('dragend', function(e){ | |
drawLine() | |
}); | |
newMarker.on('click', function(e){ | |
if(e.originalEvent.ctrlKey) { | |
map.removeLayer(newMarker) | |
removeIndex = markers.indexOf(newMarker) | |
markers.splice(removeIndex, 1); | |
drawLine() | |
} | |
}); | |
drawLine() | |
} | |
function drawLine() { | |
removeLine() | |
if(markers.length > 1) { | |
for(i=0; i < markers.length-1; i++) { | |
var latlngs = Array(); | |
latlngs.push(markers[i].getLatLng()); | |
latlngs.push(markers[i+1].getLatLng()); | |
var polyline = L.polyline(latlngs, {color: 'red'}).addTo(map); | |
polylines.push(polyline) | |
} | |
} | |
} | |
function removeLine() { | |
for(i=0; i < polylines.length; i++) { | |
map.removeLayer(polylines[i]) | |
} | |
} | |
map.on('click', function(e){ | |
addMarker(e) | |
}); | |
</script> | |
<script id="jsbin-source-css" type="text/css">#mapid { height: 500px; } | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var map = L.map('mapid').setView([51.505, 7.09], 4); | |
var markers = [] | |
var polylines = [] | |
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { | |
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' | |
}).addTo(map); | |
function addMarker(e){ | |
var newMarker = new L.marker(e.latlng,{ | |
draggable: true | |
}).addTo(map); | |
markers.push(newMarker) | |
newMarker.bindPopup('test', { //prompt("Beschriftung für den Marker"), { | |
closeOnClick: false, | |
autoClose: false | |
}).openPopup(); | |
newMarker.on('dragend', function(e){ | |
drawLine() | |
}); | |
newMarker.on('click', function(e){ | |
if(e.originalEvent.ctrlKey) { | |
map.removeLayer(newMarker) | |
removeIndex = markers.indexOf(newMarker) | |
markers.splice(removeIndex, 1); | |
drawLine() | |
} | |
}); | |
drawLine() | |
} | |
function drawLine() { | |
removeLine() | |
if(markers.length > 1) { | |
for(i=0; i < markers.length-1; i++) { | |
var latlngs = Array(); | |
latlngs.push(markers[i].getLatLng()); | |
latlngs.push(markers[i+1].getLatLng()); | |
var polyline = L.polyline(latlngs, {color: 'red'}).addTo(map); | |
polylines.push(polyline) | |
} | |
} | |
} | |
function removeLine() { | |
for(i=0; i < polylines.length; i++) { | |
map.removeLayer(polylines[i]) | |
} | |
} | |
map.on('click', function(e){ | |
addMarker(e) | |
});</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#mapid { height: 500px; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var map = L.map('mapid').setView([51.505, 7.09], 4); | |
var markers = [] | |
var polylines = [] | |
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { | |
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' | |
}).addTo(map); | |
function addMarker(e){ | |
var newMarker = new L.marker(e.latlng,{ | |
draggable: true | |
}).addTo(map); | |
markers.push(newMarker) | |
newMarker.bindPopup('test', { //prompt("Beschriftung für den Marker"), { | |
closeOnClick: false, | |
autoClose: false | |
}).openPopup(); | |
newMarker.on('dragend', function(e){ | |
drawLine() | |
}); | |
newMarker.on('click', function(e){ | |
if(e.originalEvent.ctrlKey) { | |
map.removeLayer(newMarker) | |
removeIndex = markers.indexOf(newMarker) | |
markers.splice(removeIndex, 1); | |
drawLine() | |
} | |
}); | |
drawLine() | |
} | |
function drawLine() { | |
removeLine() | |
if(markers.length > 1) { | |
for(i=0; i < markers.length-1; i++) { | |
var latlngs = Array(); | |
latlngs.push(markers[i].getLatLng()); | |
latlngs.push(markers[i+1].getLatLng()); | |
var polyline = L.polyline(latlngs, {color: 'red'}).addTo(map); | |
polylines.push(polyline) | |
} | |
} | |
} | |
function removeLine() { | |
for(i=0; i < polylines.length; i++) { | |
map.removeLayer(polylines[i]) | |
} | |
} | |
map.on('click', function(e){ | |
addMarker(e) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment