From: Tom Hughes Date: Thu, 27 Jun 2013 20:53:26 +0000 (+0100) Subject: Replace various Leaflet extensions with new builtin methods X-Git-Tag: live~4907 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/168a9fc3272777fa7ab533e936715525376f8ebf?ds=sidebyside Replace various Leaflet extensions with new builtin methods --- diff --git a/app/assets/javascripts/browse.js b/app/assets/javascripts/browse.js index f911783b5..cde7c1276 100644 --- a/app/assets/javascripts/browse.js +++ b/app/assets/javascripts/browse.js @@ -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(); diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index 6118c8e0d..98f24a6e7 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -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; diff --git a/app/assets/javascripts/index/browse.js b/app/assets/javascripts/index/browse.js index dcea8e0c0..228a5a411 100644 --- a/app/assets/javascripts/index/browse.js +++ b/app/assets/javascripts/index/browse.js @@ -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 diff --git a/app/assets/javascripts/index/export.js b/app/assets/javascripts/index/export.js index 31a981ec9..52af96ebb 100644 --- a/app/assets/javascripts/index/export.js +++ b/app/assets/javascripts/index/export.js @@ -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() + "&layer=" + layerName; + var url = "http://" + OSM.SERVER_URL + "/export/embed.html?bbox=" + bounds.toBBoxString() + "&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) { diff --git a/app/assets/javascripts/index/notes.js.erb b/app/assets/javascripts/index/notes.js.erb index 7336c49ec..2121c21a7 100644 --- a/app/assets/javascripts/index/notes.js.erb +++ b/app/assets/javascripts/index/notes.js.erb @@ -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(); diff --git a/app/assets/javascripts/map.js.erb b/app/assets/javascripts/map.js.erb index bb1c9a358..8b621e3ae 100644 --- a/app/assets/javascripts/map.js.erb +++ b/app/assets/javascripts/map.js.erb @@ -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;