From f9877fd8ba43d1619db29c49956285371a1afeee Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Sat, 17 Mar 2012 17:04:45 +0100 Subject: [PATCH] refactoring: used hasSource, hasTarget routines throughout the code --- WebContent/OSRM.Markers.js | 2 +- WebContent/geocoder.js | 8 ++++---- WebContent/main.html | 4 ++-- WebContent/main.js | 6 ++---- WebContent/routing.js | 8 ++++---- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/WebContent/OSRM.Markers.js b/WebContent/OSRM.Markers.js index a4c42d8ed..d970241a3 100644 --- a/WebContent/OSRM.Markers.js +++ b/WebContent/OSRM.Markers.js @@ -228,4 +228,4 @@ hasTarget: function() { return true; return false; } -}); \ No newline at end of file +}); diff --git a/WebContent/geocoder.js b/WebContent/geocoder.js index a145524dd..a4b7ac453 100644 --- a/WebContent/geocoder.js +++ b/WebContent/geocoder.js @@ -37,9 +37,9 @@ function updateLocation(marker_id) { // process input request and call geocoder if needed function callGeocoder(marker_id, query) { - if (marker_id == OSRM.SOURCE_MARKER_LABEL && my_markers.route[0] && my_markers.route[0].label == OSRM.SOURCE_MARKER_LABEL && my_markers.route[0].dirty_move == false && my_markers.route[0].dirty_type == false) + if (marker_id == OSRM.SOURCE_MARKER_LABEL && my_markers.hasSource() && my_markers.route[0].dirty_move == false && my_markers.route[0].dirty_type == false) return; - if (marker_id == OSRM.TARGET_MARKER_LABEL && my_markers.route[my_markers.route.length-1] && my_markers.route[my_markers.route.length-1].label == OSRM.TARGET_MARKER_LABEL && 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.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) return; if(query=="") return; @@ -143,10 +143,10 @@ OSRM.REVERSE_GEOCODE_POST = 'http://nominatim.openstreetmap.org/reverse?format=j //update reverse geocoder informatiopn in input boxes function updateReverseGeocoder(marker_id) { - if (marker_id == OSRM.SOURCE_MARKER_LABEL && my_markers.hasSource()==true) { //&& my_markers.route[0].dirty == true ) { + 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()==true) { //&& my_markers.route[my_markers.route.length-1].dirty == true) { + } 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); } diff --git a/WebContent/main.html b/WebContent/main.html index 1c75fab32..8dc644f52 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
diff --git a/WebContent/main.js b/WebContent/main.js index d34aec005..58a8dda06 100644 --- a/WebContent/main.js +++ b/WebContent/main.js @@ -156,12 +156,10 @@ function initMap() { // click on map to set source and target nodes map.on('click', function(e) { - if( !my_markers.route[0] || my_markers.route[0].label != OSRM.SOURCE_MARKER_LABEL) { + if( !my_markers.hasSource() ) onclickGeocoderResult("source", e.latlng.lat, e.latlng.lng, true, false ); - } - else if( !my_markers.route[my_markers.route.length-1] || my_markers.route[ my_markers.route.length-1 ].label != OSRM.TARGET_MARKER_LABEL) { + else if( !my_markers.hasTarget() ) onclickGeocoderResult("target", e.latlng.lat, e.latlng.lng, true, false ); - } } ); } diff --git a/WebContent/routing.js b/WebContent/routing.js index bc2c534c4..9ea529232 100644 --- a/WebContent/routing.js +++ b/WebContent/routing.js @@ -379,9 +379,9 @@ function snapRoute() { // updateLocation( "source" ); // updateLocation( "target" ); - //if(OSRM.dragid == 0 && my_markers.hasSource()==true) + //if(OSRM.dragid == 0 && my_markers.hasSource()) updateReverseGeocoder("source"); - //else if(OSRM.dragid == my_markers.route.length-1 && my_markers.hasTarget()==true) + //else if(OSRM.dragid == my_markers.route.length-1 && my_markers.hasTarget()) updateReverseGeocoder("target"); } @@ -473,9 +473,9 @@ function reverseRouting() { // click: button "show" function centerMarker(marker_id) { - if( marker_id == OSRM.SOURCE_MARKER_LABEL && my_markers.route[0] && my_markers.route[0].label == OSRM.SOURCE_MARKER_LABEL && !my_markers.route[0].dirty_type ) { + 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.route[my_markers.route.length-1] && my_markers.route[my_markers.route.length-1].label == OSRM.TARGET_MARKER_LABEL && !my_markers.route[my_markers.route.length-1].dirty_type) { + } 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(); } }