]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/application.js
Add clearer close action, refactor base layer code
[rails.git] / app / assets / javascripts / application.js
index e91a9036fd6973ce3ccbb12563b4826bd640b5aa..f5022683b8050fec55c3c346664e835996c566a0 100644 (file)
@@ -114,6 +114,10 @@ function updatelinks(loc, zoom, layers, bounds, object) {
   }
 }
 
+function minZoomAlert() {
+    alert(I18n.t("javascripts.site." + name + "_zoom_alert")); return false;
+}
+
 function getShortUrl(map) {
   return (window.location.hostname.match(/^www\.openstreetmap\.org/i) ?
           'http://osm.org/go/' : '/go/') +
@@ -122,21 +126,19 @@ function getShortUrl(map) {
 
 function getUrl(map) {
   var center = map.getCenter(),
-      zoom = map.getZoom();
+      zoom = map.getZoom(),
+      toZoom = zoomPrecision(zoom);
 
   return (window.location.hostname.match(/^www\.openstreetmap\.org/i) ?
           'http://openstreetmap.org/?' : '/?') +
         querystring.stringify({
-            lat: center.lat,
-            lon: center.lng,
-            zoom: zoom
+            lat: toZoom(center.lat),
+            lon: toZoom(center.lng),
+            zoom: zoom,
+            layers: map.getLayersCode()
         });
 }
 
-function minZoomAlert() {
-    alert(I18n.t("javascripts.site." + name + "_zoom_alert")); return false;
-}
-
 // Called to create a short code for the short link.
 function makeShortCode(map) {
     var zoom = map.getZoom(),
@@ -175,6 +177,12 @@ function makeShortCode(map) {
     return str;
 }
 
+// generate a cookie-safe string of map state
+function cookieContent(map) {
+  var center = map.getCenter().wrap();
+  return [center.lng, center.lat, map.getZoom(), map.getLayersCode()].join('|');
+}
+
 /*
  * Forms which have been cached by rails may have the wrong
  * authenticity token, so patch up any forms with the correct