Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverse geocoding and minor fixes #48

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/Control.NominatimGeocoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ L.Control.NominatimGeocoder = L.Control.extend({
options: {
collapsed: true,
position: 'topright',
text: 'Locate',
text: lang_locate,
callback: function (results) {
// Check if no results are returned
if (results.length >= 1) {
Expand Down
6 changes: 4 additions & 2 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,12 @@ var zoomControl = L.control.zoom({
map.on('locationerror', onLocationError);

map.on('moveend', nominatimQuery);
map.on('popupopen', function() {
map.on('popupopen', function(e) {
var href=$("#plusone-div").data("href");
var size=$("#plusone-div").data("size");
gapi.plusone.render("plusone-div",{'size':size,'href':href});
//gapi.plusone.render("plusone-div",{'size':size,'href':href});
// we make sure that a proper address is displayed
e.popup._source.el.fetchAddress();
});
n=true;
var href=$("#main-plus").data("href");
Expand Down
61 changes: 55 additions & 6 deletions js/poi.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,21 @@ POI.prototype.getInfoBox = function(){
content+='<div class="tab-pane active container" id="basic" style="margin:0px;width:400px">';

//name
content+='<h4><a href=\'http://osm24.eu/index.php?id='+this.element.id+'#!18/'+this.element.lat+'/'+this.element.lon+'/\'>' +((this.element.tags.hasOwnProperty("name")) ? this.element.tags["name"]:"----")+'</a> <div id="plusone-div" data-size="small" data-href=\'http://osm24.eu/index.php?id='+this.element.id+'#!18/'+this.element.lat+'/'+this.element.lon+'/\'></div></h4>';
content+='<h4><a href=\'http://osm24.eu/index.php?id='+this.element.id+'#!18/'+this.element.lat+'/'+this.element.lon+'/\'>' +(this.getName()?this.getName():"---")+'</a> <div id="plusone-div" data-size="small" data-href=\'http://osm24.eu/index.php?id='+this.element.id+'#!18/'+this.element.lat+'/'+this.element.lon+'/\'></div></h4>';
//addr
content+='<small>'+((this.element.tags.hasOwnProperty("addr:city")) ? this.element.tags["addr:city"]+', ' : "")+((this.element.tags.hasOwnProperty("addr:street")) ? this.element.tags["addr:street"]+', ' : "")+((this.element.tags.hasOwnProperty("addr:housenumber")) ? this.element.tags["addr:housenumber"]+', ' : "")+'</small>';

if(this.element.tags.hasOwnProperty("addr:housenumber") && this.element.tags.hasOwnProperty("addr:street"))
content+='<small>'+((this.element.tags.hasOwnProperty("addr:city")) ? this.element.tags["addr:city"]+', ' : "")+this.element.tags["addr:street"]+', ' +this.element.tags["addr:housenumber"]+'</small>';
else
content+='<div id="'+this.element.type+this.element.id+'">'+lang_loading+'</div>';
//net
content+='<div>';
content += this.__genItems({tag:['contact:email','email'],icon:'glyphicon glyphicon-envelope',href:'mailto:'});
content += this.__genItems({tag:['contact:phone','phone'],icon:'glyphicon glyphicon-phone-alt',href:'tel:'});
content += this.__genItems({tag:['contact:website','website'],icon:'glyphicon glyphicon-globe',href:''});
content += this.__genItems({tag:['contact:website','website'],icon:'glyphicon glyphicon-globe',href:'',
hrefFunc:function(nn){
// some website values have no protocol indication, resulting in a misintrepretation of the URL (eg. http://osm24.eu/www.jeudepaume.org)
return (nn.indexOf('http://') == -1 && nn.indexOf('https://') == -1)?'http://'+nn:nn;
}});

content += this.__genItems({tag:['contact:facebook'],icon:'glyphicon glyphicon-globe',name:"Facebook",href:'',hrefFunc:
function(nn){return ((nn.indexOf('/') === -1)?"http://facebook.com/":"")+nn;}});
Expand Down Expand Up @@ -191,9 +197,9 @@ POI.prototype.getInfoBox = function(){

content+='</tbody></table>';
if(this.element.id[0]!='w')
content+="<a href='http://www.openstreetmap.org/node/"+this.element.id+"' target='_blank'>Open OSM</a>";
content+="<a href='http://www.openstreetmap.org/node/"+this.element.id+"' target='_blank'>"+lang_open_osm+"</a>";
else
content+="<a href='http://www.openstreetmap.org/way/"+this.element.id.substr(1)+"' target='_blank'>Open OSM</a>";
content+="<a href='http://www.openstreetmap.org/way/"+this.element.id.substr(1)+"' target='_blank'>"+lang_open_osm+"</a>";

content+='</div>';

Expand Down Expand Up @@ -284,3 +290,46 @@ POI.prototype.updateShadow = function (now){
return false;
return true;
};

/*
Determine the address of a POI, if it is unknown
*/
POI.prototype.fetchAddress = function(){
var typeTable = {"node":"N","way":"W","relation":"R"};
var addressDiv = this.element.type+this.element.id;
// if the address has not been determined yet
if($("#"+addressDiv).html() == lang_loading)
{
var requestData;
if(this.element.tags.hasOwnProperty("addr:housenumber"))
{
if(this.element.type)
requestData = {osm_type:typeTable[this.element.type],osm_id:this.element.id};
else
// way objects have no key type, no idea why
requestData = {osm_type:this.element.id[0].toUpperCase(),osm_id:this.element.id.substr(1)};
}
else
requestData = {lon:this.element.lon,lat:this.element.lat};

$.ajax({
url: 'nominatim_reverse_proxy.php',
dataType: "json",
data: requestData,
number : this.element.tags["addr:housenumber"],
addressDiv : addressDiv,
success: function(nominatim){
var wayName = nominatim.address.road;
if(!wayName)wayName = nominatim.address.pedestrian;
if(!wayName)wayName = nominatim.address.footway;
var cityName = nominatim.address.city;
if(!cityName)cityName = nominatim.address.town;
if(!cityName)cityName = nominatim.address.village;
var displayedAddress = cityName?cityName:"";
displayedAddress += (wayName?", "+wayName:"");
displayedAddress += (this.number?", "+this.number:"");
$("#"+this.addressDiv).html('<small>'+displayedAddress+'</small>');
}
});
}
};
1 change: 1 addition & 0 deletions js_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
var lang_loading='<?php echo addslashes(JS_LOADING);?>';
var lang_please_zoom_in='<?php echo addslashes(JS_PLEASE_ZOOM_IN);?>';
var lang_open='<?php echo addslashes(JS_OPEN);?>';
var lang_open_osm='<?php echo addslashes(JS_OPEN_OSM);?>';
var lang_last_hour='<?php echo addslashes(JS_LAST_HOUR);?>';
var lang_close='<?php echo addslashes(JS_CLOSE);?>';
var lang_nodata='<?php echo addslashes(JS_NO_DATA);?>';
Expand Down
1 change: 1 addition & 0 deletions lang/de_DE.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@
define('JS_LOADING','Lade...');
define('JS_PLEASE_ZOOM_IN','Bitte hineinzoomen');
define('JS_OPEN','Offen');
define('JS_OPEN_OSM','Open in OSM');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Öffnen in OSM" ;)

define('JS_LAST_HOUR','Letzte Stunde');
define('JS_CLOSE','Geschlossen');
define('JS_NO_DATA','Keine Daten');
Expand Down
1 change: 1 addition & 0 deletions lang/en_EN.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@
define('JS_LOADING','Loading...');
define('JS_PLEASE_ZOOM_IN','Please zoom in');
define('JS_OPEN','Open');
define('JS_OPEN_OSM','Open in OSM');
define('JS_LAST_HOUR','Last hour');
define('JS_CLOSE','Closed');
define('JS_NO_DATA','No data');
Expand Down
3 changes: 2 additions & 1 deletion lang/fr_FR.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
define('PANEL_STORE_ART','Art');
define('PANEL_STORE_CLOTHES','Vêtements');
define('PANEL_STORE_FOOD','Alimentation');
define('PANEL_STORE_ORGANIC','Organic');
define('PANEL_STORE_ORGANIC','Bio');
define('PANEL_STORE_ELECTRONIC','Électronique');
define('PANEL_STORE_HEALTH_AND_BEAUTY','Soins et beauté');
define('PANEL_STORE_TRANSPORT','Transport');
Expand Down Expand Up @@ -349,6 +349,7 @@
define('JS_LOADING','Chargement...');
define('JS_PLEASE_ZOOM_IN','Zoomez pour voir les points d\'intérêt');
define('JS_OPEN','Ouvert');
define('JS_OPEN_OSM','Ouvrir dans OpenStreetMap');
define('JS_LAST_HOUR','Moins d\'une heure');
define('JS_CLOSE','Fermé');
define('JS_NO_DATA','Inconnu');
Expand Down
1 change: 1 addition & 0 deletions lang/it_IT.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@
define('JS_LOADING','Loading...');
define('JS_PLEASE_ZOOM_IN','Please zoom in');
define('JS_OPEN','Open');
define('JS_OPEN_OSM','Open in OSM');
define('JS_LAST_HOUR','Last hour');
define('JS_CLOSE','Closed');
define('JS_NO_DATA','No data');
Expand Down
1 change: 1 addition & 0 deletions lang/ru_RU.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@
define('JS_LOADING','Идет загрузка...');
define('JS_PLEASE_ZOOM_IN','Приблизьте карту, чтобы увидеть объекты');
define('JS_OPEN','Открыто');
define('JS_OPEN_OSM','Open in OSM');
define('JS_LAST_HOUR','Последний час');
define('JS_CLOSE','Закрыто');
define('JS_NO_DATA','Нет данных');
Expand Down
1 change: 1 addition & 0 deletions lang/uk_UA.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@
define ('JS_LOADING', 'Йде завантаження…');
define ('JS_PLEASE_ZOOM_IN', 'Наблизьте мапу, щоб побачити об’єкти');
define ('JS_OPEN', 'Відкрито');
define('JS_OPEN_OSM','Open in OSM');
define ('JS_LAST_HOUR', 'Остання година');
define ('JS_CLOSE', 'Зачинено');
define ('JS_NO_DATA', 'Дані');
Expand Down
6 changes: 6 additions & 0 deletions nominatim_reverse_proxy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
// This file performs a reverse geocoding request with nominatim API
header('Content-Type: application/json');
$_GET["format"] = "json";
echo file_get_contents('http://nominatim.openstreetmap.org/reverse?'.http_build_query($_GET));
?>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?> is not needed