From 26c9d357f0761788ad766494f54e91f8c09b6588 Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Fri, 16 Mar 2012 07:22:47 +0100 Subject: [PATCH] made reverse geocoding more intuitive, changed search and route buttons to centering buttons --- WebContent/OSRM.Markers.js | 5 +++-- WebContent/geocoder.js | 28 ++++++++++++++++------------ WebContent/main.html | 10 +++++----- WebContent/main.js | 26 ++++++++++++++------------ WebContent/routing.js | 17 +++++++++++++++++ 5 files changed, 55 insertions(+), 31 deletions(-) diff --git a/WebContent/OSRM.Markers.js b/WebContent/OSRM.Markers.js index 96bb97f3d..770cc008f 100644 --- a/WebContent/OSRM.Markers.js +++ b/WebContent/OSRM.Markers.js @@ -26,7 +26,8 @@ OSRM.Marker = function( label, style, position ) { this.marker = new L.MouseMarker( this.position, style ); this.marker.parent = this; - this.dirty = true; + this.dirty_move = true; + this.dirty_type = true; this.shown = false; this.hint = undefined; @@ -107,7 +108,7 @@ onClick: function(e) { my_markers.highlight.hide(); }, onDrag: function(e) { - this.parent.dirty = true; + this.parent.dirty_move = true; this.parent.setPosition( e.target.getLatLng() ); if(OSRM.dragging == true) // TODO: hack that deals with drag events after dragend event getRoute(OSRM.NO_DESCRIPTION); diff --git a/WebContent/geocoder.js b/WebContent/geocoder.js index 4e2135645..47fdd7242 100644 --- a/WebContent/geocoder.js +++ b/WebContent/geocoder.js @@ -27,9 +27,9 @@ OSRM.TARGET_MARKER_LABEL = "target"; // update geo coordinates in input boxes function updateLocation(marker_id) { - if (marker_id == OSRM.SOURCE_MARKER_LABEL && my_markers.route[0].dirty == true ) { + 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 == true) { + } 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); } } @@ -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 == false) + 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) 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 == false) + 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) return; //geo coordinates given -> go directly to drawing results @@ -61,7 +61,7 @@ function callGeocoder(marker_id, query) { // helper function for clicks on geocoder search results -function onclickGeocoderResult(marker_id, lat, lon, do_reverse_geocode ) { +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) ); @@ -72,12 +72,16 @@ function onclickGeocoderResult(marker_id, lat, lon, do_reverse_geocode ) { if( do_reverse_geocode == true ) updateReverseGeocoder(marker_id); - else - my_markers.route[index].dirty = false; + if( zoom == undefined ) + zoom = true; my_markers.route[index].show(); - my_markers.route[index].centerView(); + if( !my_markers.route[index].dirty_move || my_markers.route[index].dirty_type ) + my_markers.route[index].centerView(zoom); getRoute(OSRM.FULL_DESCRIPTION); + + my_markers.route[index].dirty_move = false; + my_markers.route[index].dirty_type = false; } // process JSONP response of geocoder @@ -137,10 +141,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.route[0].dirty == true ) { + if (marker_id == OSRM.SOURCE_MARKER_LABEL ) { //&& 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.route[my_markers.route.length-1].dirty == true) { + } else if (marker_id == OSRM.TARGET_MARKER_LABEL ) { //&& 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); } @@ -181,10 +185,10 @@ function showReverseGeocoderResults(marker_id, response) { if(marker_id == OSRM.SOURCE_MARKER_LABEL) { document.getElementById("input-source-name").value = address; - my_markers.route[0].dirty = false; + //my_markers.route[0].dirty = false; } else if(marker_id == OSRM.TARGET_MARKER_LABEL) { document.getElementById("input-target-name").value = address; - my_markers.route[my_markers.route.length-1].dirty = false; + //my_markers.route[my_markers.route.length-1].dirty = false; } } diff --git a/WebContent/main.html b/WebContent/main.html index b36c56cb3..9ae0b600c 100644 --- a/WebContent/main.html +++ b/WebContent/main.html @@ -88,18 +88,18 @@ or see http://www.gnu.org/licenses/agpl.txt. - + - + - + - +
Start: SuchenSuchen
Ende: SuchenSuchen
@@ -112,7 +112,7 @@ or see http://www.gnu.org/licenses/agpl.txt. Reverse Route --> - Reverse + Reverse diff --git a/WebContent/main.js b/WebContent/main.js index 1ac7f3101..7949f40fa 100644 --- a/WebContent/main.js +++ b/WebContent/main.js @@ -152,20 +152,22 @@ 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) { - index = my_markers.setSource( e.latlng ); - my_markers.route[index].show(); - my_markers.route[index].centerView(false); - getRoute(OSRM.FULL_DESCRIPTION); - updateLocation("source"); - updateReverseGeocoder("source"); +// index = my_markers.setSource( e.latlng ); +// my_markers.route[index].show(); +// my_markers.route[index].centerView(false); +// getRoute(OSRM.FULL_DESCRIPTION); +// updateLocation("source"); +// updateReverseGeocoder("source"); + 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) { - index = my_markers.setTarget( e.latlng ); - my_markers.route[index].show(); - my_markers.route[index].centerView(false); - getRoute(OSRM.FULL_DESCRIPTION); - updateLocation("target"); - updateReverseGeocoder("target"); +// index = my_markers.setTarget( e.latlng ); +// my_markers.route[index].show(); +// my_markers.route[index].centerView(false); +// getRoute(OSRM.FULL_DESCRIPTION); +// updateLocation("target"); +// updateReverseGeocoder("target"); + onclickGeocoderResult("target", e.latlng.lat, e.latlng.lng, true, false ); } } ); } diff --git a/WebContent/routing.js b/WebContent/routing.js index 0cf5707cb..12b36eb7a 100644 --- a/WebContent/routing.js +++ b/WebContent/routing.js @@ -470,3 +470,20 @@ function reverseRouting() { getRoute(OSRM.FULL_DESCRIPTION); my_markers.highlight.hide(); } + + +// click: button "search" +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 ) { + 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) { + my_markers.route[my_markers.route.length-1].centerView(); + } +} + + +// click: button "route" +function centerRoute() { + if( my_route.isShown() ) + my_route.centerView(); +} \ No newline at end of file