made printing window more robust (on refresh, stand-alone opening,
closing browser window...)
This commit is contained in:
parent
42f38a42db
commit
90925bd91d
@ -52,6 +52,7 @@ OSRM.Localization["de"] = {
|
||||
"NO_ROUTE_FOUND": "Keine Route hierher möglich",
|
||||
// printing
|
||||
"OVERVIEW_MAP": "Übersichtskarte",
|
||||
"NO_ROUTE_SELECTED": "Keine Route ausgewählt",
|
||||
// directions
|
||||
"N": "Norden",
|
||||
"E": "Ost",
|
||||
|
@ -52,6 +52,7 @@ OSRM.Localization["en"] = {
|
||||
"NO_ROUTE_FOUND": "No route possible",
|
||||
//printing
|
||||
"OVERVIEW_MAP": "Overview Map",
|
||||
"NO_ROUTE_SELECTED": "No route selected",
|
||||
// directions
|
||||
"N": "north",
|
||||
"E": "east",
|
||||
|
@ -52,6 +52,7 @@ OSRM.Localization["fi"] = {
|
||||
"NO_ROUTE_FOUND": "Reittiä ei löytynyt",
|
||||
//printing
|
||||
"OVERVIEW_MAP": "Yleiskuvakartta",
|
||||
"NO_ROUTE_SELECTED": "Ei reitti valittu",
|
||||
// directions
|
||||
"N": "pohjoiseen",
|
||||
"E": "itään",
|
||||
|
@ -52,6 +52,7 @@ OSRM.Localization["fr"] = {
|
||||
"NO_ROUTE_FOUND": "Pas d’itinéraire possible",
|
||||
//printing
|
||||
"OVERVIEW_MAP": "Overview Map",
|
||||
"NO_ROUTE_SELECTED": "Pas d’itinéraire choisi",
|
||||
// directions
|
||||
"N": "nord",
|
||||
"E": "est",
|
||||
|
@ -35,6 +35,12 @@ init: function() {
|
||||
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();
|
||||
},
|
||||
|
||||
|
||||
@ -128,14 +134,14 @@ show: function(response) {
|
||||
// draw map
|
||||
var positions = OSRM.G.route.getPositions();
|
||||
var tile_server_id = OSRM.G.map.getActiveLayerId();
|
||||
var zoom = print_window.drawMap( OSRM.DEFAULTS.TILE_SERVERS[tile_server_id], new L.LatLngBounds( positions ) );
|
||||
var zoom = print_window.OSRM.drawMap( OSRM.DEFAULTS.TILE_SERVERS[tile_server_id], new L.LatLngBounds( positions ) );
|
||||
|
||||
// draw markers
|
||||
print_window.prefetchIcons( OSRM.G.images );
|
||||
print_window.drawMarkers( OSRM.G.markers.route );
|
||||
print_window.OSRM.prefetchIcons( OSRM.G.images );
|
||||
print_window.OSRM.drawMarkers( OSRM.G.markers.route );
|
||||
|
||||
// draw route & query for better geometry
|
||||
print_window.drawRoute( positions );
|
||||
print_window.OSRM.drawRoute( positions );
|
||||
OSRM.JSONP.call(OSRM.Routing._buildCall()+'&z='+zoom+'&instructions=false', OSRM.Printing.drawRoute, OSRM.Printing.timeoutRoute, OSRM.DEFAULTS.JSONP_TIMEOUT, 'print');
|
||||
},
|
||||
timeoutRoute: function() {},
|
||||
@ -143,13 +149,13 @@ drawRoute: function(response) {
|
||||
if(!response)
|
||||
return;
|
||||
var positions = OSRM.RoutingGeometry._decode(response.route_geometry, 5);
|
||||
OSRM.G.printwindow.drawRoute( positions );
|
||||
OSRM.G.printwindow.OSRM.drawRoute( positions );
|
||||
},
|
||||
|
||||
|
||||
// opens the print window and closes old instances
|
||||
openPrintWindow: function() {
|
||||
// do not open window if there is no route to draw
|
||||
// do not open window if there is no route to draw (should never trigger!)
|
||||
if( !OSRM.G.route.isRoute() || !OSRM.G.route.isShown() )
|
||||
return;
|
||||
|
||||
@ -167,16 +173,21 @@ printWindowLoaded: function(){
|
||||
var print_window = OSRM.G.printwindow;
|
||||
var print_document = print_window.document;
|
||||
|
||||
// add events
|
||||
print_document.getElementById('gui-printer').onclick = print_window.printWindow;
|
||||
|
||||
// localization
|
||||
print_document.getElementById('description-label').innerHTML = OSRM.loc( "ROUTE_DESCRIPTION" );
|
||||
print_document.getElementById('overview-map-label').innerHTML = OSRM.loc( "OVERVIEW_MAP" );
|
||||
|
||||
print_document.getElementById('overview-map-label').innerHTML = OSRM.loc( "OVERVIEW_MAP" );
|
||||
if( !OSRM.G.route.isRoute() || !OSRM.G.route.isShown() ) { // error message if no route available (can trigger if user refreshes print-window)
|
||||
print_document.getElementById("description").innerHTML = OSRM.loc("NO_ROUTE_SELECTED");
|
||||
return;
|
||||
}
|
||||
|
||||
// add routing content
|
||||
OSRM.Printing.show( OSRM.G.response );
|
||||
|
||||
// add events
|
||||
print_document.getElementById("gui-printer-inactive").id = "gui-printer";
|
||||
print_document.getElementById('gui-printer').onclick = print_window.printWindow;
|
||||
|
||||
// finally, focus on printwindow
|
||||
print_window.focus();
|
||||
}
|
||||
|
@ -135,6 +135,14 @@ div.label
|
||||
min-width:10px;
|
||||
min-height:10px;
|
||||
}
|
||||
.not-selectable
|
||||
{
|
||||
cursor:default;
|
||||
-moz-user-select: -moz-none;
|
||||
-webkit-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
@media print {
|
||||
.pagebreak
|
||||
{
|
||||
@ -217,6 +225,11 @@ div.label
|
||||
{
|
||||
background-image:url("../images/printer_active.png");
|
||||
}
|
||||
#gui-printer-inactive
|
||||
{
|
||||
cursor:default;
|
||||
background-image:url("../images/printer_inactive.png");
|
||||
}
|
||||
|
||||
|
||||
/* table */
|
||||
|
@ -45,22 +45,22 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
|
||||
|
||||
<!-- body -->
|
||||
<body class="base-font">
|
||||
<body class="base-font not-selectable">
|
||||
|
||||
<!-- header -->
|
||||
<div id="printing-header" class="noprint">
|
||||
<div id="gui-printer" class="iconic-button top-right-button"></div>
|
||||
<div id="gui-printer-inactive" class="iconic-button top-right-button"></div>
|
||||
</div>
|
||||
|
||||
<!--description-->
|
||||
<div id="description-label" class="label">Route Description</div>
|
||||
<div id="description-label" class="label"></div>
|
||||
<div id="description" class="box"></div>
|
||||
|
||||
<!--map-->
|
||||
<div class="pagebreak"></div>
|
||||
<div class="quad noprint"></div>
|
||||
<div class="quad noprint"></div>
|
||||
<div id="overview-map-label" class="label">Overview Map</div>
|
||||
<div id="overview-map-label" class="label"></div>
|
||||
<div id="overview-map-description" class="box"></div>
|
||||
<div id="overview-map"></div>
|
||||
|
||||
|
@ -32,7 +32,7 @@ function printWindow() {
|
||||
|
||||
//prefetch icons
|
||||
OSRM.GLOBALS.icons = {};
|
||||
prefetchIcons = function(images_list) {
|
||||
OSRM.prefetchIcons = function(images_list) {
|
||||
var icon_list = [ {id:'marker-source', image_id:'marker-source'},
|
||||
{id:'marker-target', image_id:'marker-target'},
|
||||
{id:'marker-via', image_id:'marker-via'},
|
||||
@ -51,7 +51,7 @@ prefetchIcons = function(images_list) {
|
||||
|
||||
|
||||
// function to initialize a map in the new window
|
||||
function drawMap(tile_server, bounds) {
|
||||
OSRM.drawMap = function(tile_server, bounds) {
|
||||
// setup map
|
||||
var tile_layer = new L.TileLayer(tile_server.url, tile_server.options);
|
||||
OSRM.G.map = new OSRM.MapView("overview-map", {
|
||||
@ -70,29 +70,30 @@ function drawMap(tile_server, bounds) {
|
||||
|
||||
OSRM.G.map.fitBoundsUI(bounds);
|
||||
return OSRM.G.map.getBoundsZoom(bounds);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// manage makers
|
||||
function drawMarkers( markers ) {
|
||||
OSRM.drawMarkers = function( markers ) {
|
||||
OSRM.G.map.addLayer( new L.MouseMarker( markers[0].getPosition(), {draggable:false,clickable:false,icon:OSRM.G.icons['marker-source']} ) );
|
||||
for(var i=1, size=markers.length-1; i<size; i++)
|
||||
OSRM.G.map.addLayer( new L.MouseMarker( markers[i].getPosition(), {draggable:false,clickable:false,icon:OSRM.G.icons['marker-via']} ) );
|
||||
OSRM.G.map.addLayer( new L.MouseMarker( markers[markers.length-1].getPosition(), {draggable:false,clickable:false,icon:OSRM.G.icons['marker-target']} ) );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// manage route
|
||||
function drawRoute( positions ) {
|
||||
OSRM.drawRoute = function( positions ) {
|
||||
OSRM.G.route = new L.DashedPolyline();
|
||||
OSRM.G.route.setLatLngs( positions );
|
||||
OSRM.G.route.setStyle( {dashed:false,clickable:false,color:'#0033FF', weight:5} );
|
||||
OSRM.G.map.addLayer( OSRM.G.route );
|
||||
}
|
||||
function updateRoute( positions ) {
|
||||
};
|
||||
OSRM.updateRoute = function( positions ) {
|
||||
OSRM.G.route.setLatLngs( positions );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// start populating the window when it is fully loaded
|
||||
window.opener.OSRM.Browser.onLoadHandler( window.opener.OSRM.Printing.printWindowLoaded, window );
|
||||
// start populating the window when it is fully loaded - and only if it was loaded from OSRM
|
||||
if(window.opener && window.opener.OSRM)
|
||||
window.opener.OSRM.Browser.onLoadHandler( window.opener.OSRM.Printing.printWindowLoaded, window );
|
@ -67,4 +67,15 @@ OSRM.Browser.onLoadHandler = function( function_pointer, the_window ) {
|
||||
};
|
||||
the_document.attachEvent("onreadystatechange", temp_function);
|
||||
}
|
||||
};
|
||||
OSRM.Browser.onUnloadHandler = function( function_pointer, the_window ) {
|
||||
the_window = the_window || window; // default document
|
||||
var the_document = the_window.document;
|
||||
|
||||
if(the_window.addEventListener) { // FF, CH, IE9+
|
||||
the_window.addEventListener("unload", function_pointer, false);
|
||||
}
|
||||
else if(the_document.attachEvent) { // IE8-
|
||||
the_document.attachEvent("onunload", function_pointer);
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user