Skip to content

Commit

Permalink
Swap cached reverse geocodes when reversing directions
Browse files Browse the repository at this point in the history
Do this instead of putting reversed input values into url.
  • Loading branch information
AntonKhorev committed Aug 14, 2024
1 parent 8db2c54 commit e671394
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 9 additions & 0 deletions app/assets/javascripts/index/directions-endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch
map.removeLayer(endpoint.marker);
};

endpoint.swapCachedReverseGeocodes = function (otherEndpoint) {
var g0 = endpoint.cachedReverseGeocode;
var g1 = otherEndpoint.cachedReverseGeocode;
delete endpoint.cachedReverseGeocode;
delete otherEndpoint.cachedReverseGeocode;
if (g0) otherEndpoint.cachedReverseGeocode = g0;
if (g1) endpoint.cachedReverseGeocode = g1;
};

function getGeocode() {
var viewbox = map.getBounds().toBBoxString(); // <sw lon>,<sw lat>,<ne lon>,<ne lat>
var geocodeUrl = OSM.NOMINATIM_URL + "search?q=" + encodeURIComponent(endpoint.value) + "&format=json&viewbox=" + viewbox;
Expand Down
3 changes: 1 addition & 2 deletions app/assets/javascripts/index/directions.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ OSM.Directions = function (map) {
if (coordTo) {
routeTo = coordTo.lat + "," + coordTo.lng;
}
endpoints[0].swapCachedReverseGeocodes(endpoints[1]);

OSM.router.route("/directions?" + Qs.stringify({
from: $("#route_to").val(),
to: $("#route_from").val(),
route: routeTo + ";" + routeFrom
}));
});
Expand Down

0 comments on commit e671394

Please sign in to comment.