From b5070d97a96a20ba1db43ae6a3aa87dc3273b989 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sat, 15 Jun 2024 22:04:15 +0300 Subject: [PATCH] Introduce geocode event callback for route endpoints Removes remaining getRoute() call from endpoint objects. --- app/assets/javascripts/index/directions.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index 8d9263323..ae01cb566 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -25,10 +25,13 @@ OSM.Directions = function (map) { getRoute(false, !dragging); } }; + var endpointGeocodeCallback = function () { + getRoute(true, true); + }; var endpoints = [ - Endpoint($("input[name='route_from']"), OSM.MARKER_GREEN, endpointDragCallback), - Endpoint($("input[name='route_to']"), OSM.MARKER_RED, endpointDragCallback) + Endpoint($("input[name='route_from']"), OSM.MARKER_GREEN, endpointDragCallback, endpointGeocodeCallback), + Endpoint($("input[name='route_to']"), OSM.MARKER_RED, endpointDragCallback, endpointGeocodeCallback) ]; var expiry = new Date(); @@ -48,7 +51,7 @@ OSM.Directions = function (map) { select.append(""); }); - function Endpoint(input, iconUrl, dragCallback) { + function Endpoint(input, iconUrl, dragCallback, geocodeCallback) { var endpoint = {}; endpoint.marker = L.marker([0, 0], { @@ -119,7 +122,7 @@ OSM.Directions = function (map) { input.val(json[0].display_name); - getRoute(true, true); + geocodeCallback(); }); }; -- 2.39.5