]> git.openstreetmap.org Git - rails.git/commitdiff
zoomPrecision doesn't need to be higher-order
authorJohn Firebaugh <john.firebaugh@gmail.com>
Wed, 24 Jul 2013 00:32:54 +0000 (17:32 -0700)
committerJohn Firebaugh <john.firebaugh@gmail.com>
Tue, 30 Jul 2013 22:41:41 +0000 (15:41 -0700)
app/assets/javascripts/application.js
app/assets/javascripts/index/export.js
app/assets/javascripts/leaflet.extend.js.erb

index e54498834c3bdbcb70770efd2b2a8afe1ffc44e7..18b1515c59b121c6bd4cc06d0f91e488456bffb6 100644 (file)
 var querystring = require('querystring-component');
 
 function zoomPrecision(zoom) {
-    var decimals = Math.pow(10, Math.floor(zoom/3));
-    return function(x) {
-         return Math.round(x * decimals) / decimals;
-    };
+    return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
 }
 
 function normalBounds(bounds) {
@@ -62,18 +59,17 @@ function remoteEditHandler(bbox, select) {
  * view tab and various other links
  */
 function updatelinks(loc, zoom, layers, bounds, object) {
-  var toPrecision = zoomPrecision(zoom);
+  var precision = zoomPrecision(zoom);
   bounds = normalBounds(bounds);
-  var node;
 
-  var lat = toPrecision(loc.lat),
-      lon = toPrecision(loc.lon || loc.lng);
+  var lat = loc.lat.toFixed(precision),
+      lon = (loc.lon || loc.lng).toFixed(precision);
 
   if (bounds) {
-    var minlon = toPrecision(bounds.getWest()),
-        minlat = toPrecision(bounds.getSouth()),
-        maxlon = toPrecision(bounds.getEast()),
-        maxlat = toPrecision(bounds.getNorth());
+    var minlon = bounds.getWest().toFixed(precision),
+        minlat = bounds.getSouth().toFixed(precision),
+        maxlon = bounds.getEast().toFixed(precision),
+        maxlat = bounds.getNorth().toFixed(precision);
   }
 
   $(".geolink").each(setGeolink);
index 417dfabd35be892cdf5e9ad391083d30c35de215..47830f8beea33111284db05b264eebdaeb694650 100644 (file)
@@ -150,12 +150,12 @@ function initializeExport(map) {
     }
 
     function setBounds(bounds) {
-      var toPrecision = zoomPrecision(map.getZoom());
+      var precision = zoomPrecision(map.getZoom());
 
-      $("#minlon").val(toPrecision(bounds.getWest()));
-      $("#minlat").val(toPrecision(bounds.getSouth()));
-      $("#maxlon").val(toPrecision(bounds.getEast()));
-      $("#maxlat").val(toPrecision(bounds.getNorth()));
+      $("#minlon").val(bounds.getWest().toFixed(precision));
+      $("#minlat").val(bounds.getSouth().toFixed(precision));
+      $("#maxlon").val(bounds.getEast().toFixed(precision));
+      $("#maxlat").val(bounds.getNorth().toFixed(precision));
 
       mapnikSizeChanged();
       htmlUrlChanged();
index f1abfb4bab61de9144a1bf91255d5d8ff07d88d7..91cb12091140718376cd845659f057302d70cf93 100644 (file)
@@ -31,17 +31,17 @@ L.extend(L.Map.prototype, {
   getUrl: function(marker) {
     var center = this.getCenter(),
         zoom = this.getZoom(),
-        toZoom = zoomPrecision(zoom),
+        precision = zoomPrecision(zoom),
         params = {
-          lat: toZoom(center.lat),
-          lon: toZoom(center.lng),
+          lat: center.lat.toFixed(precision),
+          lon: center.lng.toFixed(precision),
           zoom: zoom,
           layers: this.getLayersCode()
         };
 
     if (marker && this.hasLayer(marker)) {
-      params.mlat = toZoom(marker.getLatLng().lat);
-      params.mlon = toZoom(marker.getLatLng().lng);
+      params.mlat = marker.getLatLng().lat.toFixed(precision);
+      params.mlon = marker.getLatLng().lng.toFixed(precision);
     }
 
     return 'http://' + OSM.SERVER_URL + '/?' + querystring.stringify(params);