From 75b771e2a9dc582d43bb7998ea73691504321233 Mon Sep 17 00:00:00 2001 From: Norbert Renner Date: Sat, 4 Apr 2015 14:58:02 +0200 Subject: [PATCH] add button to clear route --- .gitignore | 1 + bower.json | 4 +++- js/index.js | 21 +++++++++++++++++++-- js/plugin/Routing.js | 8 ++++++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 8934483..9beba72 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ bower_components/ node_modules/ nbproject/ .idea/ +bingkey.txt diff --git a/bower.json b/bower.json index 2c2de74..998f225 100644 --- a/bower.json +++ b/bower.json @@ -16,7 +16,9 @@ "bootstrap": "~3.3.4", "DataTables": "~1.10.5", "Leaflet.Elevation": "MrMufflon/Leaflet.Elevation#master", - "leaflet-control-geocoder": "~1.1.0" + "leaflet-control-geocoder": "~1.1.0", + "L.EasyButton": "*", + "bootbox": "~4.4.0" }, "overrides": { "leaflet": { diff --git a/js/index.js b/js/index.js index c82ca1e..7fac1c2 100644 --- a/js/index.js +++ b/js/index.js @@ -107,6 +107,8 @@ download, profile, trackMessages, + routingToolbar, + permalink, leftPaneId = 'leftpane', saveWarningShown = false; @@ -118,6 +120,21 @@ router = L.bRouter(); //brouterCgi dummyRouter + routingToolbar = L.easyButton( + 'glyphicon-trash', + function () { + bootbox.confirm("Delete route?", function(result) { + if (result) { + routing.clear(); + onUpdate(); + permalink._update_routing(); + } + }); + }, + 'Clear route', + map + ); + function updateRoute(evt) { router.setOptions(evt.options); @@ -256,7 +273,7 @@ router.setOptions(routingOptions.getOptions()); profile.update(routingOptions.getOptions()); - map.addControl(new L.Control.Permalink({ + permalink = new L.Control.Permalink({ text: 'Permalink', position: 'bottomright', layers: layersControl, @@ -265,7 +282,7 @@ router: router, routing: routing, profile: profile - })); + }).addTo(map); } initMap(); diff --git a/js/plugin/Routing.js b/js/plugin/Routing.js index c8181b0..e8561bf 100644 --- a/js/plugin/Routing.js +++ b/js/plugin/Routing.js @@ -96,7 +96,11 @@ BR.Routing = L.Routing.extend({ } ,clear: function() { + var drawEnabled = this._draw._enabled; var current = this._waypoints._first; + + this._draw.disable(); + if (current === null) { return; } this._removeMarkerEvents(current); while (current._routing.nextMarker) { @@ -109,6 +113,10 @@ BR.Routing = L.Routing.extend({ this._waypoints._last = null; this._waypoints.clearLayers(); this._segments.clearLayers(); + + if (drawEnabled) { + this._draw.enable(); + } } ,setWaypoints: function(latLngs, cb) {