From 66039dedb069400298717415e7c9ce4e444bfcdb Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 27 Feb 2014 18:15:54 +0000 Subject: [PATCH] Move zoomPrecision function to the OSM namespace --- app/assets/javascripts/application.js | 4 ---- app/assets/javascripts/index.js | 2 +- app/assets/javascripts/index/export.js | 2 +- app/assets/javascripts/leaflet.map.js.erb | 2 +- app/assets/javascripts/osm.js.erb | 6 +++++- app/assets/javascripts/user.js | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 5d18f1da2..75b48ac87 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -20,10 +20,6 @@ var querystring = require('querystring-component'); -function zoomPrecision(zoom) { - return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2)); -} - function remoteEditHandler(bbox, object) { var loaded = false, query = { diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index 55e612f17..4a9abc4dc 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -333,7 +333,7 @@ $(document).ready(function () { $(".describe_location").on("click", function(e) { e.preventDefault(); - var precision = zoomPrecision(map.getZoom()); + var precision = OSM.zoomPrecision(map.getZoom()); OSM.router.route("/search?query=" + encodeURIComponent( map.getCenter().lat.toFixed(precision) + "," + map.getCenter().lng.toFixed(precision))); diff --git a/app/assets/javascripts/index/export.js b/app/assets/javascripts/index/export.js index fd658c532..6e6867e5b 100644 --- a/app/assets/javascripts/index/export.js +++ b/app/assets/javascripts/index/export.js @@ -36,7 +36,7 @@ OSM.Export = function(map) { } function setBounds(bounds) { - var precision = zoomPrecision(map.getZoom()); + var precision = OSM.zoomPrecision(map.getZoom()); $("#minlon").val(bounds.getWest().toFixed(precision)); $("#minlat").val(bounds.getSouth().toFixed(precision)); $("#maxlon").val(bounds.getEast().toFixed(precision)); diff --git a/app/assets/javascripts/leaflet.map.js.erb b/app/assets/javascripts/leaflet.map.js.erb index 7ae330d9b..35370ae99 100644 --- a/app/assets/javascripts/leaflet.map.js.erb +++ b/app/assets/javascripts/leaflet.map.js.erb @@ -91,7 +91,7 @@ L.OSM.Map = L.Map.extend({ }, getUrl: function(marker) { - var precision = zoomPrecision(this.getZoom()), + var precision = OSM.zoomPrecision(this.getZoom()), params = {}; if (marker && this.hasLayer(marker)) { diff --git a/app/assets/javascripts/osm.js.erb b/app/assets/javascripts/osm.js.erb index 922bd2639..382e32bdf 100644 --- a/app/assets/javascripts/osm.js.erb +++ b/app/assets/javascripts/osm.js.erb @@ -153,7 +153,7 @@ OSM = { center = center.wrap(); layers = layers.replace('M', ''); - var precision = zoomPrecision(zoom), + var precision = OSM.zoomPrecision(zoom), hash = '#map=' + zoom + '/' + center.lat.toFixed(precision) + '/' + center.lng.toFixed(precision); @@ -163,5 +163,9 @@ OSM = { } return hash; + }, + + zoomPrecision: function (zoom) { + return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2)); } }; diff --git a/app/assets/javascripts/user.js b/app/assets/javascripts/user.js index 6a0d38dd5..fb4aa0300 100644 --- a/app/assets/javascripts/user.js +++ b/app/assets/javascripts/user.js @@ -36,7 +36,7 @@ $(document).ready(function () { map.on("click", function (e) { if ($('#updatehome').is(':checked')) { var zoom = map.getZoom(), - precision = zoomPrecision(zoom), + precision = OSM.zoomPrecision(zoom), location = e.latlng.wrap(); $('#homerow').removeClass(); -- 2.39.5