]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/user.js
Don't autofocus search, fade out "Where am I?" on focus
[rails.git] / app / assets / javascripts / user.js
index 4e646771247c93dad7c67cbe4cd49fd76c85ae0d..80b5059157ac40b40e4e155cbd1ccf7fc43b3b1e 100644 (file)
@@ -1,15 +1,20 @@
+//= require leaflet.locate
+
 $(document).ready(function () {
   var map = L.map("map", {
     attributionControl: false,
     zoomControl: false
   }).addLayer(new L.OSM.Mapnik());
 
-  L.control.zoom({position: 'topright'})
+  L.OSM.zoom()
     .addTo(map);
 
-  $("#map").on("resized", function () {
-    map.invalidateSize();
-  });
+  L.control.locate({
+    strings: {
+      title: I18n.t('javascripts.map.locate.title'),
+      popup: I18n.t('javascripts.map.locate.popup')
+    }
+  }).addTo(map);
 
   if (OSM.home) {
     map.setView([OSM.home.lat, OSM.home.lon], 12);
@@ -27,9 +32,13 @@ $(document).ready(function () {
 
     map.on("click", function (e) {
       if ($('#updatehome').is(':checked')) {
+        var zoom = map.getZoom(),
+            precision = zoomPrecision(zoom),
+            location = e.latlng.wrap();
+
         $('#homerow').removeClass();
-        $('#home_lat').val(e.latlng.lat);
-        $('#home_lon').val(e.latlng.lng);
+        $('#home_lat').val(location.lat.toFixed(precision));
+        $('#home_lon').val(location.lng.toFixed(precision));
 
         marker.setLatLng(e.latlng);
         marker.addTo(map);