geolocation will no longer interfer with initial position/route passed

to the website,
corrected centering offset of routes
This commit is contained in:
DennisSchiefer 2012-04-18 08:51:31 +01:00
parent 596e7fc60a
commit 3d9d4f3764
2 changed files with 21 additions and 9 deletions

View File

@ -39,7 +39,7 @@ OSRM.MapView = L.Map.extend({
var zoom = this.getBoundsZoom(bounds);
var sw_point = this.project( southwest, zoom);
if( OSRM.GUI.visible == true )
sw_point.x-=OSRM.GUI.width/2+20;
sw_point.x-=OSRM.GUI.width+20;
else
sw_point.x-=20;
sw_point.y+=20;
@ -96,12 +96,6 @@ init: function() {
OSRM.Browser.getElementsByClassName(document,'leaflet-control-zoom')[0].style.left=(OSRM.GUI.width+10)+"px";
OSRM.Browser.getElementsByClassName(document,'leaflet-control-zoom')[0].style.top="5px";
// initial correct map position and zoom (respect UI visibility, use browser position)
var position = new L.LatLng( OSRM.DEFAULTS.ONLOAD_LATITUDE, OSRM.DEFAULTS.ONLOAD_LONGITUDE);
OSRM.G.map.setViewUI( position, OSRM.DEFAULTS.ONLOAD_ZOOM_LEVEL, true);
if (navigator.geolocation && document.URL.indexOf("file://") == -1) // convenience during development, as FF doesn't save rights for local files
navigator.geolocation.getCurrentPosition(OSRM.Map.geolocationResponse);
// map events
OSRM.G.map.on('zoomend', OSRM.Map.zoomed );
OSRM.G.map.on('click', OSRM.Map.click );
@ -109,6 +103,14 @@ init: function() {
OSRM.G.map.on('mousemove', OSRM.Map.mousemove );
},
// init map position and zoom (respect UI visibility / use browser geolocation)
initPosition: function() {
var position = new L.LatLng( OSRM.DEFAULTS.ONLOAD_LATITUDE, OSRM.DEFAULTS.ONLOAD_LONGITUDE);
OSRM.G.map.setViewUI( position, OSRM.DEFAULTS.ONLOAD_ZOOM_LEVEL, true);
if (navigator.geolocation && document.URL.indexOf("file://") == -1) // convenience: FF does not save access rights for local files
navigator.geolocation.getCurrentPosition(OSRM.Map.geolocationResponse);
},
// map event handlers
zoomed: function(e) { OSRM.Routing.getRoute(); },
contextmenu: function(e) {;},

View File

@ -32,6 +32,10 @@ OSRM.init = function() {
// check if the URL contains some GET parameter, e.g. for showing a route
OSRM.parseParameters();
// only init default position / geolocation position if GET parameters do not specify a different one
if( OSRM.G.initial_position_override == false )
OSRM.Map.initPosition();
};
@ -110,7 +114,10 @@ OSRM.prefetchIcons = function() {
OSRM.parseParameters = function(){
var called_url = document.location.search.substr(1,document.location.search.length);
// reject messages that are clearly too long or too small
// state, if GET parameters specify a different initial position
OSRM.G.initial_position_override = false;
// reject messages that are clearly too long or too small
if( called_url.length > 1000 || called_url.length == 0)
return;
@ -166,6 +173,7 @@ OSRM.parseParameters = function(){
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].centerView();
OSRM.G.initial_position_override = true;
return;
}
@ -195,10 +203,12 @@ OSRM.parseParameters = function(){
// compute route
OSRM.Routing.getRoute();
OSRM.G.initial_position_override = true;
return;
}
// default case: do nothing
// default case: do nothing
return;
};