X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/aafb1db2be953bd854d2a4e9fdab644db00f8958..efd50cd529990069dc1ca95f66ec6f61471fe29d:/app/assets/javascripts/index/directions.js diff --git a/app/assets/javascripts/index/directions.js b/app/assets/javascripts/index/directions.js index 1ad7f9cb7..8a80328cc 100644 --- a/app/assets/javascripts/index/directions.js +++ b/app/assets/javascripts/index/directions.js @@ -40,7 +40,8 @@ OSM.Directions = function (map) { shadowUrl: OSM.MARKER_SHADOW, shadowSize: [41, 41] }), - draggable: true + draggable: true, + autoPan: true }); endpoint.marker.on('drag dragend', function (e) { @@ -53,7 +54,13 @@ OSM.Directions = function (map) { } }); + input.on("keydown", function() { + input.removeClass("error"); + }); + input.on("change", function (e) { + awaitingGeocode = true; + // make text the same in both text boxes var value = e.target.value; endpoint.setValue(value); @@ -62,6 +69,7 @@ OSM.Directions = function (map) { endpoint.setValue = function(value, latlng) { endpoint.value = value; delete endpoint.latlng; + input.removeClass("error"); input.val(value); if (latlng) { @@ -84,16 +92,14 @@ OSM.Directions = function (map) { endpoint.awaitingGeocode = false; endpoint.hasGeocode = true; if (json.length === 0) { - alert(I18n.t('javascripts.directions.errors.no_place')); + input.addClass("error"); + alert(I18n.t('javascripts.directions.errors.no_place', {place: endpoint.value})); return; } - input.val(json[0].display_name); + endpoint.setLatLng(L.latLng(json[0])); - endpoint.latlng = L.latLng(json[0]); - endpoint.marker - .setLatLng(endpoint.latlng) - .addTo(map); + input.val(json[0].display_name); if (awaitingGeocode) { awaitingGeocode = false;