geolocation will no longer interfer with initial position/route passed
to the website, corrected centering offset of routes
This commit is contained in:
parent
596e7fc60a
commit
3d9d4f3764
@ -39,7 +39,7 @@ OSRM.MapView = L.Map.extend({
|
|||||||
var zoom = this.getBoundsZoom(bounds);
|
var zoom = this.getBoundsZoom(bounds);
|
||||||
var sw_point = this.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+20;
|
sw_point.x-=OSRM.GUI.width+20;
|
||||||
else
|
else
|
||||||
sw_point.x-=20;
|
sw_point.x-=20;
|
||||||
sw_point.y+=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.left=(OSRM.GUI.width+10)+"px";
|
||||||
OSRM.Browser.getElementsByClassName(document,'leaflet-control-zoom')[0].style.top="5px";
|
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
|
// map events
|
||||||
OSRM.G.map.on('zoomend', OSRM.Map.zoomed );
|
OSRM.G.map.on('zoomend', OSRM.Map.zoomed );
|
||||||
OSRM.G.map.on('click', OSRM.Map.click );
|
OSRM.G.map.on('click', OSRM.Map.click );
|
||||||
@ -109,6 +103,14 @@ init: function() {
|
|||||||
OSRM.G.map.on('mousemove', OSRM.Map.mousemove );
|
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
|
// map event handlers
|
||||||
zoomed: function(e) { OSRM.Routing.getRoute(); },
|
zoomed: function(e) { OSRM.Routing.getRoute(); },
|
||||||
contextmenu: function(e) {;},
|
contextmenu: function(e) {;},
|
||||||
|
@ -32,6 +32,10 @@ OSRM.init = function() {
|
|||||||
|
|
||||||
// check if the URL contains some GET parameter, e.g. for showing a route
|
// check if the URL contains some GET parameter, e.g. for showing a route
|
||||||
OSRM.parseParameters();
|
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,6 +114,9 @@ OSRM.prefetchIcons = function() {
|
|||||||
OSRM.parseParameters = function(){
|
OSRM.parseParameters = function(){
|
||||||
var called_url = document.location.search.substr(1,document.location.search.length);
|
var called_url = document.location.search.substr(1,document.location.search.length);
|
||||||
|
|
||||||
|
// 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
|
// reject messages that are clearly too long or too small
|
||||||
if( called_url.length > 1000 || called_url.length == 0)
|
if( called_url.length > 1000 || called_url.length == 0)
|
||||||
return;
|
return;
|
||||||
@ -166,6 +173,7 @@ OSRM.parseParameters = function(){
|
|||||||
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.G.markers.route[index].centerView();
|
OSRM.G.markers.route[index].centerView();
|
||||||
|
OSRM.G.initial_position_override = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,10 +203,12 @@ OSRM.parseParameters = function(){
|
|||||||
|
|
||||||
// compute route
|
// compute route
|
||||||
OSRM.Routing.getRoute();
|
OSRM.Routing.getRoute();
|
||||||
|
OSRM.G.initial_position_override = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// default case: do nothing
|
// default case: do nothing
|
||||||
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user