Move zoomPrecision function to the OSM namespace

This commit is contained in:
Tom Hughes
2014-02-27 18:15:54 +00:00
parent 665abc501c
commit 66039dedb0
6 changed files with 9 additions and 9 deletions

View File

@ -20,10 +20,6 @@
var querystring = require('querystring-component'); var querystring = require('querystring-component');
function zoomPrecision(zoom) {
return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
}
function remoteEditHandler(bbox, object) { function remoteEditHandler(bbox, object) {
var loaded = false, var loaded = false,
query = { query = {

View File

@ -333,7 +333,7 @@ $(document).ready(function () {
$(".describe_location").on("click", function(e) { $(".describe_location").on("click", function(e) {
e.preventDefault(); e.preventDefault();
var precision = zoomPrecision(map.getZoom()); var precision = OSM.zoomPrecision(map.getZoom());
OSM.router.route("/search?query=" + encodeURIComponent( OSM.router.route("/search?query=" + encodeURIComponent(
map.getCenter().lat.toFixed(precision) + "," + map.getCenter().lat.toFixed(precision) + "," +
map.getCenter().lng.toFixed(precision))); map.getCenter().lng.toFixed(precision)));

View File

@ -36,7 +36,7 @@ OSM.Export = function(map) {
} }
function setBounds(bounds) { function setBounds(bounds) {
var precision = zoomPrecision(map.getZoom()); var precision = OSM.zoomPrecision(map.getZoom());
$("#minlon").val(bounds.getWest().toFixed(precision)); $("#minlon").val(bounds.getWest().toFixed(precision));
$("#minlat").val(bounds.getSouth().toFixed(precision)); $("#minlat").val(bounds.getSouth().toFixed(precision));
$("#maxlon").val(bounds.getEast().toFixed(precision)); $("#maxlon").val(bounds.getEast().toFixed(precision));

View File

@ -91,7 +91,7 @@ L.OSM.Map = L.Map.extend({
}, },
getUrl: function(marker) { getUrl: function(marker) {
var precision = zoomPrecision(this.getZoom()), var precision = OSM.zoomPrecision(this.getZoom()),
params = {}; params = {};
if (marker && this.hasLayer(marker)) { if (marker && this.hasLayer(marker)) {

View File

@ -153,7 +153,7 @@ OSM = {
center = center.wrap(); center = center.wrap();
layers = layers.replace('M', ''); layers = layers.replace('M', '');
var precision = zoomPrecision(zoom), var precision = OSM.zoomPrecision(zoom),
hash = '#map=' + zoom + hash = '#map=' + zoom +
'/' + center.lat.toFixed(precision) + '/' + center.lat.toFixed(precision) +
'/' + center.lng.toFixed(precision); '/' + center.lng.toFixed(precision);
@ -163,5 +163,9 @@ OSM = {
} }
return hash; return hash;
},
zoomPrecision: function (zoom) {
return Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
} }
}; };

View File

@ -36,7 +36,7 @@ $(document).ready(function () {
map.on("click", function (e) { map.on("click", function (e) {
if ($('#updatehome').is(':checked')) { if ($('#updatehome').is(':checked')) {
var zoom = map.getZoom(), var zoom = map.getZoom(),
precision = zoomPrecision(zoom), precision = OSM.zoomPrecision(zoom),
location = e.latlng.wrap(); location = e.latlng.wrap();
$('#homerow').removeClass(); $('#homerow').removeClass();