/* 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 description // [renders routing description and manages events] OSRM.RoutingDescription = { // route description events onClickRouteDescription: function(geometry_index) { var positions = OSRM.G.route.getPositions(); OSRM.G.markers.highlight.setPosition( positions[geometry_index] ); OSRM.G.markers.highlight.show(); OSRM.G.markers.highlight.centerView(OSRM.DEFAULTS.HIGHLIGHT_ZOOM_LEVEL); }, onClickCreateShortcut: function(src){ src += '&z='+ OSRM.G.map.getZoom() + '¢er=' + OSRM.G.map.getCenter().lat.toFixed(6) + ',' + OSRM.G.map.getCenter().lng.toFixed(6); OSRM.JSONP.call(OSRM.DEFAULTS.HOST_SHORTENER_URL+src, OSRM.RoutingDescription.showRouteLink, OSRM.RoutingDescription.showRouteLink_TimeOut, OSRM.DEFAULTS.JSONP_TIMEOUT, 'shortener'); document.getElementById('route-link').innerHTML = '['+OSRM.loc("GENERATE_LINK_TO_ROUTE")+']'; }, showRouteLink: function(response){ document.getElementById('route-link').innerHTML = '['+response.ShortURL+']'; }, showRouteLink_TimeOut: function(){ document.getElementById('route-link').innerHTML = '['+OSRM.loc("LINK_TO_ROUTE_TIMEOUT")+']'; }, // handling of routing description show: function(response) { // compute query string var query_string = '?rebuild=1'; for(var i=0; i'+OSRM.loc("GET_LINK_TO_ROUTE")+']'; // create GPX link var gpx_link = '['+OSRM.loc("GPX_FILE")+']'; // create route description var route_desc = ""; route_desc += ''; for(var i=0; i < response.route_instructions.length; i++){ //odd or even ? var rowstyle='results-odd'; if(i%2==0) { rowstyle='results-even'; } route_desc += ''; route_desc += '"; route_desc += '"; route_desc += '"; route_desc += ""; } route_desc += '
'; route_desc += ''; route_desc += "'; route_desc += '
'; // build route description if( i == 0 ) route_desc += OSRM.loc(OSRM.RoutingDescription.getDrivingInstruction(response.route_instructions[i][0])).replace(/\[(.*)\]/,"$1").replace(/%s/, OSRM.loc(response.route_instructions[i][6]) ); else if( response.route_instructions[i][1] != "" ) route_desc += OSRM.loc(OSRM.RoutingDescription.getDrivingInstruction(response.route_instructions[i][0])).replace(/\[(.*)\]/,"$1").replace(/%s/, response.route_instructions[i][1]); else route_desc += OSRM.loc(OSRM.RoutingDescription.getDrivingInstruction(response.route_instructions[i][0])).replace(/\[(.*)\]/,""); route_desc += '
'; route_desc += "
'; if( i != response.route_instructions.length-1 ) route_desc += ''+OSRM.Utils.metersToDistance(response.route_instructions[i][2])+''; route_desc += "
'; // create header header = '
' + OSRM.loc("ROUTE_DESCRIPTION") + '
' + '
' + '
' + '
' + OSRM.loc("DISTANCE")+": " + OSRM.Utils.metersToDistance(response.route_summary.total_distance) + '
' + '
' + OSRM.loc("DURATION")+": " + OSRM.Utils.secondsToTime(response.route_summary.total_time) + '
' + '
' + '
' + '' + '
' + gpx_link + '
' + '
' + '
'; // update DOM document.getElementById('information-box-header').innerHTML = header; document.getElementById('information-box').innerHTML = route_desc; }, // simple description showSimple: function(response) { header = '
' + OSRM.loc("ROUTE_DESCRIPTION") + '
' + '
' + '
' + '
' + OSRM.loc("DISTANCE")+": " + OSRM.Utils.metersToDistance(response.route_summary.total_distance) + '
' + '
' + OSRM.loc("DURATION")+": " + OSRM.Utils.secondsToTime(response.route_summary.total_time) + '
' + '
' + '
' + '
' + '
'; // update DOM document.getElementById('information-box-header').innerHTML = header; document.getElementById('information-box').innerHTML = "
"+OSRM.loc("YOUR_ROUTE_IS_BEING_COMPUTED")+"
"; }, // no description showNA: function( display_text ) { header = '
' + OSRM.loc("ROUTE_DESCRIPTION") + '
' + '
' + '
' + '
' + OSRM.loc("DISTANCE")+": N/A" + '
' + '
' + OSRM.loc("DURATION")+": N/A" + '
' + '
' + '
' + '
' + '
'; // update DOM document.getElementById('information-box-header').innerHTML = header; document.getElementById('information-box').innerHTML = "
"+display_text+"
"; }, // retrieve driving instruction icon from instruction id getDrivingInstructionIcon: function(server_instruction_id) { var local_icon_id = "direction_"; server_instruction_id = server_instruction_id.replace(/^11-\d{1,}$/,"11"); // dumb check, if there is a roundabout (all have the same icon) local_icon_id += server_instruction_id; if( OSRM.G.images[local_icon_id] ) return OSRM.G.images[local_icon_id].src; else return OSRM.G.images["direction_0"].src; }, // retrieve driving instructions from instruction ids getDrivingInstruction: function(server_instruction_id) { var local_instruction_id = "DIRECTION_"; server_instruction_id = server_instruction_id.replace(/^11-\d{2,}$/,"11-x"); // dumb check, if there are 10+ exits on a roundabout (say the same for exit 10+) local_instruction_id += server_instruction_id; var description = OSRM.loc( local_instruction_id ); if( description == local_instruction_id) return OSRM.loc("DIRECTION_0"); return description; } };