Merge branch 'trial/geocoder' into develop
This commit is contained in:
commit
a90b2371c2
@ -43,7 +43,7 @@ call: function(marker_id, query) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// build basic request for geocoder
|
// 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
|
// prioritize results in currently shown mapview
|
||||||
var bounds = OSRM.G.map.getBounds();
|
var bounds = OSRM.G.map.getBounds();
|
||||||
call += "&viewbox=" + bounds._southWest.lat + "," + bounds._northEast.lng + "," + bounds._northEast.lat + "," + bounds._southWest.lng;
|
call += "&viewbox=" + bounds._southWest.lat + "," + bounds._northEast.lng + "," + bounds._northEast.lat + "," + bounds._southWest.lng;
|
||||||
@ -80,27 +80,42 @@ _showResults: function(response, parameters) {
|
|||||||
return;
|
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 first result
|
// show first result
|
||||||
OSRM.Geocoder._onclickResult(parameters.marker_id, response[0].lat, response[0].lon);
|
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
|
if( OSRM.G.markers.route.length > 1 ) // if a route is displayed, we don't need to show other possible geocoding results
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// show possible results for input
|
// show possible results for input
|
||||||
var html = "";
|
var html = "";
|
||||||
html += '<table class="results medium-font">';
|
html += '<table class="results medium-font">';
|
||||||
for(var i=0; i < response.length; i++){
|
for(var i=0; i < filtered_response.length; i++){
|
||||||
var result = response[i];
|
var result = filtered_response[i];
|
||||||
|
|
||||||
//odd or even ?
|
//odd or even ?
|
||||||
var rowstyle='results-body-odd';
|
var rowstyle='results-body-odd';
|
||||||
if(i%2==0) { rowstyle='results-body-even'; }
|
if(i%2==0) { rowstyle='results-body-even'; }
|
||||||
|
|
||||||
html += '<tr class="'+rowstyle+'">';
|
html += '<tr class="'+rowstyle+'">';
|
||||||
html += '<td class="results-body-counter"><span">'+(i+1)+'.</span></td>';
|
if(!result.icon)
|
||||||
|
result.icon = "http://nominatim.openstreetmap.org/images/mapicons/poi_point_of_interest.glow.12.png";
|
||||||
|
html += '<td class="results-body-counter"><img src="'+ result.icon + '" alt=""/></td>';
|
||||||
html += '<td class="results-body-items">';
|
html += '<td class="results-body-items">';
|
||||||
|
|
||||||
if(result.display_name){
|
if(result.display_name){
|
||||||
html += '<div class="results-body-item" onclick="OSRM.Geocoder._onclickResult(\''+parameters.marker_id+'\', '+result.lat+', '+result.lon+');">'+result.display_name+'</div>';
|
html += '<div class="results-body-item" onclick="OSRM.Geocoder._onclickResult(\''+parameters.marker_id+'\', '+result.lat+', '+result.lon+');">'+result.display_name;
|
||||||
|
// debug output to show osm_type, class, type
|
||||||
|
// html += '<br/><span class="results-body-item-remark small-font">[osm_type: ' + result.osm_type + ', class: ' + result.class + ', type: ' + result.type + ']</span>';
|
||||||
|
html += '</div>';
|
||||||
}
|
}
|
||||||
html += "</td></tr>";
|
html += "</td></tr>";
|
||||||
}
|
}
|
||||||
@ -108,8 +123,8 @@ _showResults: function(response, parameters) {
|
|||||||
|
|
||||||
document.getElementById('information-box-header').innerHTML =
|
document.getElementById('information-box-header').innerHTML =
|
||||||
"<div class='header-title'>"+OSRM.loc("SEARCH_RESULTS")+"</div>" +
|
"<div class='header-title'>"+OSRM.loc("SEARCH_RESULTS")+"</div>" +
|
||||||
"<div class='header-content'>("+OSRM.loc("FOUND_X_RESULTS").replace(/%i/,response.length)+")</div>";
|
"<div class='header-content'>("+OSRM.loc("FOUND_X_RESULTS").replace(/%i/,filtered_response.length)+")</div>";
|
||||||
"<div class='header-content'>(found "+response.length+" results)"+"</div>";
|
"<div class='header-content'>(found "+filtered_response.length+" results)"+"</div>";
|
||||||
document.getElementById('information-box').innerHTML = html;
|
document.getElementById('information-box').innerHTML = html;
|
||||||
},
|
},
|
||||||
_showResults_Empty: function(parameters) {
|
_showResults_Empty: function(parameters) {
|
||||||
@ -131,6 +146,45 @@ _showResults_Timeout: function() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
// filter search results [true: result will not be displayed]
|
||||||
|
_filterResult: function(result) {
|
||||||
|
if( result.osm_type == "relation")
|
||||||
|
return true;
|
||||||
|
if( result.type == "aerial_views")
|
||||||
|
return true;
|
||||||
|
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);
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
// [reverse geocoding]
|
// [reverse geocoding]
|
||||||
|
|
||||||
//update geo coordinates in input boxes
|
//update geo coordinates in input boxes
|
||||||
|
@ -327,14 +327,14 @@ html, body {
|
|||||||
.results-body-counter
|
.results-body-counter
|
||||||
{
|
{
|
||||||
text-align:right;
|
text-align:right;
|
||||||
vertical-align:top;
|
vertical-align:middle;
|
||||||
font-weight:bold;
|
font-weight:bold;
|
||||||
padding:1px 5px 1px 5px;
|
padding:1px 5px 1px 5px;
|
||||||
}
|
}
|
||||||
.results-body-items
|
.results-body-items
|
||||||
{
|
{
|
||||||
text-align:left;
|
text-align:left;
|
||||||
vertical-align: middle;
|
vertical-align:top;
|
||||||
width:100%;
|
width:100%;
|
||||||
padding:1px;
|
padding:1px;
|
||||||
}
|
}
|
||||||
@ -347,6 +347,10 @@ html, body {
|
|||||||
{
|
{
|
||||||
color:#ff0000
|
color:#ff0000
|
||||||
}
|
}
|
||||||
|
.results-body-item-remark
|
||||||
|
{
|
||||||
|
color:#999999
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* style for main-output information-box -> table (driving directions) */
|
/* style for main-output information-box -> table (driving directions) */
|
||||||
|
Loading…
Reference in New Issue
Block a user