From 90161e098a03cf41343f4e335fbe4fdbe8766d05 Mon Sep 17 00:00:00 2001 From: Markus Koch Date: Sun, 19 Apr 2020 20:36:47 +0200 Subject: [PATCH] editor: Add function to reset path --- htdocs/streeteditor.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/htdocs/streeteditor.js b/htdocs/streeteditor.js index a5e9e17..5d69d0b 100644 --- a/htdocs/streeteditor.js +++ b/htdocs/streeteditor.js @@ -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(); }