]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/application.js
Even more map ui js refactor
[rails.git] / app / assets / javascripts / application.js
index 2ea37878784efde0dd05ac4645c9ebb35fa46c1c..a984a23f97fc7c5e2ede1f183e8d5337325294b3 100644 (file)
@@ -27,22 +27,30 @@ function zoomPrecision(zoom) {
     };
 }
 
+function normalBounds(bounds) {
+    if (bounds instanceof L.LatLngBounds) return bounds;
+    return new L.LatLngBounds(
+        new L.LatLng(bounds[0][0], bounds[0][1]),
+        new L.LatLng(bounds[1][0], bounds[1][1]));
+}
+
 /*
- * Called as the user scrolls/zooms around to aniplate hrefs of the
+ * Called as the user scrolls/zooms around to maniplate hrefs of the
  * view tab and various other links
  */
-function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat,object) {
+function updatelinks(loc, zoom, layers, bounds, object) {
   var toPrecision = zoomPrecision(zoom);
+  bounds = normalBounds(bounds);
   var node;
 
-  lat = toPrecision(lat);
-  lon = toPrecision(lon);
+  var lat = toPrecision(loc.lat),
+      lon = toPrecision(loc.lon || loc.lng);
 
-  if (minlon) {
-    minlon = toPrecision(minlon);
-    minlat = toPrecision(minlat);
-    maxlon = toPrecision(maxlon);
-    maxlat = toPrecision(maxlat);
+  if (bounds) {
+    var minlon = toPrecision(bounds.getWest()),
+        minlat = toPrecision(bounds.getSouth()),
+        maxlon = toPrecision(bounds.getEast()),
+        maxlat = toPrecision(bounds.getNorth());
   }
 
   $(".geolink").each(setGeolink);
@@ -52,11 +60,15 @@ function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat,object) {
     var args = getArgs(link.href);
 
     if ($(link).hasClass("llz")) {
-      args.lat = lat;
-      args.lon = lon;
-      args.zoom = zoom;
+      $.extend(args, {
+          lat: lat,
+          lon: lon,
+          zoom: zoom
+      });
     } else if (minlon && $(link).hasClass("bbox")) {
-      args.bbox = minlon + "," + minlat + "," + maxlon + "," + maxlat;
+      $.extend(args, {
+          bbox: minlon + "," + minlat + "," + maxlon + "," + maxlat
+      });
     }
 
     if (layers && $(link).hasClass("layers")) {
@@ -74,18 +86,19 @@ function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat,object) {
         $(link).off("click.minzoom");
 
         if (zoom >= minzoom) {
-          $(link).attr("title", I18n.t("javascripts.site." + name + "_tooltip"));
-          $(link).removeClass("disabled");
+          $(link).attr("title", I18n.t("javascripts.site." + name + "_tooltip"))
+              .removeClass("disabled");
         } else {
-          $(link).on("click.minzoom", function () { alert(I18n.t("javascripts.site." + name + "_zoom_alert")); return false; });
-          $(link).attr("title", I18n.t("javascripts.site." + name + "_disabled_tooltip"));
-          $(link).addClass("disabled");
+          $(link).on("click.minzoom", minZoomAlert)
+              .attr("title", I18n.t("javascripts.site." + name + "_disabled_tooltip"))
+              .addClass("disabled");
         }
     }
 
     link.href = setArgs(link.href, args);
   }
 
+
   function setShortlink() {
     var args = getArgs(this.href);
     var code = makeShortCode(lat, lon, zoom);
@@ -99,8 +112,7 @@ function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat,object) {
     // This is a hack to omit the default mapnik layer from the shortlink.
     if (layers && layers != "M") {
       args.layers = layers;
-    }
-    else {
+    } else {
       delete args.layers;
     }
 
@@ -116,6 +128,10 @@ function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat,object) {
   }
 }
 
+function minZoomAlert() {
+    alert(I18n.t("javascripts.site." + name + "_zoom_alert")); return false;
+}
+
 /*
  * Get the URL prefix to use for a short link
  */