X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/bb9a8958fb5bbe630da5c4bfd592a96b259df5b3..79158c50e91b9d8d2a43d45142f2ff6df3a91632:/app/assets/javascripts/index/directions-endpoint.js diff --git a/app/assets/javascripts/index/directions-endpoint.js b/app/assets/javascripts/index/directions-endpoint.js index b475b9a05..604dcc2b6 100644 --- a/app/assets/javascripts/index/directions-endpoint.js +++ b/app/assets/javascripts/index/directions-endpoint.js @@ -42,6 +42,7 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch setLatLng(latlng); setInputValueFromLatLng(latlng); endpoint.value = input.val(); + if (e.type === "dragend") getReverseGeocode(); dragCallback(e.type === "drag"); } @@ -70,6 +71,7 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch if (latlng) { setLatLng(latlng); setInputValueFromLatLng(latlng); + getReverseGeocode(); changeCallback(); } else if (endpoint.value) { getGeocode(); @@ -96,6 +98,20 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch }); } + function getReverseGeocode() { + var reverseGeocodeUrl = OSM.NOMINATIM_URL + "reverse?lat=" + endpoint.latlng.lat + "&lon=" + endpoint.latlng.lng + "&format=json"; + + endpoint.geocodeRequest = $.getJSON(reverseGeocodeUrl, function (json) { + delete endpoint.geocodeRequest; + if (!json || !json.display_name) { + return; + } + + endpoint.value = json.display_name; + input.val(json.display_name); + }); + } + function setLatLng(ll) { input .attr("data-lat", ll.lat)