changed sorting/filtering step of processing geocoder results:
relations are no longer skipped; boundaries are highest ranked; duplicate locations are removed
This commit is contained in:
parent
5498aa03a5
commit
4f28b2fe69
@ -74,20 +74,34 @@ _showResults: function(response, parameters) {
|
|||||||
OSRM.Geocoder._showResults_Empty(parameters);
|
OSRM.Geocoder._showResults_Empty(parameters);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(response.length == 0) {
|
if(response.length == 0) {
|
||||||
OSRM.Geocoder._showResults_Empty(parameters);
|
OSRM.Geocoder._showResults_Empty(parameters);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// filter/sort inputs
|
// filter/sort inputs
|
||||||
var filtered_response = [];
|
var filtered_response_temp = []; // filter unwanted results
|
||||||
for(var i=0; i < response.length; i++){
|
for(var i=0, iEnd=response.length; i < iEnd; i++){
|
||||||
var result = response[i];
|
var result = response[i];
|
||||||
if( OSRM.Geocoder._filterResult( result ) )
|
if( OSRM.Geocoder._filterResult( result ) )
|
||||||
continue;
|
continue;
|
||||||
|
filtered_response_temp.push( result );
|
||||||
|
}
|
||||||
|
if(filtered_response_temp.length == 0) { // stop if no results remain
|
||||||
|
OSRM.Geocoder._showResults_Empty(parameters);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
filtered_response_temp.sort( OSRM.Geocoder._compareResults ); // sort results
|
||||||
|
filtered_response_temp.sort( OSRM.Geocoder._compareLocations ); // remove duplicate locations (stable sort -> retain highest ranked)
|
||||||
|
var filtered_response = [];
|
||||||
|
filtered_response.push( filtered_response_temp[0] );
|
||||||
|
for(var i=filtered_response_temp.length-1, iEnd = 0; i>iEnd; i--) {
|
||||||
|
var prev_result = response[i-1];
|
||||||
|
var result = response[i];
|
||||||
|
if( result.lat != prev_result.lat || result.lon != prev_result.lon ) {
|
||||||
filtered_response.push( result );
|
filtered_response.push( result );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
filtered_response.sort( OSRM.Geocoder._compareResults );
|
filtered_response.sort( OSRM.Geocoder._compareResults );
|
||||||
|
|
||||||
// show first result
|
// show first result
|
||||||
@ -148,8 +162,8 @@ _showResults_Timeout: function() {
|
|||||||
|
|
||||||
// filter search results [true: result will not be displayed]
|
// filter search results [true: result will not be displayed]
|
||||||
_filterResult: function(result) {
|
_filterResult: function(result) {
|
||||||
if( result.osm_type == "relation")
|
// if( result.osm_type == "relation")
|
||||||
return true;
|
// return true;
|
||||||
if( result.type == "aerial_views")
|
if( result.type == "aerial_views")
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
@ -158,9 +172,9 @@ _filterResult: function(result) {
|
|||||||
|
|
||||||
// comparator for sorting results [higher weight: result will appear first]
|
// comparator for sorting results [higher weight: result will appear first]
|
||||||
_compare_class_weights: {
|
_compare_class_weights: {
|
||||||
place: 9000,
|
boundary: 9000,
|
||||||
highway: 8000,
|
place: 8000,
|
||||||
boundary: 7000
|
highway: 7000,
|
||||||
},
|
},
|
||||||
_compare_type_weights: {
|
_compare_type_weights: {
|
||||||
country: 13,
|
country: 13,
|
||||||
@ -185,6 +199,15 @@ _compareResults: function(lhs, rhs) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
// comparator for sorting objects according to their locations
|
||||||
|
_compareLocations: function(lhs, rhs) {
|
||||||
|
if( lhs.lat != rhs.lat )
|
||||||
|
return lhs.lat < rhs.lat;
|
||||||
|
else
|
||||||
|
return lhs.lon < rhs.lon;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
// [reverse geocoding]
|
// [reverse geocoding]
|
||||||
|
|
||||||
//update geo coordinates in input boxes
|
//update geo coordinates in input boxes
|
||||||
|
Loading…
Reference in New Issue
Block a user