added support for saving route zoom level and position in route links

This commit is contained in:
DennisSchiefer 2012-03-17 14:17:08 +01:00
parent d86eaa00a0
commit 9567a7e38c
2 changed files with 23 additions and 5 deletions

View File

@ -176,8 +176,10 @@ function checkURL(){
// storage for parameter values
var positions = [];
var destination = undefined;
var destination_name = undefined;
var zoom = null;
var center = null;
var destination = null;
var destination_name = null;
// parse input
var splitted_url = called_url.split('&');
@ -201,6 +203,17 @@ function checkURL(){
else if(name_val[0] == 'destname') {
destination_name = decodeURI(name_val[1]).replace(/<\/?[^>]+(>|$)/g ,""); // discard tags
}
else if(name_val[0] == 'zoom') {
zoom = name_val[1];
if( zoom<0 || zoom > 18)
return;
}
else if(name_val[0] == 'center') {
var coordinates = unescape(name_val[1]).split(',');
if(coordinates.length!=2 || !isLatitude(coordinates[0]) || !isLongitude(coordinates[1]) )
return;
center = new L.LatLng( coordinates[0], coordinates[1]);
}
}
// case 1: destination given
@ -227,9 +240,13 @@ function checkURL(){
for(var i=0; i<my_markers.route.length;i++)
my_markers.route[i].show();
// center on route
var bounds = new L.LatLngBounds( positions );
map.fitBounds( bounds );
// center on route (support for old links) / move to given view (new behaviour)
if(zoom == null || center == null) {
var bounds = new L.LatLngBounds( positions );
map.fitBounds( bounds );
} else {
map.setView(center, zoom);
}
// compute route
getRoute(OSRM.FULL_DESCRIPTION);

View File

@ -134,6 +134,7 @@ function showRouteLink_TimeOut(){
function showRouteDescription(response) {
// compute query string
var query_string = '?z='+ map.getZoom();
query_string += '&center=' + map.center.getLat() + ',' + map.center.getLng();
for(var i=0; i<my_markers.route.length; i++)
query_string += '&loc=' + my_markers.route[i].getLat() + ',' + my_markers.route[i].getLng();