X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/f9d714dfd36fa56ced4c0a99a6e59c945ff89cca..2fa422578448314fb6fad888b5c47cf994cb0b8c:/app/assets/javascripts/osm.js.erb diff --git a/app/assets/javascripts/osm.js.erb b/app/assets/javascripts/osm.js.erb index 409cda8d8..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); @@ -75,12 +81,14 @@ OSM = { var hash = OSM.parseHash(location.hash); // Decide on a map starting position. Various ways of doing this. - if (hash.lat && hash.lon) { + if (hash.center) { mapParams.lon = hash.center.lng; mapParams.lat = hash.center.lat; 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;