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",
|
"NO_ROUTE_FOUND": "Keine Route hierher möglich",
|
||||||
// printing
|
// printing
|
||||||
"OVERVIEW_MAP": "Übersichtskarte",
|
"OVERVIEW_MAP": "Übersichtskarte",
|
||||||
|
"NO_ROUTE_SELECTED": "Keine Route ausgewählt",
|
||||||
// directions
|
// directions
|
||||||
"N": "Norden",
|
"N": "Norden",
|
||||||
"E": "Ost",
|
"E": "Ost",
|
||||||
|
@ -52,6 +52,7 @@ OSRM.Localization["en"] = {
|
|||||||
"NO_ROUTE_FOUND": "No route possible",
|
"NO_ROUTE_FOUND": "No route possible",
|
||||||
//printing
|
//printing
|
||||||
"OVERVIEW_MAP": "Overview Map",
|
"OVERVIEW_MAP": "Overview Map",
|
||||||
|
"NO_ROUTE_SELECTED": "No route selected",
|
||||||
// directions
|
// directions
|
||||||
"N": "north",
|
"N": "north",
|
||||||
"E": "east",
|
"E": "east",
|
||||||
|
@ -52,6 +52,7 @@ OSRM.Localization["fi"] = {
|
|||||||
"NO_ROUTE_FOUND": "Reittiä ei löytynyt",
|
"NO_ROUTE_FOUND": "Reittiä ei löytynyt",
|
||||||
//printing
|
//printing
|
||||||
"OVERVIEW_MAP": "Yleiskuvakartta",
|
"OVERVIEW_MAP": "Yleiskuvakartta",
|
||||||
|
"NO_ROUTE_SELECTED": "Ei reitti valittu",
|
||||||
// directions
|
// directions
|
||||||
"N": "pohjoiseen",
|
"N": "pohjoiseen",
|
||||||
"E": "itään",
|
"E": "itään",
|
||||||
|
@ -52,6 +52,7 @@ OSRM.Localization["fr"] = {
|
|||||||
"NO_ROUTE_FOUND": "Pas d’itinéraire possible",
|
"NO_ROUTE_FOUND": "Pas d’itinéraire possible",
|
||||||
//printing
|
//printing
|
||||||
"OVERVIEW_MAP": "Overview Map",
|
"OVERVIEW_MAP": "Overview Map",
|
||||||
|
"NO_ROUTE_SELECTED": "Pas d’itinéraire choisi",
|
||||||
// directions
|
// directions
|
||||||
"N": "nord",
|
"N": "nord",
|
||||||
"E": "est",
|
"E": "est",
|
||||||
|
@ -35,6 +35,12 @@ init: function() {
|
|||||||
input_mask_header.appendChild(icon,input_mask_header.lastChild);
|
input_mask_header.appendChild(icon,input_mask_header.lastChild);
|
||||||
|
|
||||||
document.getElementById("gui-printer-inactive").onclick = OSRM.Printing.openPrintWindow;
|
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
|
// draw map
|
||||||
var positions = OSRM.G.route.getPositions();
|
var positions = OSRM.G.route.getPositions();
|
||||||
var tile_server_id = OSRM.G.map.getActiveLayerId();
|
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
|
// draw markers
|
||||||
print_window.prefetchIcons( OSRM.G.images );
|
print_window.OSRM.prefetchIcons( OSRM.G.images );
|
||||||
print_window.drawMarkers( OSRM.G.markers.route );
|
print_window.OSRM.drawMarkers( OSRM.G.markers.route );
|
||||||
|
|
||||||
// draw route & query for better geometry
|
// 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');
|
OSRM.JSONP.call(OSRM.Routing._buildCall()+'&z='+zoom+'&instructions=false', OSRM.Printing.drawRoute, OSRM.Printing.timeoutRoute, OSRM.DEFAULTS.JSONP_TIMEOUT, 'print');
|
||||||
},
|
},
|
||||||
timeoutRoute: function() {},
|
timeoutRoute: function() {},
|
||||||
@ -143,13 +149,13 @@ drawRoute: function(response) {
|
|||||||
if(!response)
|
if(!response)
|
||||||
return;
|
return;
|
||||||
var positions = OSRM.RoutingGeometry._decode(response.route_geometry, 5);
|
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
|
// opens the print window and closes old instances
|
||||||
openPrintWindow: function() {
|
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() )
|
if( !OSRM.G.route.isRoute() || !OSRM.G.route.isShown() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -167,16 +173,21 @@ printWindowLoaded: function(){
|
|||||||
var print_window = OSRM.G.printwindow;
|
var print_window = OSRM.G.printwindow;
|
||||||
var print_document = print_window.document;
|
var print_document = print_window.document;
|
||||||
|
|
||||||
// add events
|
|
||||||
print_document.getElementById('gui-printer').onclick = print_window.printWindow;
|
|
||||||
|
|
||||||
// localization
|
// localization
|
||||||
print_document.getElementById('description-label').innerHTML = OSRM.loc( "ROUTE_DESCRIPTION" );
|
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
|
// add routing content
|
||||||
OSRM.Printing.show( OSRM.G.response );
|
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
|
// finally, focus on printwindow
|
||||||
print_window.focus();
|
print_window.focus();
|
||||||
}
|
}
|
||||||
|
@ -135,6 +135,14 @@ div.label
|
|||||||
min-width:10px;
|
min-width:10px;
|
||||||
min-height: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 {
|
@media print {
|
||||||
.pagebreak
|
.pagebreak
|
||||||
{
|
{
|
||||||
@ -217,6 +225,11 @@ div.label
|
|||||||
{
|
{
|
||||||
background-image:url("../images/printer_active.png");
|
background-image:url("../images/printer_active.png");
|
||||||
}
|
}
|
||||||
|
#gui-printer-inactive
|
||||||
|
{
|
||||||
|
cursor:default;
|
||||||
|
background-image:url("../images/printer_inactive.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* table */
|
/* table */
|
||||||
|
@ -45,22 +45,22 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
|
|
||||||
|
|
||||||
<!-- body -->
|
<!-- body -->
|
||||||
<body class="base-font">
|
<body class="base-font not-selectable">
|
||||||
|
|
||||||
<!-- header -->
|
<!-- header -->
|
||||||
<div id="printing-header" class="noprint">
|
<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>
|
</div>
|
||||||
|
|
||||||
<!--description-->
|
<!--description-->
|
||||||
<div id="description-label" class="label">Route Description</div>
|
<div id="description-label" class="label"></div>
|
||||||
<div id="description" class="box"></div>
|
<div id="description" class="box"></div>
|
||||||
|
|
||||||
<!--map-->
|
<!--map-->
|
||||||
<div class="pagebreak"></div>
|
<div class="pagebreak"></div>
|
||||||
<div class="quad noprint"></div>
|
<div class="quad noprint"></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-description" class="box"></div>
|
||||||
<div id="overview-map"></div>
|
<div id="overview-map"></div>
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ function printWindow() {
|
|||||||
|
|
||||||
//prefetch icons
|
//prefetch icons
|
||||||
OSRM.GLOBALS.icons = {};
|
OSRM.GLOBALS.icons = {};
|
||||||
prefetchIcons = function(images_list) {
|
OSRM.prefetchIcons = function(images_list) {
|
||||||
var icon_list = [ {id:'marker-source', image_id:'marker-source'},
|
var icon_list = [ {id:'marker-source', image_id:'marker-source'},
|
||||||
{id:'marker-target', image_id:'marker-target'},
|
{id:'marker-target', image_id:'marker-target'},
|
||||||
{id:'marker-via', image_id:'marker-via'},
|
{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 to initialize a map in the new window
|
||||||
function drawMap(tile_server, bounds) {
|
OSRM.drawMap = function(tile_server, bounds) {
|
||||||
// setup map
|
// setup map
|
||||||
var tile_layer = new L.TileLayer(tile_server.url, tile_server.options);
|
var tile_layer = new L.TileLayer(tile_server.url, tile_server.options);
|
||||||
OSRM.G.map = new OSRM.MapView("overview-map", {
|
OSRM.G.map = new OSRM.MapView("overview-map", {
|
||||||
@ -70,29 +70,30 @@ function drawMap(tile_server, bounds) {
|
|||||||
|
|
||||||
OSRM.G.map.fitBoundsUI(bounds);
|
OSRM.G.map.fitBoundsUI(bounds);
|
||||||
return OSRM.G.map.getBoundsZoom(bounds);
|
return OSRM.G.map.getBoundsZoom(bounds);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
// manage makers
|
// 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']} ) );
|
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++)
|
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[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']} ) );
|
OSRM.G.map.addLayer( new L.MouseMarker( markers[markers.length-1].getPosition(), {draggable:false,clickable:false,icon:OSRM.G.icons['marker-target']} ) );
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
// manage route
|
// manage route
|
||||||
function drawRoute( positions ) {
|
OSRM.drawRoute = function( positions ) {
|
||||||
OSRM.G.route = new L.DashedPolyline();
|
OSRM.G.route = new L.DashedPolyline();
|
||||||
OSRM.G.route.setLatLngs( positions );
|
OSRM.G.route.setLatLngs( positions );
|
||||||
OSRM.G.route.setStyle( {dashed:false,clickable:false,color:'#0033FF', weight:5} );
|
OSRM.G.route.setStyle( {dashed:false,clickable:false,color:'#0033FF', weight:5} );
|
||||||
OSRM.G.map.addLayer( OSRM.G.route );
|
OSRM.G.map.addLayer( OSRM.G.route );
|
||||||
}
|
};
|
||||||
function updateRoute( positions ) {
|
OSRM.updateRoute = function( positions ) {
|
||||||
OSRM.G.route.setLatLngs( positions );
|
OSRM.G.route.setLatLngs( positions );
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
// start populating the window when it is fully loaded
|
// start populating the window when it is fully loaded - and only if it was loaded from OSRM
|
||||||
window.opener.OSRM.Browser.onLoadHandler( window.opener.OSRM.Printing.printWindowLoaded, window );
|
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);
|
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