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++) { for (var i = 0; i < coords.length; i++) {
coords[i] = [coords[i][1], coords[i][0]]; coords[i] = [coords[i][1], coords[i][0]];
} }
if (polyline)
polyline.remove(mymap);
polyline = L.polyline(coords).addTo(mymap); polyline = L.polyline(coords).addTo(mymap);
// polyline.on('dragend', onDragEnd); // TODO: Doesn't work, see "workaround" below // polyline.on('dragend', onDragEnd); // TODO: Doesn't work, see "workaround" below
polyline.enableEdit(); polyline.enableEdit();
@ -65,7 +67,6 @@ if (editor_mode) {
function editor_onHashChange() { function editor_onHashChange() {
if (("#" + get_location_string()) != window.location.hash) { if (("#" + get_location_string()) != window.location.hash) {
polyline.remove(mymap);
onLoad(0); onLoad(0);
} }
} }
@ -78,7 +79,6 @@ if (editor_mode) {
document.getElementById('mapid').classList.add("no-aa"); document.getElementById('mapid').classList.add("no-aa");
mymap.setMaxZoom(14); mymap.setMaxZoom(14);
mymap.off('click', onMapClick); mymap.off('click', onMapClick);
onLoad();
function get_location_string() { function get_location_string() {
var latlngs = polyline.getLatLngs(); 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()); 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({ L.EditControl = L.Control.extend({
options: { options: {
position: 'topleft', 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({ L.StartEditControl = L.EditControl.extend({
options: { options: {
position: 'topleft', position: 'topleft',
@ -139,5 +152,8 @@ if (editor_mode) {
}); });
mymap.addControl(new L.NewLineControl()); mymap.addControl(new L.NewLineControl());
mymap.addControl(new L.ResetPathControl());
mymap.addControl(new L.StartEditControl()); mymap.addControl(new L.StartEditControl());
onLoad();
} }