From 3d9d4f37649f95de6aeec86b55d9afba173ef266 Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Wed, 18 Apr 2012 08:51:31 +0100 Subject: [PATCH] geolocation will no longer interfer with initial position/route passed to the website, corrected centering offset of routes --- WebContent/OSRM.Map.js | 16 +++++++++------- WebContent/main.js | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/WebContent/OSRM.Map.js b/WebContent/OSRM.Map.js index c9858469b..16dc74eea 100644 --- a/WebContent/OSRM.Map.js +++ b/WebContent/OSRM.Map.js @@ -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) {;}, diff --git a/WebContent/main.js b/WebContent/main.js index 40abb4fd5..8755fbf8b 100644 --- a/WebContent/main.js +++ b/WebContent/main.js @@ -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; };