/*
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 printing
// [printing support]
OSRM.Printing = {
// directory with printing code, and base OSRM directory relative to this directory
DIRECTORY: 'printing/',
BASE_DIRECTORY: '../',
// create UI for printing in mainwindow
init: function() {
var icon = document.createElement('div');
icon.id = "gui-printer-inactive";
icon.className = "iconic-button top-right-button";
var spacer = document.createElement('div');
spacer.className = "quad top-right-button";
var input_mask_header = document.getElementById('input-mask-header');
input_mask_header.appendChild(spacer,input_mask_header.lastChild);
input_mask_header.appendChild(icon,input_mask_header.lastChild);
document.getElementById("gui-printer-inactive").onclick = OSRM.Printing.openPrintWindow;
OSRM.Browser.onUnloadHandler( OSRM.Printing.uninit );
},
uninit: function() {
if(OSRM.G.printwindow)
OSRM.G.printwindow.close();
},
// switch printer button on/off
activate: function() { // use showing route description as trigger
if( document.getElementById("gui-printer-inactive") )
document.getElementById("gui-printer-inactive").id = "gui-printer";
},
deactivate: function() { // use hide route as trigger
if( document.getElementById("gui-printer") )
document.getElementById("gui-printer").id = "gui-printer-inactive";
},
// create UI in printwindow
show: function(response) {
// create header
var header;
if( OSRM.Browser.IE6_8 ) { // tables used for compatibility with legacy IE (quirks mode)
header =
'';
} else {
header =
'';
}
// create route description
var body = '
';
for(var i=0; i < response.route_instructions.length; i++){
//odd or even ?
var rowstyle='description-body-odd';
if(i%2==0) { rowstyle='description-body-even'; }
body += '';
body += '';
body += ' ';
body += " | ";
// build route description
body += '';
if( response.route_instructions[i][1] != "" )
body += OSRM.loc(OSRM.RoutingDescription._getDrivingInstruction(response.route_instructions[i][0])).replace(/\[(.*)\]/,"$1").replace(/%s/, response.route_instructions[i][1]).replace(/%d/, OSRM.loc(response.route_instructions[i][6]));
else
body += OSRM.loc(OSRM.RoutingDescription._getDrivingInstruction(response.route_instructions[i][0])).replace(/\[(.*)\]/,"").replace(/%d/, OSRM.loc(response.route_instructions[i][6]));
body += " | ";
body += '';
body += (i == response.route_instructions.length-1) ? ' ' : ''+OSRM.Utils.toHumanDistance(response.route_instructions[i][2])+''; // fill last entry with a space
body += " | ";
body += "
";
}
body += '';
// put everything in DOM
var print_window = OSRM.G.printwindow;
print_window.document.getElementById('description').innerHTML = '