From 7ee58d77b7cef4be7642fe21f07ee978d68f0260 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 6 Aug 2013 09:10:56 -0700 Subject: [PATCH] Wrap permalink coordinates --- app/assets/javascripts/osm.js.erb | 32 ++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/osm.js.erb b/app/assets/javascripts/osm.js.erb index e414d26ff..4430943d1 100644 --- a/app/assets/javascripts/osm.js.erb +++ b/app/assets/javascripts/osm.js.erb @@ -139,26 +139,28 @@ OSM = { }, formatHash: function(args) { + var center, zoom, layers; + if (args instanceof L.Map) { - args = { - lat: args.getCenter().lat, - lon: args.getCenter().lng, - zoom: args.getZoom(), - layers: args.getLayersCode() - }; + center = args.getCenter(); + zoom = args.getZoom(); + layers = args.getLayersCode(); + } else { + center = L.latLng(args.lat, args.lon); + zoom = args.zoom; + layers = args.layers || ''; } - var precision = zoomPrecision(args.zoom), - hash = '#map=' + args.zoom + - '/' + args.lat.toFixed(precision) + - '/' + args.lon.toFixed(precision); + center = center.wrap(); + layers = layers.replace('M', ''); - if (args.layers) { - args.layers = args.layers.replace('M', ''); - } + var precision = zoomPrecision(zoom), + hash = '#map=' + zoom + + '/' + center.lat.toFixed(precision) + + '/' + center.lng.toFixed(precision); - if (args.layers) { - hash += '&layers=' + args.layers; + if (layers) { + hash += '&layers=' + layers; } return hash; -- 2.39.5