]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/application.js
Basic javascript cleanup
[rails.git] / app / assets / javascripts / application.js
index 78cbb57ea94148a3ed9ea14e4eda4a30edb96afc..df8dcda15eade9cd7c2004ea3cc76c2eed381190 100644 (file)
 //= require export
 //= require map
 //= require menu
+//= require sidebar
+
+function zoomPrecision(zoom) {
+    var decimals = Math.pow(10, Math.floor(zoom/3));
+    return function(x) {
+         return Math.round(x * decimals) / decimals;
+    };
+}
 
 /*
  * Called as the user scrolls/zooms around to aniplate hrefs of the
  * view tab and various other links
  */
 function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat,objtype,objid) {
-  var decimals = Math.pow(10, Math.floor(zoom/3));
+  var toPrecision = zoomPrecision(zoom);
   var node;
 
-  lat = Math.round(lat * decimals) / decimals;
-  lon = Math.round(lon * decimals) / decimals;
+  lat = toPrecision(lat);
+  lon = toPrecision(lon);
 
   if (minlon) {
-    minlon = Math.round(minlon * decimals) / decimals;
-    minlat = Math.round(minlat * decimals) / decimals;
-    maxlon = Math.round(maxlon * decimals) / decimals;
-    maxlat = Math.round(maxlat * decimals) / decimals;
+    minlon = toPrecision(minlon);
+    minlat = toPrecision(minlat);
+    maxlon = toPrecision(maxlon);
+    maxlat = toPrecision(maxlat);
   }
 
   $(".geolink").each(function (index, link) {