X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/05eba790089d8e70d3061cb07f6d40720aee6010..1a5f14d338b1e809947232e0dc0a59040f265395:/app/assets/javascripts/osm.js.erb?ds=inline diff --git a/app/assets/javascripts/osm.js.erb b/app/assets/javascripts/osm.js.erb index f3c1c3607..5343b039c 100644 --- a/app/assets/javascripts/osm.js.erb +++ b/app/assets/javascripts/osm.js.erb @@ -1,13 +1,14 @@ OSM = { <% if defined?(PIWIK_LOCATION) and defined?(PIWIK_SITE) %> - PIWIK_LOCATION: <%= PIWIK_LOCATION.to_json %>, - PIWIK_SITE: <%= PIWIK_SITE.to_json %>, + PIWIK_LOCATION: <%= PIWIK_LOCATION.to_json %>, + PIWIK_SITE: <%= PIWIK_SITE.to_json %>, <% end %> - MAX_REQUEST_AREA: <%= MAX_REQUEST_AREA.to_json %>, - SERVER_URL: <%= SERVER_URL.to_json %>, - API_VERSION: <%= API_VERSION.to_json %>, - STATUS: <%= STATUS.to_json %>, + MAX_REQUEST_AREA: <%= MAX_REQUEST_AREA.to_json %>, + SERVER_URL: <%= SERVER_URL.to_json %>, + API_VERSION: <%= API_VERSION.to_json %>, + STATUS: <%= STATUS.to_json %>, + MAX_NOTE_REQUEST_AREA: <%= MAX_NOTE_REQUEST_AREA.to_json %>, apiUrl: function (object) { var url = "/api/" + OSM.API_VERSION + "/" + object.type + "/" + object.id; @@ -22,7 +23,7 @@ OSM = { }, mapParams: function (search) { - var params = {}, mapParams = {}, loc; + var params = {}, mapParams = {}, bounds, loc; search = (search || window.location.search).replace('?', '').split(/&|;/); @@ -56,21 +57,34 @@ OSM = { } } - // Decide on a lat lon to initialise the map with. Various ways of doing this if (params.bbox) { - var bbox = params.bbox.split(","); - mapParams.bbox = true; - mapParams.minlon = parseFloat(bbox[0]); - mapParams.minlat = parseFloat(bbox[1]); - mapParams.maxlon = parseFloat(bbox[2]); - mapParams.maxlat = parseFloat(bbox[3]); - mapParams.object_zoom = false; + params.bbox = params.bbox.split(','); + bounds = L.latLngBounds( + [parseFloat(params.bbox[1]), + parseFloat(params.bbox[0])], + [parseFloat(params.bbox[3]), + parseFloat(params.bbox[2])]); } else if (params.minlon && params.minlat && params.maxlon && params.maxlat) { - mapParams.bbox = true; - mapParams.minlon = parseFloat(params.minlon); - mapParams.minlat = parseFloat(params.minlat); - mapParams.maxlon = parseFloat(params.maxlon); - mapParams.maxlat = parseFloat(params.maxlat); + bounds = L.latLngBounds( + [parseFloat(params.minlat), + parseFloat(params.minlon)], + [parseFloat(params.maxlat), + parseFloat(params.maxlon)]); + } + + if (params.box === 'yes') { + mapParams.box = bounds; + } + + // Decide on a map starting position. Various ways of doing this. + var hash = L.Hash.parseHash(location.hash); + if (hash) { + mapParams.lon = hash.center.lng; + mapParams.lat = hash.center.lat; + mapParams.zoom = hash.zoom; + mapParams.object_zoom = false; + } else if (bounds) { + mapParams.bounds = bounds; mapParams.object_zoom = false; } else if (params.lon && params.lat) { mapParams.lon = parseFloat(params.lon); @@ -93,21 +107,21 @@ OSM = { mapParams.lat = OSM.home.lat; mapParams.zoom = 10; } else if (OSM.location) { - mapParams.bbox = true; - mapParams.minlon = OSM.location.minlon; - mapParams.minlat = OSM.location.minlat; - mapParams.maxlon = OSM.location.maxlon; - mapParams.maxlat = OSM.location.maxlat; + mapParams.bounds = L.latLngBounds( + [OSM.location.minlat, + OSM.location.minlon], + [OSM.location.maxlat, + OSM.location.maxlon]); } else { mapParams.lon = -0.1; mapParams.lat = 51.5; mapParams.zoom = parseInt(params.zoom || 5); } - if (mapParams.bbox) { - mapParams.box = params.box == "yes"; - mapParams.lon = (mapParams.minlon + mapParams.maxlon) / 2; - mapParams.lat = (mapParams.minlat + mapParams.maxlat) / 2; + mapParams.notes = params.notes == "yes"; + + if (params.note) { + mapParams.note = parseInt(params.note); } var scale = parseFloat(params.scale); @@ -116,5 +130,12 @@ OSM = { } return mapParams; + }, + + formatHash: function(args) { + var precision = zoomPrecision(args.zoom); + return '#' + args.zoom + + '/' + args.lat.toFixed(precision) + + '/' + args.lon.toFixed(precision); } };