From: Richard Fairhurst Date: Wed, 22 Jan 2014 09:52:01 +0000 (+0000) Subject: Move routing engines into their own files X-Git-Tag: live~4842^2~58 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/3bd5ae239950a842e565ba747466da903e605bda Move routing engines into their own files --- diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index a3531eb30..9ddac98a3 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -15,6 +15,7 @@ //= require index/new_note //= require router //= require routing +//= require_tree ./routing_engines (function() { var loaderTimeout; @@ -348,6 +349,8 @@ $(document).ready(function () { }); OSM.routing = OSM.Routing(map,'OSM.routing',$('.query_wrapper.routing')); + OSM.routing.addEngines(OSM.RoutingEngines.list); + OSM.routing.chooseEngine('Car (OSRM)'); $(".get_directions").on("click",function(e) { e.preventDefault(); diff --git a/app/assets/javascripts/routing.js.erb b/app/assets/javascripts/routing.js.erb index 4eb91fc7a..afa15ba4f 100644 --- a/app/assets/javascripts/routing.js.erb +++ b/app/assets/javascripts/routing.js.erb @@ -7,10 +7,13 @@ https://github.com/apmon/openstreetmap-website/blob/9755c3ae0a8d0684d43760f91dc864ff42d8477a/app/views/routing/start.js.erb *** draggable start/end markers - *** click each part *** translation (including all alerts and presentation) *** export GPX *** URL history (or do we consciously not want to support that?) + + *** add MapQuest engine + *** add YOURS engine + *** finish CloudMade engine */ var TURN_INSTRUCTIONS=["", @@ -39,6 +42,11 @@ var ROUTING_POLYLINE={ }; +OSM.RoutingEngines={ + list: [] + // common functions and constants, e.g. OSRM parser, can go here +}; + OSM.Routing=function(map,name,jqSearch) { var r={}; r.map=map; // Leaflet map @@ -77,9 +85,6 @@ OSM.Routing=function(map,name,jqSearch) { // Route-fetching UI - r.selectEngine=function(e) { - r.chosenEngine=r.engines[e.target.selectedIndex]; - }; r.requestRoute=function() { if (r.route_from && r.route_to) { r.chosenEngine.getRoute(true,[r.route_from,r.route_to]); @@ -147,90 +152,39 @@ OSM.Routing=function(map,name,jqSearch) { if (r.polyline) map.removeLayer(r.polyline); }; - // Add engines - - r.engines=[]; - r.addEngine=function(engine) { - // Save engine - var i=r.engines.length; - engine.subscript=i; - r['engine'+i]=engine; - r.engines.push(engine); - - // Add generic JSONP function - engine.requestJSONP=function(url) { - var script = document.createElement('script'); - script.src = url+r.name+".engine"+this.subscript+".gotRoute"; - // OSRM doesn't like non-alphanumeric, otherwise we could just do OSM.routing.engines["+engine.subscript+"].gotRoute - document.body.appendChild(script); - }; - - // Populate dropdown - var select=jqSearch.find('select.routing_engines'); - select.append(""); + // Routing engine handling + + // Add all engines + r.addEngines=function(list) { + list.sort(function(a,b) { return a.name>b.name; }); + r.engines=list; + var select=r.jqSearch.find('select.routing_engines'); + for (var i=0; i"+engine.name+""); + } + r.chosenEngine=r.engines[0]; }; - - // OSRM car engine - // *** this should all be shared from an OSRM library somewhere - // *** need to clear hints at some point - - r.addEngine({ - name: 'Car (OSRM)', - draggable: true, - _hints: {}, - getRoute: function(final,points) { - var url="http://router.project-osrm.org/viaroute?z=14&output=json"; - for (var i=0; i