for (anchor in links) {
node = document.getElementById(anchor);
if (! node) { continue; }
- node.href = links[anchor] + "?lat=" + lat + "&lon=" + lon + "&zoom=" + zoom;
+ var args = getArgs(node.href);
+ args["lat"] = lat;
+ args["lon"] = lon;
+ args["zoom"] = zoom;
+ node.href = setArgs(node.href, args);
}
node = document.getElementById("editanchor");
if (node) {
if ( zoom >= 14) {
- node.href = '/edit.html?lat=' + lat + '&lon=' + lon + "&zoom=" + zoom;
+ var args = getArgs(node.href);
+ args.lat = lat;
+ args.lon = lon;
+ args.zoom = zoom;
+ node.href = setArgs(node.href, args);
node.style.fontStyle = 'normal';
} else {
node.href = 'javascript:alert("zoom in to edit map");';
}
}
}
+
+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("&");
+}