Replace various Leaflet extensions with new builtin methods
authorTom Hughes <tom@compton.nu>
Thu, 27 Jun 2013 20:53:26 +0000 (21:53 +0100)
committerTom Hughes <tom@compton.nu>
Thu, 27 Jun 2013 20:53:26 +0000 (21:53 +0100)
app/assets/javascripts/browse.js
app/assets/javascripts/index.js
app/assets/javascripts/index/browse.js
app/assets/javascripts/index/export.js
app/assets/javascripts/index/notes.js.erb
app/assets/javascripts/map.js.erb

index f911783..cde7c12 100644 (file)
@@ -1,9 +1,9 @@
 $(document).ready(function () {
   function remoteEditHandler(bbox, select) {
-    var left = bbox.getWestLng() - 0.0001;
-    var top = bbox.getNorthLat() + 0.0001;
-    var right = bbox.getEastLng() + 0.0001;
-    var bottom = bbox.getSouthLat() - 0.0001;
+    var left = bbox.getWest() - 0.0001;
+    var top = bbox.getNorth() + 0.0001;
+    var right = bbox.getEast() + 0.0001;
+    var bottom = bbox.getSouth() - 0.0001;
     var loaded = false;
 
     $("#linkloader").load(function () { loaded = true; });
@@ -61,8 +61,8 @@ $(document).ready(function () {
     });
 
     updatelinks(params.lon, params.lat, 16, null, 
-                bbox.getWestLng(), bbox.getSouthLat(),
-                bbox.getEastLng(), bbox.getNorthLat(),
+                bbox.getWest(), bbox.getSouth(),
+                bbox.getEast(), bbox.getNorth(),
                 object);
   } else {
     $("#object_larger_map").hide();
@@ -94,10 +94,10 @@ $(document).ready(function () {
         updatelinks(centre.lng,
                     centre.lat,
                     16, null,
-                    extent.getWestLng(),
-                    extent.getSouthLat(),
-                    extent.getEastLng(),
-                    extent.getNorthLat(),
+                    extent.getWest(),
+                    extent.getSouth(),
+                    extent.getEast(),
+                    extent.getNorth(),
                     object);
       } else {
         $("#small_map").hide();
index 6118c8e..98f24a6 100644 (file)
@@ -79,10 +79,10 @@ $(document).ready(function () {
                 center.lat,
                 zoom,
                 layers,
-                extents.getWestLng(),
-                extents.getSouthLat(),
-                extents.getEastLng(),
-                extents.getNorthLat(),
+                extents.getWest(),
+                extents.getSouth(),
+                extents.getEast(),
+                extents.getNorth(),
                 params.object);
 
     var expiry = new Date();
@@ -95,10 +95,10 @@ $(document).ready(function () {
     var loaded = false;
 
     $("#linkloader").load(function () { loaded = true; });
-    $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.getWestLng()
-                                                                   + "&bottom=" + extent.getSouthLat()
-                                                                   + "&right=" + extent.getEastLng()
-                                                                   + "&top=" + extent.getNorthLat());
+    $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.getWest()
+                                                                   + "&bottom=" + extent.getSouth()
+                                                                   + "&right=" + extent.getEast()
+                                                                   + "&top=" + extent.getNorth());
 
     setTimeout(function () {
       if (!loaded) alert(I18n.t('site.index.remote_failed'));
@@ -121,10 +121,10 @@ $(document).ready(function () {
     $("#sidebar_title").html(I18n.t('site.sidebar.search_results'));
     $("#sidebar_content").load($(this).attr("action"), {
       query: $("#query").val(),
-      minlon: bounds.getWestLng(),
-      minlat: bounds.getSouthLat(),
-      maxlon: bounds.getEastLng(),
-      maxlat: bounds.getNorthLat()
+      minlon: bounds.getWest(),
+      minlat: bounds.getSouth(),
+      maxlon: bounds.getEast(),
+      maxlat: bounds.getNorth()
     }, openSidebar);
 
     return false;
index dcea8e0..228a5a4 100644 (file)
@@ -151,7 +151,7 @@ $(document).ready(function () {
 
     setStatus(I18n.t('browse.start_rjs.loading'));
 
-    var url = "/api/" + OSM.API_VERSION + "/map?bbox=" + bounds.toBBOX();
+    var url = "/api/" + OSM.API_VERSION + "/map?bbox=" + bounds.toBBoxString();
 
     /*
      * Modern browsers are quite happy showing far more than 100 features in
index 31a981e..52af96e 100644 (file)
@@ -67,7 +67,7 @@ $(document).ready(function () {
       var bounds = map.getBounds(),
         centerLat = bounds.getCenter().lat,
         halfWorldMeters = 6378137 * Math.PI * Math.cos(centerLat * Math.PI / 180),
-        meters = halfWorldMeters * (bounds.getNorthEast().lng - bounds.getSouthWest().lng) / 180,
+        meters = halfWorldMeters * (bounds.getEast() - bounds.getWest()) / 180,
         pixelsPerMeter = map.getSize().x / meters,
         metersPerPixel = 1 / (92 * 39.3701);
       return Math.round(1 / (pixelsPerMeter * metersPerPixel));
@@ -152,10 +152,10 @@ $(document).ready(function () {
     function setBounds(bounds) {
       var toPrecision = zoomPrecision(map.getZoom());
 
-      $("#minlon").val(toPrecision(bounds.getWestLng()));
-      $("#minlat").val(toPrecision(bounds.getSouthLat()));
-      $("#maxlon").val(toPrecision(bounds.getEastLng()));
-      $("#maxlat").val(toPrecision(bounds.getNorthLat()));
+      $("#minlon").val(toPrecision(bounds.getWest()));
+      $("#minlat").val(toPrecision(bounds.getSouth()));
+      $("#maxlon").val(toPrecision(bounds.getEast()));
+      $("#maxlat").val(toPrecision(bounds.getNorth()));
 
       mapnikSizeChanged();
       htmlUrlChanged();
@@ -188,7 +188,7 @@ $(document).ready(function () {
       var bounds = getBounds();
       var layerName = getMapBaseLayer().keyid;
 
-      var url = "http://" + OSM.SERVER_URL + "/export/embed.html?bbox=" + bounds.toBBOX() + "&amp;layer=" + layerName;
+      var url = "http://" + OSM.SERVER_URL + "/export/embed.html?bbox=" + bounds.toBBoxString() + "&amp;layer=" + layerName;
       var markerUrl = "";
 
       if ($("#marker_lat").val() && $("#marker_lon").val()) {
@@ -254,16 +254,16 @@ $(document).ready(function () {
     }
 
     function maxMapnikScale() {
-      var bounds = getMercatorBounds();
+      var size = getMercatorBounds().getSize();
 
-      return Math.floor(Math.sqrt(bounds.getWidth() * bounds.getHeight() / 0.3136));
+      return Math.floor(Math.sqrt(size.x * size.y / 0.3136));
     }
 
     function mapnikImageSize(scale) {
-      var bounds = getMercatorBounds();
+      var size = getMercatorBounds().getSize();
 
-      return {w: Math.round(bounds.getWidth() / scale / 0.00028),
-              h: Math.round(bounds.getHeight() / scale / 0.00028)};
+      return {w: Math.round(size.x / scale / 0.00028),
+              h: Math.round(size.y / scale / 0.00028)};
     }
 
     function roundScale(scale) {
index 7336c49..2121c21 100644 (file)
@@ -115,7 +115,7 @@ $(document).ready(function () {
     var size = bounds.getSize();
 
     if (size <= OSM.MAX_NOTE_REQUEST_AREA) {
-      var url = "/api/" + OSM.API_VERSION + "/notes.json?bbox=" + bounds.toBBOX();
+      var url = "/api/" + OSM.API_VERSION + "/notes.json?bbox=" + bounds.toBBoxString();
 
       if (noteLoader) noteLoader.abort();
 
index bb1c9a3..8b621e3 100644 (file)
@@ -1,31 +1,5 @@
 // Leaflet extensions
 L.extend(L.LatLngBounds.prototype, {
-  getSouthLat: function () {
-    return this._southWest.lat;
-  },
-
-  getWestLng: function () {
-    return this._southWest.lng;
-  },
-
-  getNorthLat: function () {
-    return this._northEast.lat;
-  },
-
-  getEastLng: function () {
-    return this._northEast.lng;
-  },
-
-  toBBOX: function () {
-    var decimal = 6;
-    var mult = Math.pow(10, decimal);
-    var xmin = Math.round(this.getWestLng() * mult) / mult;
-    var ymin = Math.round(this.getSouthLat() * mult) / mult;
-    var xmax = Math.round(this.getEastLng() * mult) / mult;
-    var ymax = Math.round(this.getNorthLat() * mult) / mult;
-    return xmin + "," + ymin + "," + xmax + "," + ymax;
-  },
-
   getSize: function () {
     return (this._northEast.lat - this._southWest.lat) *
            (this._northEast.lng - this._southWest.lng);
@@ -36,16 +10,6 @@ L.extend(L.LatLngBounds.prototype, {
   }
 });
 
-L.extend(L.Bounds.prototype, {
-  getWidth: function () {
-   return this.max.x - this.min.x;
-  },
-
-  getHeight: function () {
-   return this.max.y - this.min.y;
-  }
-});
-
 L.Icon.Default.imagePath = <%= "#{asset_prefix}/images".to_json %>;
 
 var map;