]> git.openstreetmap.org Git - rails.git/commitdiff
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 f911783b58792da7639d5e73b01ee2721e6e19dc..cde7c1276a76ad334bac9bc4414b6e3ec88854fd 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 6118c8e0d741c7a3ef0614d24f3e91b922e69aab..98f24a6e7bd104f7668dc7c5feb2f1f2675047d3 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 dcea8e0c0b209ca1528c7765f8efa933bc0a4552..228a5a411ba8f38e62acbcddbae405dcbcf069fd 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 31a981ec9a15b34ff87d183e9b3f91b58b6ce676..52af96ebb7ad20d120ce60b9c84e234a17b104df 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 7336c49ec60121e25ee4a8e02ba837e6b82d2fc6..2121c21a7cff27dbcaf9176708af34b047cf9e94 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 bb1c9a35858f7b45523b25ccc10b1bae3d38d7d0..8b621e3aed4473302d4963473b7c9d75556e8d36 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;