X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/6618cb9019687c8c2edf74698f84b385c0d9edd6..aaeca5b5346b01d7ef26a301492804d36049eff8:/app/assets/javascripts/osm.js.erb?ds=sidebyside diff --git a/app/assets/javascripts/osm.js.erb b/app/assets/javascripts/osm.js.erb index 409cda8d8..5c555a25a 100644 --- a/app/assets/javascripts/osm.js.erb +++ b/app/assets/javascripts/osm.js.erb @@ -1,7 +1,6 @@ OSM = { -<% if defined?(PIWIK_LOCATION) and defined?(PIWIK_SITE) %> - PIWIK_LOCATION: <%= PIWIK_LOCATION.to_json %>, - PIWIK_SITE: <%= PIWIK_SITE.to_json %>, +<% if defined?(PIWIK) %> + PIWIK: <%= PIWIK.to_json %>, <% end %> MAX_REQUEST_AREA: <%= MAX_REQUEST_AREA.to_json %>, @@ -22,8 +21,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 +34,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 +80,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 +146,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;