]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/application.js
Use custom zoom control everywhere
[rails.git] / app / assets / javascripts / application.js
index a7548e7f9cbff9a7175a431bd0912ae0394aef2e..0ee6dc8806a7c94607619259352e92970668b58f 100644 (file)
@@ -5,6 +5,7 @@
 //= require augment
 //= require leaflet
 //= require leaflet.osm
+//= require leaflet.zoom
 //= require leaflet.extend
 //= require leaflet.locationfilter
 //= require i18n/translations
@@ -114,14 +115,29 @@ 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/') +
           makeShortCode(map);
 }
 
-function minZoomAlert() {
-    alert(I18n.t("javascripts.site." + name + "_zoom_alert")); return false;
+function getUrl(map) {
+  var center = map.getCenter(),
+      zoom = map.getZoom(),
+      toZoom = zoomPrecision(zoom);
+
+  return (window.location.hostname.match(/^www\.openstreetmap\.org/i) ?
+          'http://openstreetmap.org/?' : '/?') +
+        querystring.stringify({
+            lat: toZoom(center.lat),
+            lon: toZoom(center.lng),
+            zoom: zoom,
+            layers: map.getLayersCode()
+        });
 }
 
 // Called to create a short code for the short link.
@@ -162,6 +178,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