editor: Add function to reset path

This commit is contained in:
Markus Koch 2020-04-19 20:36:47 +02:00
parent 4c7590a212
commit 90161e098a

View File

@ -57,6 +57,8 @@ if (editor_mode) {
for (var i = 0; i < coords.length; i++) {
coords[i] = [coords[i][1], coords[i][0]];
}
if (polyline)
polyline.remove(mymap);
polyline = L.polyline(coords).addTo(mymap);
// polyline.on('dragend', onDragEnd); // TODO: Doesn't work, see "workaround" below
polyline.enableEdit();
@ -65,7 +67,6 @@ if (editor_mode) {
function editor_onHashChange() {
if (("#" + get_location_string()) != window.location.hash) {
polyline.remove(mymap);
onLoad(0);
}
}
@ -78,7 +79,6 @@ if (editor_mode) {
document.getElementById('mapid').classList.add("no-aa");
mymap.setMaxZoom(14);
mymap.off('click', onMapClick);
onLoad();
function get_location_string() {
var latlngs = polyline.getLatLngs();
@ -98,6 +98,10 @@ if (editor_mode) {
prompt("Copy this string back into the Wiki and wait for a few hours:", get_location_string());
}
function reset_path(e) {
onLoad(1);
}
L.EditControl = L.Control.extend({
options: {
position: 'topleft',
@ -120,6 +124,15 @@ if (editor_mode) {
}
});
L.ResetPathControl = L.EditControl.extend({
options: {
position: 'topleft',
callback: reset_path,
title: 'Enter path coordinates',
html: '↺'
}
});
L.StartEditControl = L.EditControl.extend({
options: {
position: 'topleft',
@ -139,5 +152,8 @@ if (editor_mode) {
});
mymap.addControl(new L.NewLineControl());
mymap.addControl(new L.ResetPathControl());
mymap.addControl(new L.StartEditControl());
onLoad();
}