Toggle drawing mode via panel button (#41)

This commit is contained in:
Gautier Pelloux-Prayer 2016-07-28 20:52:24 +02:00
parent 4d76d87709
commit fcfc1d5cfe
4 changed files with 35 additions and 6 deletions

File diff suppressed because one or more lines are too long

4
dist/brouter-web.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -163,7 +163,27 @@
router = L.bRouter(); //brouterCgi dummyRouter router = L.bRouter(); //brouterCgi dummyRouter
routingToolbar = L.easyButton( drawButton = L.easyButton({
states: [{
stateName: 'deactivate-draw',
icon: 'glyphicon-ok',
onClick: function (control) {
routing.draw(false);
control.state('activate-draw');
},
title: 'Stop drawing route'
}, {
stateName: 'activate-draw',
icon: 'glyphicon-road',
onClick: function (control) {
routing.draw(true);
control.state('deactivate-draw');
},
title: 'Draw route'
}]
});
deleteButton = L.easyButton(
'glyphicon-trash', 'glyphicon-trash',
function () { function () {
bootbox.confirm({ bootbox.confirm({
@ -179,7 +199,9 @@
}); });
}, },
'Clear route' 'Clear route'
).addTo(map); );
drawToolbar = L.easyBar([drawButton, deleteButton]).addTo(map);
function updateRoute(evt) { function updateRoute(evt) {
router.setOptions(evt.options); router.setOptions(evt.options);
@ -276,10 +298,17 @@
} }
} }
}); });
routing.on('routing:routeWaypointEnd routing:setWaypointsEnd', function(evt) { routing.on('routing:routeWaypointEnd routing:setWaypointsEnd', function(evt) {
search.clear(); search.clear();
onUpdate(evt && evt.err); onUpdate(evt && evt.err);
}); });
map.on('routing:draw-start', function() {
drawButton.state('deactivate-draw');
});
map.on('routing:draw-end', function() {
drawButton.state('activate-draw');
});
function onUpdate(err) { function onUpdate(err) {
if (err) { if (err) {