From: Richard Fairhurst Date: Wed, 22 Jan 2014 18:20:07 +0000 (+0000) Subject: Move more engine-specific stuff out of main .js X-Git-Tag: live~4233^2~55 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/d14406cead2782c382de89428a2dcc5bb3e85ae8 Move more engine-specific stuff out of main .js --- diff --git a/app/assets/javascripts/routing.js.erb b/app/assets/javascripts/routing.js.erb index e9954bbcb..27818b66b 100644 --- a/app/assets/javascripts/routing.js.erb +++ b/app/assets/javascripts/routing.js.erb @@ -99,10 +99,11 @@ OSM.Routing=function(map,name,jqSearch) { r.map.fitBounds(r.polyline.getBounds()); }; - // Take an array of directions and write it out - // (we use OSRM's route_instructions format) + // Take directions and write them out + // data = { steps: array of [latlng, sprite number, instruction text, distance in metres] } + // sprite numbers equate to OSRM's route_instructions turn values // *** translations? - r.setItinerary=function(steps) { + r.setItinerary=function(data) { // Create base table $("#content").removeClass("overlay-sidebar"); $('#sidebar_content').empty(); @@ -111,16 +112,10 @@ OSM.Routing=function(map,name,jqSearch) { $('#sidebar_content').html(html); // Add each row var cumulative=0; - for (var i=0; i "; - instText+=TURN_INSTRUCTIONS[instCodes[0]]; - if (instCodes[1]) { instText+="exit "+instCodes[1]+" "; } - if (instCodes[0]!=15) { instText+=step[1] ? ""+step[1]+"" : "(unnamed)"; } + for (var i=0; i"); - row.append(" "); - row.append(""+instText); + row.append(" "); + row.append(""+step[2]); row.append(""+dist); - with ({num: i, dist: step[3]}) { - row.on('click',function(e) { - r.clickTurn(num, r.polyline.getLatLngs()[dist]); - }); + with ({ num: i, ll: step[0] }) { + row.on('click',function(e) { r.clickTurn(num, ll); }); }; $('#turnbyturn').append(row); - cumulative+=step[2]; + cumulative+=step[3]; } }; r.clickTurn=function(num,latlng) { diff --git a/app/assets/javascripts/routing_engines/osrm_car.js b/app/assets/javascripts/routing_engines/osrm_car.js index f0c05a850..0fdb42889 100644 --- a/app/assets/javascripts/routing_engines/osrm_car.js +++ b/app/assets/javascripts/routing_engines/osrm_car.js @@ -21,10 +21,22 @@ OSM.RoutingEngines.list.push({ alert("Couldn't find route between those two places"); return false; } - // *** store hints + // Draw polyline var line=L.PolylineUtil.decode(data.route_geometry); for (i=0; i "; + instText+=TURN_INSTRUCTIONS[instCodes[0]]; + if (instCodes[1]) { instText+="exit "+instCodes[1]+" "; } + if (instCodes[0]!=15) { instText+=s[1] ? ""+s[1]+"" : "(unnamed)"; } + steps.push([line[s[3]], s[0].split('-')[0], instText, s[2]]); + } + router.setItinerary({ steps: steps }); } });