add button to clear route

This commit is contained in:
Norbert Renner 2015-04-04 14:58:02 +02:00
parent 1bd2eb0082
commit 75b771e2a9
4 changed files with 31 additions and 3 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@ bower_components/
node_modules/ node_modules/
nbproject/ nbproject/
.idea/ .idea/
bingkey.txt

View file

@ -16,7 +16,9 @@
"bootstrap": "~3.3.4", "bootstrap": "~3.3.4",
"DataTables": "~1.10.5", "DataTables": "~1.10.5",
"Leaflet.Elevation": "MrMufflon/Leaflet.Elevation#master", "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": { "overrides": {
"leaflet": { "leaflet": {

View file

@ -107,6 +107,8 @@
download, download,
profile, profile,
trackMessages, trackMessages,
routingToolbar,
permalink,
leftPaneId = 'leftpane', leftPaneId = 'leftpane',
saveWarningShown = false; saveWarningShown = false;
@ -118,6 +120,21 @@
router = L.bRouter(); //brouterCgi dummyRouter 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) { function updateRoute(evt) {
router.setOptions(evt.options); router.setOptions(evt.options);
@ -256,7 +273,7 @@
router.setOptions(routingOptions.getOptions()); router.setOptions(routingOptions.getOptions());
profile.update(routingOptions.getOptions()); profile.update(routingOptions.getOptions());
map.addControl(new L.Control.Permalink({ permalink = new L.Control.Permalink({
text: 'Permalink', text: 'Permalink',
position: 'bottomright', position: 'bottomright',
layers: layersControl, layers: layersControl,
@ -265,7 +282,7 @@
router: router, router: router,
routing: routing, routing: routing,
profile: profile profile: profile
})); }).addTo(map);
} }
initMap(); initMap();

View file

@ -96,7 +96,11 @@ BR.Routing = L.Routing.extend({
} }
,clear: function() { ,clear: function() {
var drawEnabled = this._draw._enabled;
var current = this._waypoints._first; var current = this._waypoints._first;
this._draw.disable();
if (current === null) { return; } if (current === null) { return; }
this._removeMarkerEvents(current); this._removeMarkerEvents(current);
while (current._routing.nextMarker) { while (current._routing.nextMarker) {
@ -109,6 +113,10 @@ BR.Routing = L.Routing.extend({
this._waypoints._last = null; this._waypoints._last = null;
this._waypoints.clearLayers(); this._waypoints.clearLayers();
this._segments.clearLayers(); this._segments.clearLayers();
if (drawEnabled) {
this._draw.enable();
}
} }
,setWaypoints: function(latLngs, cb) { ,setWaypoints: function(latLngs, cb) {