more work on printing
This commit is contained in:
parent
47369a0036
commit
c7782b2776
@ -27,27 +27,27 @@ OSRM.GLOBALS.map = null;
|
|||||||
OSRM.MapView = L.Map.extend({
|
OSRM.MapView = L.Map.extend({
|
||||||
setViewUI: function(position, zoom) {
|
setViewUI: function(position, zoom) {
|
||||||
if( OSRM.GUI.visible == true ) {
|
if( OSRM.GUI.visible == true ) {
|
||||||
var point = OSRM.G.map.project( position, zoom);
|
var point = this.project( position, zoom);
|
||||||
point.x-=OSRM.GUI.width/2;
|
point.x-=OSRM.GUI.width/2;
|
||||||
position = OSRM.G.map.unproject(point,zoom);
|
position = this.unproject(point,zoom);
|
||||||
}
|
}
|
||||||
this.setView( position, zoom);
|
this.setView( position, zoom);
|
||||||
},
|
},
|
||||||
fitBoundsUI: function(bounds) {
|
fitBoundsUI: function(bounds) {
|
||||||
var southwest = bounds.getSouthWest();
|
var southwest = bounds.getSouthWest();
|
||||||
var northeast = bounds.getNorthEast();
|
var northeast = bounds.getNorthEast();
|
||||||
var zoom = OSRM.G.map.getBoundsZoom(bounds);
|
var zoom = this.getBoundsZoom(bounds);
|
||||||
var sw_point = OSRM.G.map.project( southwest, zoom);
|
var sw_point = this.project( southwest, zoom);
|
||||||
if( OSRM.GUI.visible == true )
|
if( OSRM.GUI.visible == true )
|
||||||
sw_point.x-=OSRM.GUI.width/2;
|
sw_point.x-=OSRM.GUI.width/2;
|
||||||
else
|
else
|
||||||
sw_point.x-=10;
|
sw_point.x-=10;
|
||||||
sw_point.y+=10;
|
sw_point.y+=10;
|
||||||
var ne_point = OSRM.G.map.project( northeast, zoom);
|
var ne_point = this.project( northeast, zoom);
|
||||||
ne_point.y-=10;
|
ne_point.y-=10;
|
||||||
sw_point.x+=10;
|
sw_point.x+=10;
|
||||||
bounds.extend( OSRM.G.map.unproject(sw_point,zoom) );
|
bounds.extend( this.unproject(sw_point,zoom) );
|
||||||
bounds.extend( OSRM.G.map.unproject(ne_point,zoom) );
|
bounds.extend( this.unproject(ne_point,zoom) );
|
||||||
this.fitBounds( bounds );
|
this.fitBounds( bounds );
|
||||||
},
|
},
|
||||||
getCenterUI: function(unbounded) {
|
getCenterUI: function(unbounded) {
|
||||||
|
@ -19,7 +19,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
// [printing support]
|
// [printing support]
|
||||||
|
|
||||||
OSRM.Printing = {
|
OSRM.Printing = {
|
||||||
|
|
||||||
|
// create UI for printing in mainwindow
|
||||||
init: function() {
|
init: function() {
|
||||||
var icon = document.createElement('div');
|
var icon = document.createElement('div');
|
||||||
icon.id = "gui-printer";
|
icon.id = "gui-printer";
|
||||||
@ -35,12 +36,11 @@ init: function() {
|
|||||||
document.getElementById("gui-printer").onclick = OSRM.Printing.print;
|
document.getElementById("gui-printer").onclick = OSRM.Printing.print;
|
||||||
},
|
},
|
||||||
|
|
||||||
windowLoaded: function(){
|
// create UI in printwindow
|
||||||
OSRM.Printing.show( OSRM.G.response );
|
|
||||||
OSRM.printwindow.focus();
|
|
||||||
},
|
|
||||||
|
|
||||||
show: function(response) {
|
show: function(response) {
|
||||||
|
// add events
|
||||||
|
OSRM.printwindow.document.getElementById('gui-printer').onclick = OSRM.printwindow.printWindow;
|
||||||
|
|
||||||
// create header
|
// create header
|
||||||
header =
|
header =
|
||||||
'<div class="full">' +
|
'<div class="full">' +
|
||||||
@ -68,7 +68,7 @@ show: function(response) {
|
|||||||
route_desc += '<tr class="'+rowstyle+'">';
|
route_desc += '<tr class="'+rowstyle+'">';
|
||||||
|
|
||||||
route_desc += '<td class="result-directions">';
|
route_desc += '<td class="result-directions">';
|
||||||
route_desc += '<img width="18px" src="'+OSRM.RoutingDescription.getDrivingInstructionIcon(response.route_instructions[i][0])+'" alt="" />';
|
route_desc += '<img width="18px" src=../"'+OSRM.RoutingDescription.getDrivingInstructionIcon(response.route_instructions[i][0])+'" alt="" />';
|
||||||
route_desc += "</td>";
|
route_desc += "</td>";
|
||||||
|
|
||||||
route_desc += '<td class="result-items">';
|
route_desc += '<td class="result-items">';
|
||||||
@ -99,7 +99,7 @@ show: function(response) {
|
|||||||
OSRM.printwindow.document.getElementById('description').innerHTML = route_desc;
|
OSRM.printwindow.document.getElementById('description').innerHTML = route_desc;
|
||||||
|
|
||||||
// init map
|
// init map
|
||||||
var map = OSRM.printwindow.initialize();
|
var map = OSRM.printwindow.initialize( OSRM.DEFAULTS.TILE_SERVERS[0] );
|
||||||
var markers = OSRM.G.markers.route;
|
var markers = OSRM.G.markers.route;
|
||||||
map.addLayer( new L.MouseMarker( markers[0].getPosition(), {draggable:false,clickable:false,icon:OSRM.G.icons['marker-source']} ) );
|
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++)
|
||||||
@ -110,13 +110,25 @@ show: function(response) {
|
|||||||
route.setStyle( {dashed:false,clickable:false,color:'#0033FF', weight:5} );
|
route.setStyle( {dashed:false,clickable:false,color:'#0033FF', weight:5} );
|
||||||
map.addLayer( route );
|
map.addLayer( route );
|
||||||
var bounds = new L.LatLngBounds( OSRM.G.route.getPositions() );
|
var bounds = new L.LatLngBounds( OSRM.G.route.getPositions() );
|
||||||
map.fitBounds( bounds );
|
map.fitBoundsUI( bounds );
|
||||||
},
|
},
|
||||||
|
|
||||||
// react to click
|
// open printwindow
|
||||||
print: function() {
|
print: function() {
|
||||||
|
// do not open window if there is no route to draw
|
||||||
|
if( !OSRM.G.route.isRoute() || !OSRM.G.route.isShown() )
|
||||||
|
return;
|
||||||
|
// close old window (should we really do this?)
|
||||||
|
if( OSRM.printwindow )
|
||||||
|
OSRM.printwindow.close();
|
||||||
OSRM.printwindow = window.open("printing/printing.html","","width=540,height=500,left=100,top=100,dependent=yes,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes");
|
OSRM.printwindow = window.open("printing/printing.html","","width=540,height=500,left=100,top=100,dependent=yes,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes");
|
||||||
OSRM.printwindow.addEventListener("DOMContentLoaded", OSRM.Printing.windowLoaded, false);
|
OSRM.printwindow.addEventListener("DOMContentLoaded", OSRM.Printing.printwindowLoaded, false);
|
||||||
|
},
|
||||||
|
|
||||||
|
// add content to printwindow after it has finished loading
|
||||||
|
printwindowLoaded: function(){
|
||||||
|
OSRM.Printing.show( OSRM.G.response );
|
||||||
|
OSRM.printwindow.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -39,37 +39,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
|
|
||||||
<!-- scripts -->
|
<!-- scripts -->
|
||||||
<script src="../leaflet/leaflet-src.js" type="text/javascript"></script>
|
<script src="../leaflet/leaflet-src.js" type="text/javascript"></script>
|
||||||
|
<script src="printing.js" type="text/javascript"></script>
|
||||||
<script>
|
<script src="../OSRM.Map.js" type="text/javascript"></script>
|
||||||
function initialize() {
|
|
||||||
// setup events
|
|
||||||
document.getElementById('gui-printer').onclick= printsite;
|
|
||||||
|
|
||||||
// setup map
|
|
||||||
var osmorgURL = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
|
||||||
osmorgOptions = {maxZoom: 18};
|
|
||||||
var osmorg = new L.TileLayer(osmorgURL, osmorgOptions);
|
|
||||||
var temp1 = new L.Map("map", {
|
|
||||||
center: new L.LatLng(51.505, -0.09),
|
|
||||||
zoom: 13,
|
|
||||||
zoomAnimation: false,
|
|
||||||
fadeAnimation: false,
|
|
||||||
layers: [osmorg],
|
|
||||||
attributionControl: false,
|
|
||||||
zoomControl: false,
|
|
||||||
dragging:false,
|
|
||||||
scrollWheelZoom:false,
|
|
||||||
touchZoom:false,
|
|
||||||
doubleClickZoom:false
|
|
||||||
});
|
|
||||||
return temp1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function printsite() {
|
|
||||||
window.print();
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
||||||
|
49
WebContent/printing/printing.js
Normal file
49
WebContent/printing/printing.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
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 initialization
|
||||||
|
// [for printing window]
|
||||||
|
|
||||||
|
OSRM = {};
|
||||||
|
OSRM.GLOBALS = {};
|
||||||
|
OSRM.GUI = { visible:false };
|
||||||
|
OSRM.G = OSRM.GLOBALS;
|
||||||
|
|
||||||
|
// function to initialize a map in the new window
|
||||||
|
function initialize(tile_server) {
|
||||||
|
// setup map
|
||||||
|
var tile_layer = new L.TileLayer(tile_server.url, tile_server.options);
|
||||||
|
OSRM.G.map = new OSRM.MapView("map", {
|
||||||
|
center: new L.LatLng(51.505, -0.09),
|
||||||
|
zoom: 13,
|
||||||
|
zoomAnimation: false,
|
||||||
|
fadeAnimation: false,
|
||||||
|
layers: [tile_layer],
|
||||||
|
attributionControl: false,
|
||||||
|
zoomControl: false,
|
||||||
|
dragging:false,
|
||||||
|
scrollWheelZoom:false,
|
||||||
|
touchZoom:false,
|
||||||
|
doubleClickZoom:false
|
||||||
|
});
|
||||||
|
return OSRM.G.map;
|
||||||
|
}
|
||||||
|
|
||||||
|
//print the window
|
||||||
|
function printWindow() {
|
||||||
|
window.print();
|
||||||
|
}
|
@ -1,105 +0,0 @@
|
|||||||
/*
|
|
||||||
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 CSS styles for printing*/
|
|
||||||
|
|
||||||
|
|
||||||
/* printer button */
|
|
||||||
.printer-inactive
|
|
||||||
{
|
|
||||||
cursor:pointer;
|
|
||||||
width:16px;
|
|
||||||
height:16px;
|
|
||||||
background-image:url("../images/printer_inactive.png");
|
|
||||||
}
|
|
||||||
.printer
|
|
||||||
{
|
|
||||||
cursor:pointer;
|
|
||||||
width:16px;
|
|
||||||
height:16px;
|
|
||||||
background-image:url("../images/printer.png");
|
|
||||||
}
|
|
||||||
.printer:hover
|
|
||||||
{
|
|
||||||
background-image:url("../images/printer_hover.png");
|
|
||||||
}
|
|
||||||
.printer:active
|
|
||||||
{
|
|
||||||
background-image:url("../images/printer_active.png");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* route summary */
|
|
||||||
.route-summary
|
|
||||||
{
|
|
||||||
font-size: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* route description box */
|
|
||||||
#description
|
|
||||||
{
|
|
||||||
position:absolute;
|
|
||||||
bottom:15px;
|
|
||||||
top:60px;
|
|
||||||
width:380px;
|
|
||||||
font-size:12px;
|
|
||||||
margin:5px;
|
|
||||||
}
|
|
||||||
.results-table
|
|
||||||
{
|
|
||||||
border-spacing:0px;
|
|
||||||
}
|
|
||||||
.results-odd
|
|
||||||
{
|
|
||||||
background-color: #FAF3E9; //#ffffff;
|
|
||||||
}
|
|
||||||
.results-even
|
|
||||||
{
|
|
||||||
background-color: #F2DE9C; //#ffffe0;
|
|
||||||
}
|
|
||||||
.result-items
|
|
||||||
{
|
|
||||||
text-align:left;
|
|
||||||
vertical-align: middle;
|
|
||||||
width:100%;
|
|
||||||
padding-left:1px;
|
|
||||||
padding-right:1px;
|
|
||||||
padding-top:1px;
|
|
||||||
padding-bottom:1px;
|
|
||||||
}
|
|
||||||
.result-direction
|
|
||||||
{
|
|
||||||
width:30px;
|
|
||||||
padding-left:1px;
|
|
||||||
padding-right:1px;
|
|
||||||
padding-top:1px;
|
|
||||||
padding-bottom:1px;
|
|
||||||
}
|
|
||||||
.result-distance
|
|
||||||
{
|
|
||||||
text-align:right;
|
|
||||||
vertical-align: middle;
|
|
||||||
width:30px;
|
|
||||||
padding-left:1px;
|
|
||||||
padding-right:1px;
|
|
||||||
padding-top:1px;
|
|
||||||
padding-bottom:1px;
|
|
||||||
}
|
|
||||||
.result-item
|
|
||||||
{
|
|
||||||
cursor:pointer;
|
|
||||||
color:#000000
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user