/* This program is free software; you can redistribute it and/or modify it under the terms of the GNU AFFERO General Public License as published by the Free Software Foundation; either version 3 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or see http://www.gnu.org/licenses/agpl.txt. */ // OSRM routing alternatives // [everything about handling alternatives] OSRM.RoutingAlternatives = { // data of gui buttons for alternativess _buttons: [ {id:"gui-a", label:"A"}, {id:"gui-b", label:"B"} ], // initialize required values init: function() { OSRM.G.active_alternative = 0; OSRM.G.alternative_count = 0; }, // restructure response data prepare: function(response) { // move best route to alternative array var the_response = OSRM.G.response; the_response.alternative_geometries.unshift( response.route_geometry ); the_response.alternative_instructions.unshift( response.route_instructions ); the_response.alternative_summaries.unshift( response.route_summary ); // update basic information OSRM.G.alternative_count = response.alternative_geometries.length; if( OSRM.G.active_alternative >= OSRM.G.alternative_count ) // reset if the selected alternative cannot be found OSRM.G.active_alternative = 0; // switch data the_response.route_geometry = the_response.alternative_geometries[OSRM.G.active_alternative]; the_response.route_instructions = the_response.alternative_instructions[OSRM.G.active_alternative]; the_response.route_summary = the_response.alternative_summaries[OSRM.G.active_alternative]; }, // switch active alternative and redraw buttons accordingly setActive: function(button_id) { // switch active alternative OSRM.G.active_alternative = button_id; // redraw clickable buttons var buttons = OSRM.RoutingAlternatives._buttons; for(var i=0, size=OSRM.G.alternative_count; i'+buttons[i].label+'' + data; } // draw non-clickable buttons for(var i=OSRM.G.alternative_count, size=buttons.length; i'+buttons[i].label+'' + data; } // add buttons to DOM document.getElementById('information-box-header').innerHTML = data + document.getElementById('information-box-header').innerHTML; // add events for(var i=0, size=OSRM.G.alternative_count; i