]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/directions-endpoint.js
Add coordinate precision function
[rails.git] / app / assets / javascripts / index / directions-endpoint.js
index 3ffb9b498723f06363cfe1f94c246e39ec864ca9..2cc3ea66256488c3bbd426d31f175e3836b3c3dd 100644 (file)
@@ -27,11 +27,14 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch
 
     if (endpoint.geocodeRequest) endpoint.geocodeRequest.abort();
     delete endpoint.geocodeRequest;
+    removeLatLng();
+    delete endpoint.value;
+    input.val("");
     map.removeLayer(endpoint.marker);
   };
 
   function markerDragListener(e) {
-    var latlng = convertLatLngToZoomPrecision(e.target.getLatLng());
+    const latlng = L.latLng(OSM.cropLocation(e.target.getLatLng(), map.getZoom()));
 
     setLatLng(latlng);
     setInputValueFromLatLng(latlng);
@@ -106,11 +109,5 @@ OSM.DirectionsEndpoint = function Endpoint(map, input, iconUrl, dragCallback, ch
     input.val(latlng.lat + ", " + latlng.lng);
   }
 
-  function convertLatLngToZoomPrecision(latlng) {
-    var precision = OSM.zoomPrecision(map.getZoom());
-
-    return L.latLng(latlng.lat.toFixed(precision), latlng.lng.toFixed(precision));
-  }
-
   return endpoint;
 };