decimal places for the zoom level whilst still preserving accuracy sufficient to position the map within a few pixels. The relationship between zoom level, decimal places, and the accuracy with which the map can then be positioned in pixels is as follows: Zoom Decimals Accuracy (pixels) 1 0 1.42 2 0 2.84 3 1 0.57 4 1 1.14 5 1 2.28 6 2 0.46 7 2 0.91 8 2 1.82 9 3 0.36 10 3 0.73 11 3 1.46 12 4 0.29 13 4 0.58 14 4 1.17 15 5 0.23 16 5 0.47 17 5 0.93 18 6 0.19 So the worse case is at zoom 2 where accuracy is still within 3 pixels. Based on a patch by rjmunro.
91 lines
2.2 KiB
JavaScript
91 lines
2.2 KiB
JavaScript
function updatelinks(lon,lat,zoom,layers) {
|
|
var decimals = Math.pow(10, Math.floor(zoom/3));
|
|
var node;
|
|
|
|
lat = Math.round(lat * decimals) / decimals;
|
|
lon = Math.round(lon * decimals) / decimals;
|
|
|
|
node = document.getElementById("permalinkanchor");
|
|
if (node) {
|
|
var args = getArgs(node.href);
|
|
args["lat"] = lat;
|
|
args["lon"] = lon;
|
|
args["zoom"] = zoom;
|
|
args["layers"] = layers;
|
|
node.href = setArgs(node.href, args);
|
|
}
|
|
|
|
node = document.getElementById("viewanchor");
|
|
if (node) {
|
|
var args = getArgs(node.href);
|
|
args["lat"] = lat;
|
|
args["lon"] = lon;
|
|
args["zoom"] = zoom;
|
|
args["layers"] = layers;
|
|
node.href = setArgs(node.href, args);
|
|
}
|
|
|
|
node = document.getElementById("editanchor");
|
|
if (node) {
|
|
if (zoom >= 11) {
|
|
var args = new Object();
|
|
args.lat = lat;
|
|
args.lon = lon;
|
|
args.zoom = zoom;
|
|
node.href = setArgs("/edit.html", args);
|
|
node.style.fontStyle = 'normal';
|
|
} else {
|
|
node.href = 'javascript:alert("zoom in to edit map");';
|
|
node.style.fontStyle = 'italic';
|
|
}
|
|
}
|
|
}
|
|
|
|
function getArgs(url) {
|
|
var args = new Object();
|
|
var querystart = url.indexOf("?");
|
|
|
|
if (querystart >= 0) {
|
|
var querystring = url.substring(querystart + 1);
|
|
var queryitems = querystring.split("&");
|
|
|
|
for (var i = 0; i < queryitems.length; i++) {
|
|
if (match = queryitems[i].match(/^(.*)=(.*)$/)) {
|
|
args[unescape(match[1])] = unescape(match[2]);
|
|
} else {
|
|
args[unescape(queryitems[i])] = null
|
|
}
|
|
}
|
|
}
|
|
|
|
return args;
|
|
}
|
|
|
|
function setArgs(url, args) {
|
|
var queryitems = new Array();
|
|
|
|
for (arg in args)
|
|
{
|
|
if (args[arg] == null) {
|
|
queryitems.push(escape(arg));
|
|
} else {
|
|
queryitems.push(escape(arg) + "=" + escape(args[arg]));
|
|
}
|
|
}
|
|
|
|
return url.replace(/\?.*$/, "") + "?" + queryitems.join("&");
|
|
}
|
|
|
|
function getStyle(el, property) {
|
|
var style;
|
|
|
|
if (el.currentStyle) {
|
|
style = el.currentStyle[property];
|
|
} else if( window.getComputedStyle ) {
|
|
style = document.defaultView.getComputedStyle(el,null).getPropertyValue(property);
|
|
} else {
|
|
style = el.style[property];
|
|
}
|
|
|
|
return style;
|
|
}
|