Introduce drag event callback for route endpoints
Avoids calling getRoute() from within endpoint objects.
This commit is contained in:
parent
84aa7f455a
commit
d3ab0c9a8a
1 changed files with 10 additions and 6 deletions
|
@ -20,9 +20,15 @@ OSM.Directions = function (map) {
|
|||
weight: 12
|
||||
});
|
||||
|
||||
var endpointDragCallback = function (dragging) {
|
||||
if (map.hasLayer(polyline)) {
|
||||
getRoute(false, !dragging);
|
||||
}
|
||||
};
|
||||
|
||||
var endpoints = [
|
||||
Endpoint($("input[name='route_from']"), OSM.MARKER_GREEN),
|
||||
Endpoint($("input[name='route_to']"), OSM.MARKER_RED)
|
||||
Endpoint($("input[name='route_from']"), OSM.MARKER_GREEN, endpointDragCallback),
|
||||
Endpoint($("input[name='route_to']"), OSM.MARKER_RED, endpointDragCallback)
|
||||
];
|
||||
|
||||
var expiry = new Date();
|
||||
|
@ -42,7 +48,7 @@ OSM.Directions = function (map) {
|
|||
select.append("<option value='" + i + "'>" + I18n.t("javascripts.directions.engines." + engine.id) + "</option>");
|
||||
});
|
||||
|
||||
function Endpoint(input, iconUrl) {
|
||||
function Endpoint(input, iconUrl, dragCallback) {
|
||||
var endpoint = {};
|
||||
|
||||
endpoint.marker = L.marker([0, 0], {
|
||||
|
@ -63,9 +69,7 @@ OSM.Directions = function (map) {
|
|||
if (dragging && !chosenEngine.draggable) return;
|
||||
if (dragging && awaitingRoute) return;
|
||||
endpoint.setLatLng(e.target.getLatLng());
|
||||
if (map.hasLayer(polyline)) {
|
||||
getRoute(false, !dragging);
|
||||
}
|
||||
dragCallback(dragging);
|
||||
});
|
||||
|
||||
input.on("keydown", function () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue