diff --git a/WebContent/OSRM.Markers.js b/WebContent/OSRM.Markers.js index d970241a3..de782bd52 100644 --- a/WebContent/OSRM.Markers.js +++ b/WebContent/OSRM.Markers.js @@ -34,11 +34,11 @@ OSRM.Marker = function( label, style, position ) { }; OSRM.extend( OSRM.Marker,{ show: function() { - map.addLayer(this.marker); + OSRM.G.map.addLayer(this.marker); this.shown = true; }, hide: function() { - map.removeLayer(this.marker); + OSRM.G.map.removeLayer(this.marker); this.shown = false; }, setPosition: function( position ) { @@ -61,9 +61,9 @@ isShown: function() { centerView: function(zooming) { var zoom = OSRM.DEFAULTS.ZOOM_LEVEL; if( zooming == false ) - zoom = map.getZoom(); - //map.setView( new L.LatLng( this.position.lat, this.position.lng-0.02), zoom); // dirty hack - map.setView( new L.LatLng( this.position.lat, this.position.lng), zoom); + zoom = OSRM.G.map.getZoom(); + //OSRM.G.map.setView( new L.LatLng( this.position.lat, this.position.lng-0.02), zoom); // dirty hack + OSRM.G.map.setView( new L.LatLng( this.position.lat, this.position.lng), zoom); }, toString: function() { return "OSRM.Marker: \""+this.label+"\", "+this.position+")"; @@ -102,57 +102,57 @@ OSRM.RouteMarker = function ( label, style, position ) { OSRM.inheritFrom( OSRM.RouteMarker, OSRM.Marker ); OSRM.extend( OSRM.RouteMarker, { onClick: function(e) { - for( var i=0; i this.route.length-2 ) return -1; - this.route.splice(id+1,0, new OSRM.RouteMarker("via", {draggable:true,icon:OSRM.icons['marker-via']}, position)); + this.route.splice(id+1,0, new OSRM.RouteMarker(OSRM.CONSTANTS.VIA_LABEL, {draggable:true,icon:OSRM.icons['marker-via']}, position)); return id+1; }, removeMarker: function(id) { @@ -208,9 +208,9 @@ removeMarker: function(id) { return; // also remove vias if source or target are removed - if( id==0 && this.route[0].label == OSRM.SOURCE_MARKER_LABEL ) + if( id==0 && this.route[0].label == OSRM.CONSTANTS.SOURCE_LABEL ) this.removeVias(); - else if( id == this.route.length-1 && this.route[ this.route.length-1 ].label == OSRM.TARGET_MARKER_LABEL ) { + else if( id == this.route.length-1 && this.route[ this.route.length-1 ].label == OSRM.CONSTANTS.TARGET_LABEL ) { this.removeVias(); id = this.route.length-1; } @@ -219,12 +219,12 @@ removeMarker: function(id) { this.route.splice(id, 1); }, hasSource: function() { - if( my_markers.route[0] && my_markers.route[0].label == OSRM.SOURCE_MARKER_LABEL ) + if( OSRM.G.markers.route[0] && OSRM.G.markers.route[0].label == OSRM.CONSTANTS.SOURCE_LABEL ) return true; return false; }, hasTarget: function() { - if( my_markers.route[my_markers.route.length-1] && my_markers.route[my_markers.route.length-1].label == OSRM.TARGET_MARKER_LABEL ) + if( OSRM.G.markers.route[OSRM.G.markers.route.length-1] && OSRM.G.markers.route[OSRM.G.markers.route.length-1].label == OSRM.CONSTANTS.TARGET_LABEL ) return true; return false; } diff --git a/WebContent/OSRM.Route.js b/WebContent/OSRM.Route.js index 6c7db4395..39cb278af 100644 --- a/WebContent/OSRM.Route.js +++ b/WebContent/OSRM.Route.js @@ -32,11 +32,11 @@ OSRM.SimpleRoute = function (label, style) { }; OSRM.extend( OSRM.SimpleRoute,{ show: function() { - map.addLayer(this.route); + OSRM.G.map.addLayer(this.route); this.shown = true; }, hide: function() { - map.removeLayer(this.route); + OSRM.G.map.removeLayer(this.route); this.shown = false; }, isShown: function() { @@ -53,10 +53,10 @@ setStyle: function(style) { }, centerView: function() { var bounds = new L.LatLngBounds( this.getPositions() ); - map.fitBounds( bounds ); + OSRM.G.map.fitBounds( bounds ); }, onClick: function(e) { - if(my_route.isRoute()) + if(OSRM.G.route.isRoute()) findViaPosition( e.latlng ); }, toString: function() { @@ -74,11 +74,11 @@ OSRM.MultiRoute = function (label) { }; OSRM.extend( OSRM.MultiRoute,{ show: function() { - map.addLayer(this.route); + OSRM.G.map.addLayer(this.route); this.shown = true; }, hide: function() { - map.removeLayer(this.route); + OSRM.G.map.removeLayer(this.route); this.shown = false; }, isShown: function() { @@ -86,7 +86,7 @@ isShown: function() { }, addRoute: function(positions) { var line = new L.DashedPolyline( positions ); - line.on('click', function(e) { my_route.fire('click',e); }); + line.on('click', function(e) { OSRM.G.route.fire('click',e); }); this.route.addLayer( line ); }, clearRoutes: function() { diff --git a/WebContent/OSRM.base.js b/WebContent/OSRM.base.js index eea2a1457..0a4de29fa 100644 --- a/WebContent/OSRM.base.js +++ b/WebContent/OSRM.base.js @@ -23,6 +23,8 @@ OSRM.VERSION = '0.1.1'; OSRM.CONSTANTS = {}; OSRM.DEFAULTS = {}; OSRM.GLOBALS = {}; +OSRM.G = OSRM.GLOBALS; // abbreviations +OSRM.C = OSRM.CONSTANTS; // [convenience function] declare one class to be a subclass of another class diff --git a/WebContent/OSRM.config.js b/WebContent/OSRM.config.js index 849c9cca3..0348b0554 100644 --- a/WebContent/OSRM.config.js +++ b/WebContent/OSRM.config.js @@ -21,6 +21,8 @@ or see http://www.gnu.org/licenses/agpl.txt. OSRM.DEFAULTS = { HOST_ROUTING_URL: 'http://router.project-osrm.org/viaroute', HOST_SHORTENER_URL: 'http://map.project-osrm.org/shorten/', + HOST_GEOCODER_URL: 'http://nominatim.openstreetmap.org/search', + HOST_REVERSE_GEOCODER_URL: 'http://nominatim.openstreetmap.org/reverse', WEBSITE_URL: document.URL.replace(/#*(\?.*|$)/i,""), // truncates URL before first ?, and removes tailing # JSONP_TIMEOUT: 5000, ZOOM_LEVEL: 14, @@ -28,5 +30,6 @@ OSRM.DEFAULTS = { ONLOAD_LONGITUDE: 10.10, ONLOAD_SOURCE: "", ONLOAD_TARGET: "", - LANGUAGE: "en" + LANGUAGE: "en", + GEOCODER_BOUNDS: '&bounded=1&viewbox=-27.0,72.0,46.0,36.0' }; diff --git a/WebContent/geocoder.js b/WebContent/geocoder.js index a4b7ac453..9c02a5bc7 100644 --- a/WebContent/geocoder.js +++ b/WebContent/geocoder.js @@ -20,26 +20,26 @@ or see http://www.gnu.org/licenses/agpl.txt. // [TODO: better separation of GUI and geocoding routines, reverse geocoding] // some constants -OSRM.GEOCODE_POST = 'http://nominatim.openstreetmap.org/search?format=json&bounded=1&viewbox=-27.0,72.0,46.0,36.0'; -OSRM.SOURCE_MARKER_LABEL = "source"; -OSRM.TARGET_MARKER_LABEL = "target"; +OSRM.CONSTANTS.SOURCE_LABEL = "source"; +OSRM.CONSTANTS.TARGET_LABEL = "target"; +OSRM.CONSTANTS.VIA_LABEL = "via"; // update geo coordinates in input boxes function updateLocation(marker_id) { - if (marker_id == OSRM.SOURCE_MARKER_LABEL && my_markers.route[0].dirty_move == true ) { - document.getElementById("input-source-name").value = my_markers.route[0].getPosition().lat.toFixed(6) + ", " + my_markers.route[0].getPosition().lng.toFixed(6); - } else if (marker_id == OSRM.TARGET_MARKER_LABEL && my_markers.route[my_markers.route.length-1].dirty_move == true) { - document.getElementById("input-target-name").value = my_markers.route[my_markers.route.length-1].getPosition().lat.toFixed(6) + ", " + my_markers.route[my_markers.route.length-1].getPosition().lng.toFixed(6); + if (marker_id == OSRM.CONSTANTS.SOURCE_LABEL && OSRM.G.markers.route[0].dirty_move == true ) { + document.getElementById("input-source-name").value = OSRM.G.markers.route[0].getPosition().lat.toFixed(6) + ", " + OSRM.G.markers.route[0].getPosition().lng.toFixed(6); + } else if (marker_id == OSRM.CONSTANTS.TARGET_LABEL && OSRM.G.markers.route[OSRM.G.markers.route.length-1].dirty_move == true) { + document.getElementById("input-target-name").value = OSRM.G.markers.route[OSRM.G.markers.route.length-1].getPosition().lat.toFixed(6) + ", " + OSRM.G.markers.route[OSRM.G.markers.route.length-1].getPosition().lng.toFixed(6); } } // process input request and call geocoder if needed function callGeocoder(marker_id, query) { - if (marker_id == OSRM.SOURCE_MARKER_LABEL && my_markers.hasSource() && my_markers.route[0].dirty_move == false && my_markers.route[0].dirty_type == false) + if (marker_id == OSRM.CONSTANTS.SOURCE_LABEL && OSRM.G.markers.hasSource() && OSRM.G.markers.route[0].dirty_move == false && OSRM.G.markers.route[0].dirty_type == false) return; - if (marker_id == OSRM.TARGET_MARKER_LABEL && my_markers.hasTarget() && my_markers.route[my_markers.route.length-1].dirty_move == false && my_markers.route[my_markers.route.length-1].dirty_type == false) + if (marker_id == OSRM.CONSTANTS.TARGET_LABEL && OSRM.G.markers.hasTarget() && OSRM.G.markers.route[OSRM.G.markers.route.length-1].dirty_move == false && OSRM.G.markers.route[OSRM.G.markers.route.length-1].dirty_type == false) return; if(query=="") return; @@ -52,12 +52,12 @@ function callGeocoder(marker_id, query) { } //build request - if (marker_id == OSRM.SOURCE_MARKER_LABEL) { - var src= OSRM.GEOCODE_POST + "&q=" + query; - OSRM.JSONP.call( src, showGeocoderResults_Source, showGeocoderResults_Timeout, OSRM.DEFAULTS.JSONP_TIMEOUT, "geocoder_source" ); - } else if (marker_id == OSRM.TARGET_MARKER_LABEL) { - var src = OSRM.GEOCODE_POST + "&q=" + query; - OSRM.JSONP.call( src, showGeocoderResults_Target, showGeocoderResults_Timeout, OSRM.DEFAULTS.JSONP_TIMEOUT, "geocoder_target" ); + if (marker_id == OSRM.CONSTANTS.SOURCE_LABEL) { + var call = OSRM.DEFAULTS.HOST_GEOCODER_URL + "?format=json" + OSRM.DEFAULTS.GEOCODER_BOUNDS + "&q=" + query; + OSRM.JSONP.call( call, showGeocoderResults_Source, showGeocoderResults_Timeout, OSRM.DEFAULTS.JSONP_TIMEOUT, "geocoder_source" ); + } else if (marker_id == OSRM.CONSTANTS.TARGET_LABEL) { + var call = OSRM.DEFAULTS.HOST_GEOCODER_URL + "?format=json" + OSRM.DEFAULTS.GEOCODER_BOUNDS + "&q=" + query; + OSRM.JSONP.call( call, showGeocoderResults_Target, showGeocoderResults_Timeout, OSRM.DEFAULTS.JSONP_TIMEOUT, "geocoder_target" ); } } @@ -65,10 +65,10 @@ function callGeocoder(marker_id, query) { // helper function for clicks on geocoder search results function onclickGeocoderResult(marker_id, lat, lon, do_reverse_geocode, zoom ) { var index; - if( marker_id == OSRM.SOURCE_MARKER_LABEL ) - index = my_markers.setSource( new L.LatLng(lat, lon) ); - else if( marker_id == OSRM.TARGET_MARKER_LABEL ) - index = my_markers.setTarget( new L.LatLng(lat, lon) ); + if( marker_id == OSRM.CONSTANTS.SOURCE_LABEL ) + index = OSRM.G.markers.setSource( new L.LatLng(lat, lon) ); + else if( marker_id == OSRM.CONSTANTS.TARGET_LABEL ) + index = OSRM.G.markers.setTarget( new L.LatLng(lat, lon) ); else index = -1; // via nodes not yet implemented @@ -77,19 +77,19 @@ function onclickGeocoderResult(marker_id, lat, lon, do_reverse_geocode, zoom ) { if( zoom == undefined ) zoom = true; - my_markers.route[index].show(); - if( !my_markers.route[index].dirty_move || my_markers.route[index].dirty_type ) - my_markers.route[index].centerView(zoom); - getRoute(OSRM.FULL_DESCRIPTION); + OSRM.G.markers.route[index].show(); + if( !OSRM.G.markers.route[index].dirty_move || OSRM.G.markers.route[index].dirty_type ) + OSRM.G.markers.route[index].centerView(zoom); + getRoute(OSRM.CONSTANTS.FULL_DESCRIPTION); - my_markers.route[index].dirty_move = false; - my_markers.route[index].dirty_type = false; + OSRM.G.markers.route[index].dirty_move = false; + OSRM.G.markers.route[index].dirty_type = false; } // process JSONP response of geocoder // (with wrapper functions for source/target jsonp) -function showGeocoderResults_Source(response) { showGeocoderResults(OSRM.SOURCE_MARKER_LABEL, response); } -function showGeocoderResults_Target(response) { showGeocoderResults(OSRM.TARGET_MARKER_LABEL, response); } +function showGeocoderResults_Source(response) { showGeocoderResults(OSRM.CONSTANTS.SOURCE_LABEL, response); } +function showGeocoderResults_Target(response) { showGeocoderResults(OSRM.CONSTANTS.TARGET_LABEL, response); } function showGeocoderResults(marker_id, response) { if(response){ if(response.length == 0) { @@ -125,9 +125,9 @@ function showGeocoderResults(marker_id, response) { } function showGeocoderResults_Empty(marker_id) { document.getElementById('information-box-headline').innerHTML = OSRM.loc("SEARCH_RESULTS")+":"; - if(marker_id == OSRM.SOURCE_MARKER_LABEL) + if(marker_id == OSRM.CONSTANTS.SOURCE_LABEL) document.getElementById('information-box').innerHTML = "

"+OSRM.loc("NO_RESULTS_FOUND_SOURCE")+".

"; - else if(marker_id == OSRM.TARGET_MARKER_LABEL) + else if(marker_id == OSRM.CONSTANTS.TARGET_LABEL) document.getElementById('information-box').innerHTML = "

"+OSRM.loc("NO_RESULTS_FOUND_TARGET")+".

"; else document.getElementById('information-box').innerHTML = "

"+OSRM.loc("NO_RESULTS_FOUND")+".

"; @@ -139,35 +139,34 @@ function showGeocoderResults_Timeout() { // - [upcoming feature: reverse geocoding (untested) ] - -OSRM.REVERSE_GEOCODE_POST = 'http://nominatim.openstreetmap.org/reverse?format=json&bounded=1&viewbox=-27.0,72.0,46.0,36.0'; //update reverse geocoder informatiopn in input boxes function updateReverseGeocoder(marker_id) { - if (marker_id == OSRM.SOURCE_MARKER_LABEL && my_markers.hasSource()) { //&& my_markers.route[0].dirty == true ) { - //document.getElementById("input-source-name").value = my_markers.route[0].getPosition().lat.toFixed(6) + ", " + my_markers.route[0].getPosition().lng.toFixed(6); - callReverseGeocoder("source", my_markers.route[0].getPosition().lat, my_markers.route[0].getPosition().lng); - } else if (marker_id == OSRM.TARGET_MARKER_LABEL && my_markers.hasTarget()) { //&& my_markers.route[my_markers.route.length-1].dirty == true) { - //document.getElementById("input-target-name").value = my_markers.route[my_markers.route.length-1].getPosition().lat.toFixed(6) + ", " + my_markers.route[my_markers.route.length-1].getPosition().lng.toFixed(6); - callReverseGeocoder("target", my_markers.route[my_markers.route.length-1].getPosition().lat, my_markers.route[my_markers.route.length-1].getPosition().lng); + if (marker_id == OSRM.CONSTANTS.SOURCE_LABEL && OSRM.G.markers.hasSource()) { //&& OSRM.G.markers.route[0].dirty == true ) { + //document.getElementById("input-source-name").value = OSRM.G.markers.route[0].getPosition().lat.toFixed(6) + ", " + OSRM.G.markers.route[0].getPosition().lng.toFixed(6); + callReverseGeocoder(OSRM.CONSTANTS.SOURCE_LABEL, OSRM.G.markers.route[0].getPosition().lat, OSRM.G.markers.route[0].getPosition().lng); + } else if (marker_id == OSRM.CONSTANTS.TARGET_LABEL && OSRM.G.markers.hasTarget()) { //&& OSRM.G.markers.route[OSRM.G.markers.route.length-1].dirty == true) { + //document.getElementById("input-target-name").value = OSRM.G.markers.route[OSRM.G.markers.route.length-1].getPosition().lat.toFixed(6) + ", " + OSRM.G.markers.route[OSRM.G.markers.route.length-1].getPosition().lng.toFixed(6); + callReverseGeocoder(OSRM.CONSTANTS.TARGET_LABEL, OSRM.G.markers.route[OSRM.G.markers.route.length-1].getPosition().lat, OSRM.G.markers.route[OSRM.G.markers.route.length-1].getPosition().lng); } } //prepare request and call reverse geocoder function callReverseGeocoder(marker_id, lat, lon) { //build request - if (marker_id == OSRM.SOURCE_MARKER_LABEL) { - var src= OSRM.REVERSE_GEOCODE_POST + "&lat=" + lat + "&lon=" + lon; - OSRM.JSONP.call( src, showReverseGeocoderResults_Source, showReverseGeocoderResults_Timeout, OSRM.DEFAULTS.JSONP_TIMEOUT, "reverse_geocoder_source" ); - } else if (marker_id == OSRM.TARGET_MARKER_LABEL) { - var src = OSRM.REVERSE_GEOCODE_POST + "&lat=" + lat + "&lon=" + lon; - OSRM.JSONP.call( src, showReverseGeocoderResults_Target, showReverseGeocoderResults_Timeout, OSRM.DEFAULTS.JSONP_TIMEOUT, "reverse_geocoder_target" ); + if (marker_id == OSRM.CONSTANTS.SOURCE_LABEL) { + var call = OSRM.DEFAULTS.HOST_REVERSE_GEOCODER_URL + "?format=json" + "&lat=" + lat + "&lon=" + lon; + OSRM.JSONP.call( call, showReverseGeocoderResults_Source, showReverseGeocoderResults_Timeout, OSRM.DEFAULTS.JSONP_TIMEOUT, "reverse_geocoder_source" ); + } else if (marker_id == OSRM.CONSTANTS.TARGET_LABEL) { + var call = OSRM.DEFAULTS.HOST_REVERSE_GEOCODER_URL + "?format=json" + "&lat=" + lat + "&lon=" + lon; + OSRM.JSONP.call( call, showReverseGeocoderResults_Target, showReverseGeocoderResults_Timeout, OSRM.DEFAULTS.JSONP_TIMEOUT, "reverse_geocoder_target" ); } } //processing JSONP response of reverse geocoder //(with wrapper functions for source/target jsonp) function showReverseGeocoderResults_Timeout() {} -function showReverseGeocoderResults_Source(response) { showReverseGeocoderResults(OSRM.SOURCE_MARKER_LABEL, response); } -function showReverseGeocoderResults_Target(response) { showReverseGeocoderResults(OSRM.TARGET_MARKER_LABEL, response); } +function showReverseGeocoderResults_Source(response) { showReverseGeocoderResults(OSRM.CONSTANTS.SOURCE_LABEL, response); } +function showReverseGeocoderResults_Target(response) { showReverseGeocoderResults(OSRM.CONSTANTS.TARGET_LABEL, response); } function showReverseGeocoderResults(marker_id, response) { //OSRM.debug.log("[inner] reverse geocoder"); if(response){ @@ -191,14 +190,14 @@ function showReverseGeocoderResults(marker_id, response) { if( address == "" ) return; - if(marker_id == OSRM.SOURCE_MARKER_LABEL) { + if(marker_id == OSRM.CONSTANTS.SOURCE_LABEL) { document.getElementById("input-source-name").value = address; - my_markers.route[0].dirty_move = false; - my_markers.route[0].dirty_type = false; - } else if(marker_id == OSRM.TARGET_MARKER_LABEL) { + OSRM.G.markers.route[0].dirty_move = false; + OSRM.G.markers.route[0].dirty_type = false; + } else if(marker_id == OSRM.CONSTANTS.TARGET_LABEL) { document.getElementById("input-target-name").value = address; - my_markers.route[my_markers.route.length-1].dirty_move = false; - my_markers.route[my_markers.route.length-1].dirty_type = false; + OSRM.G.markers.route[OSRM.G.markers.route.length-1].dirty_move = false; + OSRM.G.markers.route[OSRM.G.markers.route.length-1].dirty_type = false; } } diff --git a/WebContent/main.html b/WebContent/main.html index 8dc644f52..9866f1135 100644 --- a/WebContent/main.html +++ b/WebContent/main.html @@ -88,13 +88,13 @@ or see http://www.gnu.org/licenses/agpl.txt. - + - +
Start: Zeigen
Ende: Zeigen
@@ -112,7 +112,7 @@ or see http://www.gnu.org/licenses/agpl.txt.

Options
- Unbenannte Straßen hervorheben + Unbenannte Straßen hervorheben
diff --git a/WebContent/main.js b/WebContent/main.js index 58a8dda06..4a660a4f2 100644 --- a/WebContent/main.js +++ b/WebContent/main.js @@ -18,7 +18,8 @@ or see http://www.gnu.org/licenses/agpl.txt. // OSRM initialization // [initialization of maps, local strings, image prefetching] -var map; +// will hold the Leaflet map object +OSRM.GLOBALS.map = null; // onload initialization routine @@ -92,7 +93,7 @@ function initLocale() { // centering on geolocation function callbak_centerOnGeolocation( position ) { - map.setView( new L.LatLng( position.coords.latitude, position.coords.longitude-0.02), OSRM.DEFAULTS.ZOOM_LEVEL); + OSRM.G.map.setView( new L.LatLng( position.coords.latitude, position.coords.longitude-0.02), OSRM.DEFAULTS.ZOOM_LEVEL); } function centerOnGeolocation() { if (navigator.geolocation) @@ -125,7 +126,7 @@ function initMap() { cloudmade = new L.TileLayer(cloudmadeURL, cloudmadeOptions); // setup map - map = new L.Map('map', { + OSRM.G.map = new L.Map('map', { center: new L.LatLng(51.505, -0.09), zoom: 13, zoomAnimation: false, // false: removes animations and hiding of routes during zoom @@ -143,23 +144,23 @@ function initMap() { var overlayMaps = {}; var layersControl = new L.Control.Layers(baseMaps, overlayMaps); - map.addControl(layersControl); + OSRM.G.map.addControl(layersControl); // move zoom markers getElementsByClassName(document,'leaflet-control-zoom')[0].style.left="420px"; getElementsByClassName(document,'leaflet-control-zoom')[0].style.top="5px"; // initial map position and zoom - map.setView( new L.LatLng( OSRM.DEFAULTS.ONLOAD_LATITUDE, OSRM.DEFAULTS.ONLOAD_LONGITUDE), OSRM.DEFAULTS.ZOOM_LEVEL); - map.on('zoomend', function(e) { getRoute(OSRM.FULL_DESCRIPTION); }); - map.on('contextmenu', function(e) {}); + OSRM.G.map.setView( new L.LatLng( OSRM.DEFAULTS.ONLOAD_LATITUDE, OSRM.DEFAULTS.ONLOAD_LONGITUDE), OSRM.DEFAULTS.ZOOM_LEVEL); + OSRM.G.map.on('zoomend', function(e) { getRoute(OSRM.CONSTANTS.FULL_DESCRIPTION); }); + OSRM.G.map.on('contextmenu', function(e) {}); // click on map to set source and target nodes - map.on('click', function(e) { - if( !my_markers.hasSource() ) - onclickGeocoderResult("source", e.latlng.lat, e.latlng.lng, true, false ); - else if( !my_markers.hasTarget() ) - onclickGeocoderResult("target", e.latlng.lat, e.latlng.lng, true, false ); + OSRM.G.map.on('click', function(e) { + if( !OSRM.G.markers.hasSource() ) + onclickGeocoderResult(OSRM.CONSTANTS.SOURCE_LABEL, e.latlng.lat, e.latlng.lng, true, false ); + else if( !OSRM.G.markers.hasTarget() ) + onclickGeocoderResult(OSRM.CONSTANTS.TARGET_LABEL, e.latlng.lat, e.latlng.lng, true, false ); } ); } @@ -216,7 +217,7 @@ function checkURL(){ // case 1: destination given if( destination != undefined ) { - onclickGeocoderResult("target", destination.lat, destination.lng, (destination_name == undefined) ); + onclickGeocoderResult(OSRM.CONSTANTS.TARGET_LABEL, destination.lat, destination.lng, (destination_name == undefined) ); if( destination_name != undefined ) document.getElementById("input-target-name").value = destination_name; return; @@ -226,27 +227,27 @@ function checkURL(){ if( positions != []) { // draw via points if( positions.length > 0) { - onclickGeocoderResult("source", positions[0].lat, positions[0].lng, true, false ); - //my_markers.setSource( positions[0] ); + onclickGeocoderResult(OSRM.CONSTANTS.SOURCE_LABEL, positions[0].lat, positions[0].lng, true, false ); + //OSRM.G.markers.setSource( positions[0] ); } if(positions.length > 1) { - onclickGeocoderResult("target", positions[positions.length-1].lat, positions[positions.length-1].lng, true, false ); - //my_markers.setTarget( positions[positions.length-1] ); + onclickGeocoderResult(OSRM.CONSTANTS.TARGET_LABEL, positions[positions.length-1].lat, positions[positions.length-1].lng, true, false ); + //OSRM.G.markers.setTarget( positions[positions.length-1] ); } for(var i=1; i"; } @@ -69,9 +71,9 @@ function showRouteSimple(response) { updateHints(response); // // TODO: hack to process final drag event, if it was fenced, but we are still dragging (alternative approach) -// if(OSRM.pending) { -// clearTimeout(OSRM.pendingTimer); -// OSRM.pendingTimer = setTimeout(timeoutDrag,100); +// if(OSRM.GLOBALS.pending) { +// clearTimeout(OSRM.GLOBALS.pendingTimer); +// OSRM.GLOBALS.pendingTimer = setTimeout(timeoutDrag,100); // } } function showRoute(response) { @@ -80,7 +82,7 @@ function showRoute(response) { if(response.status == 207) { showNoRouteGeometry(); - my_route.hideUnnamedRoute(); + OSRM.G.route.hideUnnamedRoute(); showNoRouteDescription(); document.getElementById('information-box').innerHTML = "

"+OSRM.loc("NO_ROUTE_FOUND")+".

"; } else { @@ -96,13 +98,13 @@ function showRoute(response) { // show route geometry function showNoRouteGeometry() { var positions = []; - for(var i=0; i'+OSRM.loc("GET_LINK")+']'; @@ -228,7 +230,7 @@ function showNoRouteDescription() { function showRouteNonames(response) { // do not display unnamed streets? if( document.getElementById('option-highlight-nonames').checked == false) { - my_route.hideUnnamedRoute(); + OSRM.G.route.hideUnnamedRoute(); return; } @@ -262,7 +264,7 @@ function showRouteNonames(response) { } // display unnamed streets - my_route.showUnnamedRoute(all_positions); + OSRM.G.route.showUnnamedRoute(all_positions); } @@ -272,8 +274,8 @@ function showRouteNonames(response) { function getRoute(do_description) { // if source or target are not set -> hide route - if( my_markers.route.length < 2 ) { - my_route.hideRoute(); + if( OSRM.G.markers.route.length < 2 ) { + OSRM.G.route.hideRoute(); return; } @@ -283,13 +285,13 @@ function getRoute(do_description) { var timeout = undefined; var source = OSRM.DEFAULTS.HOST_ROUTING_URL; - source += '?z=' + map.getZoom() + '&output=json' + '&geomformat=cmp'; - if(my_markers.checksum) - source += '&checksum=' + my_markers.checksum; - for(var i=0; i 1){ - my_markers.route[0].label = OSRM.SOURCE_MARKER_LABEL; - my_markers.route[0].marker.setIcon( new L.Icon('images/marker-source.png') ); + } else if(OSRM.G.markers.route.length > 1){ + OSRM.G.markers.route[0].label = OSRM.CONSTANTS.SOURCE_LABEL; + OSRM.G.markers.route[0].marker.setIcon( new L.Icon('images/marker-source.png') ); - my_markers.route[my_markers.route.length-1].label = OSRM.TARGET_MARKER_LABEL; - my_markers.route[my_markers.route.length-1].marker.setIcon( new L.Icon('images/marker-target.png') ); + OSRM.G.markers.route[OSRM.G.markers.route.length-1].label = OSRM.CONSTANTS.TARGET_LABEL; + OSRM.G.markers.route[OSRM.G.markers.route.length-1].marker.setIcon( new L.Icon('images/marker-target.png') ); } // recompute route - if( my_route.isShown() ) { - getRoute(OSRM.FULL_DESCRIPTION); - my_markers.highlight.hide(); + if( OSRM.G.route.isShown() ) { + getRoute(OSRM.CONSTANTS.FULL_DESCRIPTION); + OSRM.G.markers.highlight.hide(); } else { document.getElementById('information-box').innerHTML = ""; document.getElementById('information-box-headline').innerHTML = ""; @@ -473,9 +475,9 @@ function reverseRouting() { // click: button "show" function centerMarker(marker_id) { - if( marker_id == OSRM.SOURCE_MARKER_LABEL && my_markers.hasSource() && !my_markers.route[0].dirty_type ) { - my_markers.route[0].centerView(); - } else if( marker_id == OSRM.TARGET_MARKER_LABEL && my_markers.hasTarget() && !my_markers.route[my_markers.route.length-1].dirty_type) { - my_markers.route[my_markers.route.length-1].centerView(); + if( marker_id == OSRM.CONSTANTS.SOURCE_LABEL && OSRM.G.markers.hasSource() && !OSRM.G.markers.route[0].dirty_type ) { + OSRM.G.markers.route[0].centerView(); + } else if( marker_id == OSRM.CONSTANTS.TARGET_LABEL && OSRM.G.markers.hasTarget() && !OSRM.G.markers.route[OSRM.G.markers.route.length-1].dirty_type) { + OSRM.G.markers.route[OSRM.G.markers.route.length-1].centerView(); } } diff --git a/WebContent/via.js b/WebContent/via.js index 1b9a3c8bc..ec106d82a 100644 --- a/WebContent/via.js +++ b/WebContent/via.js @@ -16,7 +16,7 @@ or see http://www.gnu.org/licenses/agpl.txt. */ // store location of via points returned by server -var via_points; +OSRM.GLOBALS.via_points = null; // find route segment of current route geometry that is closest to the new via node (marked by index of its endpoint) @@ -24,7 +24,7 @@ function findNearestRouteSegment( new_via ) { var min_dist = Number.MAX_VALUE; var min_index = undefined; - var positions = my_route.getPositions(); + var positions = OSRM.G.route.getPositions(); for(var i=0; i nearest_index) { new_via_index = i; break; @@ -54,10 +54,10 @@ function findViaPosition( new_via_position ) { } // add via node - var index = my_markers.setVia(new_via_index, new_via_position); - my_markers.route[index].show(); + var index = OSRM.G.markers.setVia(new_via_index, new_via_position); + OSRM.G.markers.route[index].show(); - getRoute(OSRM.FULL_DESCRIPTION); + getRoute(OSRM.CONSTANTS.FULL_DESCRIPTION); return new_via_index; } \ No newline at end of file