recentering/zooming on a route is only done, when the route is first

drawn by clicking on the map and only if the rout doesn't fit into the
current viewport
This commit is contained in:
DennisSchiefer 2012-07-04 13:31:45 +01:00
parent d88baaf1a4
commit 5e3de973d7
2 changed files with 10 additions and 8 deletions

View File

@ -89,13 +89,13 @@ click: function(e) {
if( !OSRM.G.markers.hasSource() ) { if( !OSRM.G.markers.hasSource() ) {
var index = OSRM.G.markers.setSource( e.latlng ); var index = OSRM.G.markers.setSource( e.latlng );
OSRM.Geocoder.updateAddress( OSRM.C.SOURCE_LABEL, OSRM.C.DO_FALLBACK_TO_LAT_LNG ); OSRM.Geocoder.updateAddress( OSRM.C.SOURCE_LABEL, OSRM.C.DO_FALLBACK_TO_LAT_LNG );
OSRM.G.markers.route[index].show(); OSRM.G.markers.route[index].show();
OSRM.Routing.getRoute(); OSRM.Routing.getRoute( {recenter:OSRM.G.markers.route.length == 2} ); // allow recentering when the route is first shown
} else if( !OSRM.G.markers.hasTarget() ) { } else if( !OSRM.G.markers.hasTarget() ) {
var index = OSRM.G.markers.setTarget( e.latlng ); var index = OSRM.G.markers.setTarget( e.latlng );
OSRM.Geocoder.updateAddress( OSRM.C.TARGET_LABEL, OSRM.C.DO_FALLBACK_TO_LAT_LNG ); OSRM.Geocoder.updateAddress( OSRM.C.TARGET_LABEL, OSRM.C.DO_FALLBACK_TO_LAT_LNG );
OSRM.G.markers.route[index].show(); OSRM.G.markers.route[index].show();
OSRM.Routing.getRoute(); OSRM.Routing.getRoute( {recenter:OSRM.G.markers.route.length == 2} ); // allow recentering when the route is first shown
} }
}, },
geolocationResponse: function(response) { geolocationResponse: function(response) {

View File

@ -54,7 +54,7 @@ timeoutRoute_Reversed: function() {
OSRM.G.markers.reverseMarkers(); OSRM.G.markers.reverseMarkers();
OSRM.Routing.timeoutRoute(); OSRM.Routing.timeoutRoute();
}, },
showRoute: function(response) { showRoute: function(response, parameters) {
if(!response) if(!response)
return; return;
@ -71,8 +71,10 @@ showRoute: function(response) {
OSRM.Routing._snapRoute(); OSRM.Routing._snapRoute();
} }
OSRM.Routing._updateHints(response); OSRM.Routing._updateHints(response);
var bounds = new L.LatLngBounds( OSRM.G.route._current_route.getPositions() ); if( parameters && parameters.recenter == true ) { // allow recentering when the route is first shown
OSRM.G.map.setViewBoundsUI(bounds); var bounds = new L.LatLngBounds( OSRM.G.route._current_route.getPositions() );
OSRM.G.map.setViewBoundsUI(bounds);
}
}, },
showRoute_Dragging: function(response) { showRoute_Dragging: function(response) {
if(!response) if(!response)
@ -109,7 +111,7 @@ showRoute_Redraw: function(response) {
//-- main function -- //-- main function --
//generate server calls to query routes //generate server calls to query routes
getRoute: function() { getRoute: function(parameters) {
// if source or target are not set -> hide route // if source or target are not set -> hide route
if( OSRM.G.markers.route.length < 2 ) { if( OSRM.G.markers.route.length < 2 ) {
@ -119,7 +121,7 @@ getRoute: function() {
OSRM.JSONP.clear('dragging'); OSRM.JSONP.clear('dragging');
OSRM.JSONP.clear('redraw'); OSRM.JSONP.clear('redraw');
OSRM.JSONP.clear('route'); OSRM.JSONP.clear('route');
OSRM.JSONP.call(OSRM.Routing._buildCall()+'&instructions=true', OSRM.Routing.showRoute, OSRM.Routing.timeoutRoute, OSRM.DEFAULTS.JSONP_TIMEOUT, 'route'); OSRM.JSONP.call(OSRM.Routing._buildCall()+'&instructions=true', OSRM.Routing.showRoute, OSRM.Routing.timeoutRoute, OSRM.DEFAULTS.JSONP_TIMEOUT, 'route', parameters);
}, },
getRoute_Reversed: function() { getRoute_Reversed: function() {
if( OSRM.G.markers.route.length < 2 ) if( OSRM.G.markers.route.length < 2 )