X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/3eaf58c151ca9c790dcf6d0937dc186c5c790422..902f1b088743b1983ef5bbb2ac7a3c8f2fadbdf1:/app/assets/javascripts/routing.js.erb diff --git a/app/assets/javascripts/routing.js.erb b/app/assets/javascripts/routing.js.erb index 3c6db9999..af9ce4fbf 100644 --- a/app/assets/javascripts/routing.js.erb +++ b/app/assets/javascripts/routing.js.erb @@ -9,8 +9,6 @@ *** translation (including all alerts and presentation) *** export GPX *** URL history (or do we consciously not want to support that?) - *** spinner when waiting for result (beneath 'Go' button?) - *** add YOURS engine */ @@ -109,7 +107,7 @@ OSM.Routing=function(map,name,jqSearch) { r.updateMarker(field.id); if (r.awaitingGeocode) { r.awaitingGeocode=false; - r.requestRoute(true); + r.requestRoute(true, true); } }; @@ -121,7 +119,7 @@ OSM.Routing=function(map,name,jqSearch) { // *** ^^^ this is slightly off - we need to work out the latLng of the tip r.createMarker(ll,id); r.setNumericInput(ll,id); - r.requestRoute(true); + r.requestRoute(true, false); // update to/from field }; r.createMarker=function(latlng,id) { @@ -148,7 +146,7 @@ OSM.Routing=function(map,name,jqSearch) { if (e.type=='drag' && !r.chosenEngine.draggable) return; if (e.type=='drag' && r.awaitingRoute) return; r.setNumericInput(e.target.getLatLng(), e.target.options.name); - r.requestRoute(e.type=='dragend'); + r.requestRoute(e.type=='dragend', false); }; // Set a route input field to a numeric value r.setNumericInput=function(ll,id) { @@ -159,10 +157,14 @@ OSM.Routing=function(map,name,jqSearch) { // Route-fetching UI - r.requestRoute=function(isFinal) { + r.requestRoute=function(isFinal, updateZoom) { if (r.route_from && r.route_to) { + $(".query_wrapper.routing .spinner").show(); r.awaitingRoute=true; r.chosenEngine.getRoute(isFinal,[r.route_from,r.route_to]); + if(updateZoom){ + r.map.fitBounds(L.latLngBounds([r.route_from, r.route_to]).pad(0.05)); + } // then, when the route has been fetched, it'll call the engine's gotRoute function } else if (r.route_from==false || r.route_to==false) { // we're waiting for a Nominatim response before we can request a route @@ -181,13 +183,13 @@ OSM.Routing=function(map,name,jqSearch) { // 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(data) { // Create base table $("#content").removeClass("overlay-sidebar"); $('#sidebar_content').empty(); - var html='

' + I18n.t('javascripts.directions.directions') + '

'.replace(/~/g,"'"); - html+=""; + var html=('

' + + '' + I18n.t('javascripts.directions.directions') + + '

').replace(/~/g,"'"); $('#sidebar_content').html(html); // Add each row var cumulative=0; @@ -211,6 +213,8 @@ OSM.Routing=function(map,name,jqSearch) { $('#turnbyturn').append(row); cumulative+=step[3]; } + $('#sidebar_content').append('

' + r.chosenEngine.creditline + '

'); + }; r.clickTurn=function(num,latlng) { r.popup=L.popup().setLatLng(latlng).setContent("

"+(num+1)+"

").openOn(r.map); @@ -242,7 +246,10 @@ OSM.Routing=function(map,name,jqSearch) { script.src = url+r.name+".gotRoute"+num; document.body.appendChild(script); }; - r['gotRoute'+num]=function(data) { r.awaitingRoute=false; list[num].gotRoute(r,data); }; + r['gotRoute'+num]=function(data) { + r.awaitingRoute=false; list[num].gotRoute(r,data); + $(".query_wrapper.routing .spinner").hide(); + }; } select.append(""); } @@ -252,6 +259,9 @@ OSM.Routing=function(map,name,jqSearch) { // Choose an engine on dropdown change r.selectEngine=function(e) { r.chosenEngine=r.engines[e.target.selectedIndex]; + if (r.polyline){ // and if a route is currently showing, must also refresh, else confusion + r.requestRoute(true, false); + } }; // Choose an engine by name r.chooseEngine=function(name) {