2 * Called as the user scrolls/zooms around to aniplate hrefs of the
3 * view tab and various other links
5 function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat) {
6 var decimals = Math.pow(10, Math.floor(zoom/3));
9 lat = Math.round(lat * decimals) / decimals;
10 lon = Math.round(lon * decimals) / decimals;
12 node = document.getElementById("permalinkanchor");
14 var args = getArgs(node.href);
19 args["layers"] = layers;
21 node.href = setArgs(node.href, args);
24 node = document.getElementById("viewanchor");
26 var args = getArgs(node.href);
31 args["layers"] = layers;
33 node.href = setArgs(node.href, args);
36 node = document.getElementById("exportanchor");
38 var args = getArgs(node.href);
43 args["layers"] = layers;
45 node.href = setArgs(node.href, args);
48 node = document.getElementById("editanchor");
51 var args = new Object();
55 node.href = setArgs("/edit", args);
56 node.style.fontStyle = 'normal';
58 node.href = 'javascript:alert("zoom in to edit map");';
59 node.style.fontStyle = 'italic';
63 node = document.getElementById("historyanchor");
66 var args = new Object();
67 //set bbox param from 'extents' object
68 if (typeof minlon == "number" &&
69 typeof minlat == "number" &&
70 typeof maxlon == "number" &&
71 typeof maxlat == "number") {
73 minlon = Math.round(minlon * decimals) / decimals;
74 minlat = Math.round(minlat * decimals) / decimals;
75 maxlon = Math.round(maxlon * decimals) / decimals;
76 maxlat = Math.round(maxlat * decimals) / decimals;
77 args.bbox = minlon + "," + minlat + "," + maxlon + "," + maxlat;
80 node.href = setArgs("/history", args);
81 node.style.fontStyle = 'normal';
83 node.href = 'javascript:alert("zoom in to see editing history");';
84 node.style.fontStyle = 'italic';
89 function getArgs(url) {
90 var args = new Object();
91 var querystart = url.indexOf("?");
93 if (querystart >= 0) {
94 var querystring = url.substring(querystart + 1);
95 var queryitems = querystring.split("&");
97 for (var i = 0; i < queryitems.length; i++) {
98 if (match = queryitems[i].match(/^(.*)=(.*)$/)) {
99 args[unescape(match[1])] = unescape(match[2]);
101 args[unescape(queryitems[i])] = null
110 * Called to set the arguments on a URL from the given hash.
112 function setArgs(url, args) {
113 var queryitems = new Array();
117 if (args[arg] == null) {
118 queryitems.push(escape(arg));
120 queryitems.push(escape(arg) + "=" + escape(args[arg]));
124 return url.replace(/\?.*$/, "") + "?" + queryitems.join("&");
128 * Called to get the arguments from a URL as a hash.
130 function getStyle(el, property) {
133 if (el.currentStyle) {
134 style = el.currentStyle[property];
135 } else if( window.getComputedStyle ) {
136 style = document.defaultView.getComputedStyle(el,null).getPropertyValue(property);
138 style = el.style[property];
145 * Called to interpolate JavaScript variables in strings using a
146 * similar syntax to rails I18n string interpolation - the only
147 * difference is that [[foo]] is the placeholder syntax instead
148 * of {{foo}} which allows the same string to be processed by both
149 * rails and then later by javascript.
151 function i18n(string, keys) {
152 for (var key in keys) {
153 var re_key = '\\[\\[' + key + '\\]\\]';
154 var re = new RegExp(re_key, "g");
156 string = string.replace(re, keys[key]);