From 2ad919c9708f1ac8b61a959391a21da5c53eebcc Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Wed, 13 Jun 2012 10:29:30 +0100 Subject: [PATCH 1/5] added geocoder filtering and using Nominatim icons --- WebContent/base/OSRM.Geocoder.js | 66 ++++++++++++++++++++++++++++---- WebContent/main.css | 6 ++- 2 files changed, 64 insertions(+), 8 deletions(-) diff --git a/WebContent/base/OSRM.Geocoder.js b/WebContent/base/OSRM.Geocoder.js index 45c2659c5..e3353aaab 100644 --- a/WebContent/base/OSRM.Geocoder.js +++ b/WebContent/base/OSRM.Geocoder.js @@ -85,22 +85,39 @@ _showResults: function(response, parameters) { if( OSRM.G.markers.route.length > 1 ) // if a route is displayed, we don't need to show other possible geocoding results return; + // filter/sort inputs + var filtered_response = []; + for(var i=0; i < response.length; i++){ + var result = response[i]; + if( OSRM.Geocoder._filterResult( result ) ) + continue; + filtered_response.push( result ); + } + filtered_response.sort( OSRM.Geocoder._compareResults ); + // show possible results for input var html = ""; html += ''; - for(var i=0; i < response.length; i++){ - var result = response[i]; - + for(var i=0; i < filtered_response.length; i++){ + var result = filtered_response[i]; + //odd or even ? var rowstyle='results-body-odd'; if(i%2==0) { rowstyle='results-body-even'; } html += ''; - html += ''; +// html += ''; + // optimally show Nominatim icons instead of numbers + if(!result.icon) + result.icon = "http://nominatim.openstreetmap.org/images/mapicons/poi_point_of_interest.glow.12.png"; + html += ''; html += '"; } @@ -108,8 +125,8 @@ _showResults: function(response, parameters) { document.getElementById('information-box-header').innerHTML = "
"+OSRM.loc("SEARCH_RESULTS")+"
" + - "
("+OSRM.loc("FOUND_X_RESULTS").replace(/%i/,response.length)+")
"; - "
(found "+response.length+" results)"+"
"; + "
("+OSRM.loc("FOUND_X_RESULTS").replace(/%i/,filtered_response.length)+")
"; + "
(found "+filtered_response.length+" results)"+"
"; document.getElementById('information-box').innerHTML = html; }, _showResults_Empty: function(parameters) { @@ -128,6 +145,41 @@ _showResults_Timeout: function() { "
"+OSRM.loc("SEARCH_RESULTS")+"
" + "
("+OSRM.loc("FOUND_X_RESULTS").replace(/%i/,0)+")
"; document.getElementById('information-box').innerHTML = "
"+OSRM.loc("TIMED_OUT")+"
"; +}, + + +// filter search results [false: result will not be displayed] +_filterResult: function(result) { + return false; +}, + + +// comparator for sorting results [higher weight: result will appear first] +_compare_class_weights: { + place: 9000, + highway: 8000, + boundary: 7000 +}, +_compare_type_weights: { + country: 13, + state: 12, + county: 11, + city: 10, + town: 9, + village: 8, + hamlet: 7, + suburb: 6, + locality: 5, + farm: 4 +}, +_compareResults: function(lhs, rhs) { + var class_values = OSRM.Geocoder._compare_class_weights; + var type_values = OSRM.Geocoder._compare_type_weights; + + var lhs_value = (-class_values[ lhs.class ] || 0) + (-type_values[ lhs.type ] || 0); + var rhs_value = (-class_values[ rhs.class ] || 0) + (-type_values[ rhs.type ] || 0); + + return (lhs_value - rhs_value); }, diff --git a/WebContent/main.css b/WebContent/main.css index 2b61e5071..5ecc05738 100644 --- a/WebContent/main.css +++ b/WebContent/main.css @@ -347,6 +347,10 @@ html, body { { color:#ff0000 } +.results-body-item-remark +{ + color:#999999 +} /* style for main-output information-box -> table (driving directions) */ @@ -666,5 +670,5 @@ input[type=checkbox], .small-font { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 9px; - font-weight: normal; + font-weight: normal; } \ No newline at end of file From f575ff2ba57be83ecd36b643df5f851ef6210057 Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Wed, 4 Jul 2012 13:58:06 +0100 Subject: [PATCH 2/5] increased limit on search results --- WebContent/base/OSRM.Geocoder.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/WebContent/base/OSRM.Geocoder.js b/WebContent/base/OSRM.Geocoder.js index e3353aaab..7671da521 100644 --- a/WebContent/base/OSRM.Geocoder.js +++ b/WebContent/base/OSRM.Geocoder.js @@ -43,7 +43,7 @@ call: function(marker_id, query) { } // build basic request for geocoder - var call = OSRM.DEFAULTS.HOST_GEOCODER_URL + "?format=json&json_callback=%jsonp" + OSRM.DEFAULTS.GEOCODER_BOUNDS + "&accept-language="+OSRM.Localization.current_language+"&q=" + query; + var call = OSRM.DEFAULTS.HOST_GEOCODER_URL + "?format=json&json_callback=%jsonp" + OSRM.DEFAULTS.GEOCODER_BOUNDS + "&accept-language="+OSRM.Localization.current_language+"&limit=30&q=" + query; // prioritize results in currently shown mapview var bounds = OSRM.G.map.getBounds(); call += "&viewbox=" + bounds._southWest.lat + "," + bounds._northEast.lng + "," + bounds._northEast.lat + "," + bounds._southWest.lng; @@ -79,6 +79,8 @@ _showResults: function(response, parameters) { OSRM.Geocoder._showResults_Empty(parameters); return; } + console.log(response.length); + console.log(response); // show first result OSRM.Geocoder._onclickResult(parameters.marker_id, response[0].lat, response[0].lon); From 60436e9928ac27050b175f416d8acb66f89825f2 Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Wed, 4 Jul 2012 14:07:31 +0100 Subject: [PATCH 3/5] filter boundaries --- WebContent/base/OSRM.Geocoder.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/WebContent/base/OSRM.Geocoder.js b/WebContent/base/OSRM.Geocoder.js index 7671da521..810edc415 100644 --- a/WebContent/base/OSRM.Geocoder.js +++ b/WebContent/base/OSRM.Geocoder.js @@ -79,13 +79,6 @@ _showResults: function(response, parameters) { OSRM.Geocoder._showResults_Empty(parameters); return; } - console.log(response.length); - console.log(response); - - // show first result - OSRM.Geocoder._onclickResult(parameters.marker_id, response[0].lat, response[0].lon); - if( OSRM.G.markers.route.length > 1 ) // if a route is displayed, we don't need to show other possible geocoding results - return; // filter/sort inputs var filtered_response = []; @@ -97,6 +90,11 @@ _showResults: function(response, parameters) { } filtered_response.sort( OSRM.Geocoder._compareResults ); + // show first result + OSRM.Geocoder._onclickResult(parameters.marker_id, filtered_response[0].lat, filtered_response[0].lon); + if( OSRM.G.markers.route.length > 1 ) // if a route is displayed, we don't need to show other possible geocoding results + return; + // show possible results for input var html = ""; html += '
'+(i+1)+'.'+(i+1)+'.'; if(result.display_name){ - html += '
'+result.display_name+'
'; + html += '
'+result.display_name; + // optionally show osm_type, class, type + html += '
[osm_type: ' + result.osm_type + ', class: ' + result.class + ', type: ' + result.type + ']'; + html += '
'; } html += "
'; @@ -150,8 +148,10 @@ _showResults_Timeout: function() { }, -// filter search results [false: result will not be displayed] +// filter search results [true: result will not be displayed] _filterResult: function(result) { + if( result.osm_type == "relation") + return true; return false; }, From 314ff97ca01fc9e1ee1ff1d389ac3f5e11d18727 Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Wed, 4 Jul 2012 15:42:20 +0100 Subject: [PATCH 4/5] nominatim results with type "arial_views" will not be displayed --- WebContent/base/OSRM.Geocoder.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/WebContent/base/OSRM.Geocoder.js b/WebContent/base/OSRM.Geocoder.js index 810edc415..66ab2a856 100644 --- a/WebContent/base/OSRM.Geocoder.js +++ b/WebContent/base/OSRM.Geocoder.js @@ -152,6 +152,8 @@ _showResults_Timeout: function() { _filterResult: function(result) { if( result.osm_type == "relation") return true; + if( result.type == "aerial_views") + return true; return false; }, From 052f7060c172e6c3cf05081c41fb3456edf289e6 Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Wed, 4 Jul 2012 16:15:04 +0100 Subject: [PATCH 5/5] changed look of geocoder results a bit (vertical alignment, debug messages) --- WebContent/base/OSRM.Geocoder.js | 6 ++---- WebContent/main.css | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/WebContent/base/OSRM.Geocoder.js b/WebContent/base/OSRM.Geocoder.js index 66ab2a856..183c0b5ce 100644 --- a/WebContent/base/OSRM.Geocoder.js +++ b/WebContent/base/OSRM.Geocoder.js @@ -106,8 +106,6 @@ _showResults: function(response, parameters) { if(i%2==0) { rowstyle='results-body-even'; } html += ''; -// html += ''; - // optimally show Nominatim icons instead of numbers if(!result.icon) result.icon = "http://nominatim.openstreetmap.org/images/mapicons/poi_point_of_interest.glow.12.png"; html += ''; @@ -115,8 +113,8 @@ _showResults: function(response, parameters) { if(result.display_name){ html += '
'+result.display_name; - // optionally show osm_type, class, type - html += '
[osm_type: ' + result.osm_type + ', class: ' + result.class + ', type: ' + result.type + ']'; + // debug output to show osm_type, class, type + // html += '
[osm_type: ' + result.osm_type + ', class: ' + result.class + ', type: ' + result.type + ']'; html += '
'; } html += ""; diff --git a/WebContent/main.css b/WebContent/main.css index 5ecc05738..ad328ec83 100644 --- a/WebContent/main.css +++ b/WebContent/main.css @@ -327,14 +327,14 @@ html, body { .results-body-counter { text-align:right; - vertical-align:top; + vertical-align:middle; font-weight:bold; padding:1px 5px 1px 5px; } .results-body-items { text-align:left; - vertical-align: middle; + vertical-align:top; width:100%; padding:1px; }
'+(i+1)+'.