From 7a50d2f9964421e932313b15f5d7d3b05ded4c45 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Sun, 12 Jun 2016 12:39:09 +0200 Subject: [PATCH] factor out link formatting function and osm type translation --- lib/output.php | 43 ++++++++++++++++++++ lib/template/address-json.php | 5 +-- lib/template/address-jsonv2.php | 3 +- lib/template/address-xml.php | 3 +- lib/template/details-error-html.php | 31 ++++++-------- lib/template/details-html.php | 33 ++------------- lib/template/search-batch-json.php | 2 +- lib/template/search-json.php | 3 +- lib/template/search-jsonv2.php | 2 +- lib/template/search-xml.php | 3 +- website/deletable.php | 7 ++-- website/details.php | 2 +- website/hierarchy.php | 63 ++++++++++++++++------------- website/polygons.php | 9 ++--- website/reverse.php | 1 + website/search.php | 1 + 16 files changed, 111 insertions(+), 100 deletions(-) create mode 100644 lib/output.php diff --git a/lib/output.php b/lib/output.php new file mode 100644 index 00000000..722d73b1 --- /dev/null +++ b/lib/output.php @@ -0,0 +1,43 @@ +'.$sOSMType.' '.($sRefText?$sRefText:$aFeature['osm_id']).''; + } + return ''; + } + + function wikipediaLink($aFeature) + { + if ($aFeature['wikipedia']) + { + list($sLanguage, $sArticle) = explode(':',$aFeature['wikipedia']); + return ''.$aFeature['wikipedia'].''; + } + return ''; + } + + function detailsLink($aFeature, $sTitle=false) + { + if (!$aFeature['place_id']) return ''; + + return ''.($sTitle?$sTitle:$aFeature['place_id']).''; + } + diff --git a/lib/template/address-json.php b/lib/template/address-json.php index 38db01c8..bf6c700b 100644 --- a/lib/template/address-json.php +++ b/lib/template/address-json.php @@ -12,8 +12,7 @@ { if (isset($aPlace['place_id'])) $aFilteredPlaces['place_id'] = $aPlace['place_id']; $aFilteredPlaces['licence'] = "Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright"; - $sOSMType = ($aPlace['osm_type'] == 'N'?'node':($aPlace['osm_type'] == 'W'?'way':($aPlace['osm_type'] == 'R'?'relation': - ($aPlace['osm_type'] == 'T'?'tiger':($aPlace['osm_type'] == 'I'?'interpolation':''))))); + $sOSMType = formatOSMType($aPlace['osm_type']); if ($sOSMType) { $aFilteredPlaces['osm_type'] = $sOSMType; @@ -50,8 +49,6 @@ { $aFilteredPlaces['geokml'] = $aPlace['askml']; } - - } javascript_renderData($aFilteredPlaces); diff --git a/lib/template/address-jsonv2.php b/lib/template/address-jsonv2.php index 2cef5e31..d6214176 100644 --- a/lib/template/address-jsonv2.php +++ b/lib/template/address-jsonv2.php @@ -12,8 +12,7 @@ { if ($aPlace['place_id']) $aFilteredPlaces['place_id'] = $aPlace['place_id']; $aFilteredPlaces['licence'] = "Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright"; - $sOSMType = ($aPlace['osm_type'] == 'N'?'node':($aPlace['osm_type'] == 'W'?'way':($aPlace['osm_type'] == 'R'?'relation': - ($aPlace['osm_type'] == 'T'?'tiger':($aPlace['osm_type'] == 'I'?'interpolation':''))))); + $sOSMType = formatOSMType($aPlace['osm_type']); if ($sOSMType) { $aFilteredPlaces['osm_type'] = $sOSMType; diff --git a/lib/template/address-xml.php b/lib/template/address-xml.php index 5e74846e..2bfcffbf 100644 --- a/lib/template/address-xml.php +++ b/lib/template/address-xml.php @@ -22,8 +22,7 @@ { echo "'.$sOSMType.' '.$aFeature['osm_id'].''; - } - return ''; - } - - function osm_map_url($aFeature) + function osmMapUrl($aFeature) { $sLon = $aFeature['error_x']; $sLat = $aFeature['error_y']; - if (isset($sLat)) + if (isset($sFeature['error_x']) && isset($sFeature['error_y'])) { - $sOSMType = ($aFeature['osm_type'] == 'N'?'node':($aFeature['osm_type'] == 'W'?'way':($aFeature['osm_type'] == 'R'?'relation':''))); + $sBaseUrl = '//www.openstreetmap.org/'; + $sOSMType = formatOSMType($aFeature['osm_type'], false); if ($sOSMType) { - return "http://www.openstreetmap.org/?lat=".$sLat."&lon=".$sLon."&zoom=18&layers=M&".$sOSMType."=".$aFeature['osm_id']; + $sBaseUrl += $sOSMType.'/'.$aFeature['osm_id']; + } + + return 'view on osm.org'; } } return ''; @@ -45,7 +40,7 @@ return "http://localhost:8111/load_and_zoom?left=".($sLon-$fWidth)."&right=".($sLon+$fWidth)."&top=".($sLat+$fWidth)."&bottom=".($sLat-$fWidth); } - $sOSMType = ($aFeature['osm_type'] == 'N'?'node':($aFeature['osm_type'] == 'W'?'way':($aFeature['osm_type'] == 'R'?'relation':''))); + $sOSMType = formatOSMType($aFeature['osm_type'], false); if ($sOSMType) { return 'http://localhost:8111/import?url=http://www.openstreetmap.org/api/0.6/'.$sOSMType.'/'.$aFeature['osm_id'].'/full'; @@ -63,7 +58,7 @@ if (isset($sLat)) { - return "http://www.openstreetmap.org/edit?editor=potlatch2&bbox=".($sLon-$fWidth).",".($sLat-$fWidth).",".($sLon+$fWidth).",".($sLat+$fWidth); + return "//www.openstreetmap.org/edit?editor=potlatch2&bbox=".($sLon-$fWidth).",".($sLat-$fWidth).",".($sLon+$fWidth).",".($sLat+$fWidth); } return ''; } @@ -87,7 +82,7 @@
- OSM: + OSM:
@@ -95,9 +90,7 @@

- - view on osm.org - +

Edit