From: John Firebaugh Date: Fri, 5 Oct 2012 02:15:24 +0000 (-0700) Subject: Extract OSM.apiUrl X-Git-Tag: live~5896 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/e4ef507c5c56ab1f700a04c099f6938a143f836f Extract OSM.apiUrl --- diff --git a/app/assets/javascripts/browse.js b/app/assets/javascripts/browse.js index 7df6d67d6..e98aa2ed6 100644 --- a/app/assets/javascripts/browse.js +++ b/app/assets/javascripts/browse.js @@ -42,19 +42,16 @@ $(document).ready(function () { updatelinks(centre.lon, centre.lat, 16, null, params.minlon, params.minlat, params.maxlon, params.maxlat); } else { - var url = "/api/" + OSM.API_VERSION + "/" + params.type + "/" + params.id; - - if (params.type != "node") { - url += "/full"; - } else if (!params.visible) { - var previous_version = params.version - 1; - url += "/" + previous_version; - } - $("#object_larger_map").hide(); $("#object_edit").hide(); - addObjectToMap(url, true, function(extent) { + var object = {type: params.type, id: params.id}; + + if (!params.visible) { + object.version = params.version - 1; + } + + addObjectToMap(object, true, function(extent) { $("#loading").hide(); $("#browse_map .geolink").show(); diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index 2216a0352..75b3fa1a8 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -33,13 +33,7 @@ $(document).ready(function () { } if (params.object) { - var url = "/api/" + OSM.API_VERSION + "/" + params.object_type + "/" + params.object_id; - - if (params.object_type != "node") { - url += "/full"; - } - - addObjectToMap(url, params.object_zoom); + addObjectToMap({type: params.object_type, id: params.object_id}, params.object_zoom); } handleResize(); diff --git a/app/assets/javascripts/map.js.erb b/app/assets/javascripts/map.js.erb index fc2f955a8..fd5962d4f 100644 --- a/app/assets/javascripts/map.js.erb +++ b/app/assets/javascripts/map.js.erb @@ -106,13 +106,13 @@ function addMarkerToMap(position, icon, description) { return marker; } -function addObjectToMap(url, zoom, callback) { +function addObjectToMap(object, zoom, callback) { var layer = new OpenLayers.Layer.Vector("Objects", { strategies: [ new OpenLayers.Strategy.Fixed() ], protocol: new OpenLayers.Protocol.HTTP({ - url: url, + url: OSM.apiUrl(object), format: new OpenLayers.Format.OSM() }), style: { diff --git a/app/assets/javascripts/osm.js.erb b/app/assets/javascripts/osm.js.erb index 3c3378f98..22a1023b4 100644 --- a/app/assets/javascripts/osm.js.erb +++ b/app/assets/javascripts/osm.js.erb @@ -8,6 +8,18 @@ OSM = { SERVER_URL: <%= SERVER_URL.to_json %>, API_VERSION: <%= API_VERSION.to_json %>, + apiUrl: function (object) { + var url = "/api/" + OSM.API_VERSION + "/" + object.type + "/" + object.id; + + if (object.type != "node") { + url += "/full"; + } else if (object.version) { + url += "/" + object.version; + } + + return url; + }, + mapParams: function (search) { var params = {}, mapParams = {}, loc;