X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/fd7840d5f16f21431fb4f0b1d62387cd045b1da4..953d8b4b59e8b194bf83b094ecfd9f5e368a04b8:/app/assets/javascripts/index/directions-endpoint.js?ds=sidebyside diff --git a/app/assets/javascripts/index/directions-endpoint.js b/app/assets/javascripts/index/directions-endpoint.js index 0f53e77d9..14c91a4fb 100644 --- a/app/assets/javascripts/index/directions-endpoint.js +++ b/app/assets/javascripts/index/directions-endpoint.js @@ -15,7 +15,11 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ge }); endpoint.marker.on("drag dragend", function (e) { - endpoint.setLatLng(e.target.getLatLng()); + var latlng = e.target.getLatLng(); + + setLatLng(latlng); + setInputValueFromLatLng(latlng); + endpoint.value = input.val(); dragCallback(e.type === "drag"); }); @@ -36,7 +40,8 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ge input.val(value); if (latlng) { - endpoint.setLatLng(latlng); + setLatLng(latlng); + setInputValueFromLatLng(latlng); } else { endpoint.getGeocode(); } @@ -62,7 +67,7 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ge return; } - endpoint.setLatLng(L.latLng(json[0])); + setLatLng(L.latLng(json[0])); input.val(json[0].display_name); @@ -70,15 +75,19 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ge }); }; - endpoint.setLatLng = function (ll) { - var precision = OSM.zoomPrecision(map.getZoom()); - input.val(ll.lat.toFixed(precision) + ", " + ll.lng.toFixed(precision)); + function setLatLng(ll) { endpoint.hasGeocode = true; endpoint.latlng = ll; endpoint.marker .setLatLng(ll) .addTo(map); - }; + } + + function setInputValueFromLatLng(latlng) { + var precision = OSM.zoomPrecision(map.getZoom()); + + input.val(latlng.lat.toFixed(precision) + ", " + latlng.lng.toFixed(precision)); + } return endpoint; };