X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/afc46bcd9bbfae631ad0bca1600cf44ac330c653..c919340c1193730c29710468f8d528967914bc61:/app/assets/javascripts/osm.js.erb diff --git a/app/assets/javascripts/osm.js.erb b/app/assets/javascripts/osm.js.erb index e414d26ff..eb5ce64f3 100644 --- a/app/assets/javascripts/osm.js.erb +++ b/app/assets/javascripts/osm.js.erb @@ -22,8 +22,8 @@ OSM = { return url; }, - mapParams: function (search) { - var params = {}, mapParams = {}, bounds, loc; + params: function(search) { + var params = {}; search = (search || window.location.search).replace('?', '').split(/&|;/); @@ -35,6 +35,12 @@ OSM = { params[key] = decodeURIComponent(val); } + return params; + }, + + mapParams: function (search) { + var params = OSM.params(search), mapParams = {}, bounds, loc; + if (params.mlon && params.mlat) { mapParams.marker = true; mapParams.mlon = parseFloat(params.mlon); @@ -81,6 +87,8 @@ OSM = { mapParams.zoom = hash.zoom; mapParams.object_zoom = false; } else if (bounds) { + mapParams.lon = bounds.getCenter().lng; // Not used by main map, but + mapParams.lat = bounds.getCenter().lat; // are used by iD/Potlatch. mapParams.bounds = bounds; mapParams.object_zoom = false; } else if (params.lon && params.lat) { @@ -139,26 +147,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;