]> git.openstreetmap.org Git - nominatim.git/blob - lib/template/details-html.php
Merge pull request #1733 from krahulreddy/whitespaces-considered-as-single-space
[nominatim.git] / lib / template / details-html.php
1 <?php
2     header("content-type: text/html; charset=UTF-8");
3 ?>
4 <?php include(CONST_BasePath.'/lib/template/includes/html-header.php'); ?>
5     <link href="css/common.css" rel="stylesheet" type="text/css" />
6     <link href="css/details.css" rel="stylesheet" type="text/css" />
7 </head>
8
9
10 <?php
11
12     function headline($sTitle)
13     {
14         echo "<tr class='all-columns'><td colspan='6'><h2>".$sTitle."</h2></td></tr>\n";
15     }
16
17     function headline3($sTitle)
18     {
19         echo "<tr class='all-columns'><td colspan='6'><h3>".$sTitle."</h3></td></tr>\n";
20     }
21
22
23     function format_distance($fDistance, $bInMeters = false)
24     {
25         if ($bInMeters) {
26             // $fDistance is in meters
27             if ($fDistance < 1) {
28                 return '0';
29             }
30             elseif ($fDistance < 1000) {
31                 return '<abbr class="distance" title="'.$fDistance.' meters">~'.(round($fDistance,0)).' m</abbr>';
32             }
33             else {
34                 return '<abbr class="distance" title="'.$fDistance.' meters">~'.(round($fDistance/1000,1)).' km</abbr>';
35             }
36         } else {
37             if ($fDistance == 0) {
38                 return '0';
39             } else {
40                 return '<abbr class="distance" title="spheric distance '.$fDistance.'">'.(round($fDistance,4)).'</abbr>';
41             }
42         }
43     }
44
45     function kv($sKey,$sValue)
46     {
47         echo ' <tr><td>' . $sKey . '</td><td>'.$sValue.'</td></tr>'. "\n";
48     }
49
50
51     function hash_to_subtable($aAssociatedList)
52     {
53         $sHTML = '';
54         foreach ($aAssociatedList as $sKey => $sValue) {
55             $sHTML = $sHTML.' <div class="line"><span class="name">'.$sValue.'</span> ('.$sKey.')</div>'."\n";
56         }
57         return $sHTML;
58     }
59
60     function map_icon($sIcon)
61     {
62         if ($sIcon){
63             echo '<img id="mapicon" src="'.CONST_Website_BaseURL.'images/mapicons/'.$sIcon.'.n.32.png'.'" alt="'.$sIcon.'" />';
64         }
65     }
66
67
68     function _one_row($aAddressLine, $bDistanceInMeters = false){
69         $bNotUsed = isset($aAddressLine['isaddress']) && !$aAddressLine['isaddress'];
70
71         echo '<tr class="' . ($bNotUsed?'notused':'') . '">'."\n";
72         echo '  <td class="name">'.(trim($aAddressLine['localname'])!==null?$aAddressLine['localname']:'<span class="noname">No Name</span>')."</td>\n";
73         echo '  <td>' . $aAddressLine['class'].':'.$aAddressLine['type'];
74         if ($aAddressLine['type'] == 'administrative'
75             && isset($aAddressLine['place_type']))
76         {
77             echo '('.$aAddressLine['place_type'].')';
78         }
79         echo "</td>\n";
80         echo '  <td>' . osmLink($aAddressLine) . "</td>\n";
81         echo '  <td>' . (isset($aAddressLine['rank_address']) ? $aAddressLine['rank_address'] : '') . "</td>\n";
82         echo '  <td>' . ($aAddressLine['admin_level'] < 15 ? $aAddressLine['admin_level'] : '') . "</td>\n";
83         echo '  <td>' . format_distance($aAddressLine['distance'], $bDistanceInMeters)."</td>\n";
84         echo '  <td>' . detailsPermaLink($aAddressLine,'details &gt;') . "</td>\n";
85         echo "</tr>\n";
86     }
87
88     function _one_keyword_row($keyword_token,$word_id){
89         echo "<tr>\n";
90         echo '<td>';
91         // mark partial tokens (those starting with a space) with a star for readability
92         echo ($keyword_token[0]==' '?'*':'');
93         echo $keyword_token;
94         if (isset($word_id))
95         {
96             echo '</td><td>word id: '.$word_id;
97         }
98         echo "</td></tr>\n";
99     }
100
101 ?>
102
103
104
105 <body id="details-page">
106     <?php include(CONST_BasePath.'/lib/template/includes/html-top-navigation.php'); ?>
107     <div class="container">
108         <div class="row">
109             <div class="col-sm-10">
110                 <h1>
111                     <?php echo $aPointDetails['localname'] ?>
112                 </h1>
113             </div>
114             <div class="col-sm-2 text-right">
115                 <?php map_icon($aPointDetails['icon']) ?>
116             </div>
117         </div>
118         <div class="row">
119             <div class="col-md-6">
120                 <table id="locationdetails" class="table table-striped">
121
122                 <?php
123
124                     kv('Name'            , hash_to_subtable($aPointDetails['aNames']) );
125                     kv('Type'            , $aPointDetails['class'].':'.$aPointDetails['type'] );
126                     kv('Last Updated'    , (new DateTime('@'.$aPointDetails['indexed_epoch']))->format(DateTime::RFC822) );
127                     kv('Admin Level'     , $aPointDetails['admin_level'] );
128                     kv('Rank'            , $aPointDetails['rank_search_label'] );
129                     if ($aPointDetails['calculated_importance']) {
130                         kv('Importance'    , $aPointDetails['calculated_importance'].($aPointDetails['importance']?'':' (estimated)') );
131                     }
132                     kv('Coverage'        , ($aPointDetails['isarea']?'Polygon':'Point') );
133                     kv('Centre Point'    , $aPointDetails['lat'].','.$aPointDetails['lon'] );
134                     kv('OSM'             , osmLink($aPointDetails) );
135                     kv('Place Id (<a href="https://nominatim.org/release-docs/develop/api/Output/#place_id-is-not-a-persistent-id">on this server</a>)'
136                                          , $aPointDetails['place_id'] );
137                     if ($aPointDetails['wikipedia'])
138                     {
139                         kv('Wikipedia Calculated' , wikipediaLink($aPointDetails) );
140                     }
141
142                     kv('Computed Postcode', $aPointDetails['postcode']);
143                     kv('Address Tags'    , hash_to_subtable($aPointDetails['aAddressTags']) );
144                     kv('Extra Tags'      , hash_to_subtable($aPointDetails['aExtraTags']) );
145
146                 ?>
147
148                 </table>
149             </div>
150
151             <div class="col-md-6">
152                 <div id="map"></div>
153             </div>
154
155         </div>
156         <div class="row">
157             <div class="col-md-12">
158
159             <h2>Address</h2>
160
161             <table id="address" class="table table-striped table-responsive">
162                 <thead>
163                     <tr>
164                       <td>Local name</td>
165                       <td>Type</td>
166                       <td>OSM</td>
167                       <td>Address rank</td>
168                       <td>Admin level</td>
169                       <td>Distance</td>
170                       <td></td>
171                     </tr>
172                 </thead>
173                 <tbody>
174
175                 <?php
176                     foreach ($aAddressLines as $aAddressLine) {
177                         _one_row($aAddressLine);
178                     }
179                 ?>
180
181
182 <?php
183
184     if ($aLinkedLines)
185     {
186         headline('Linked Places');
187         foreach ($aLinkedLines as $aAddressLine) {
188             _one_row($aAddressLine, true);
189         }
190     }
191
192     if ($bIncludeKeywords)
193     {
194         headline('Name Keywords');
195         if ($aPlaceSearchNameKeywords) {
196             foreach ($aPlaceSearchNameKeywords as $aRow) {
197                 _one_keyword_row($aRow['word_token'], $aRow['word_id']);
198             }
199         }
200
201         headline('Address Keywords');
202         if ($aPlaceSearchAddressKeywords) {
203             foreach ($aPlaceSearchAddressKeywords as $aRow) {
204                 _one_keyword_row($aRow['word_token'], $aRow['word_id']);
205             }
206         }
207     }
208
209     if (!empty($aHierarchyLines))
210     {
211         headline('Parent Of');
212
213         $aGroupedAddressLines = array();
214         foreach ($aHierarchyLines as $aAddressLine) {
215             if ($aAddressLine['type'] == 'yes') $sType = $aAddressLine['class'];
216             else $sType = $aAddressLine['type'];
217
218             if (!isset($aGroupedAddressLines[$sType]))
219                 $aGroupedAddressLines[$sType] = array();
220             $aGroupedAddressLines[$sType][] = $aAddressLine;
221         }
222         foreach ($aGroupedAddressLines as $sGroupHeading => $aHierarchyLines) {
223             $sGroupHeading = ucwords($sGroupHeading);
224             headline3($sGroupHeading);
225
226             foreach ($aHierarchyLines as $aAddressLine) {
227                 _one_row($aAddressLine, true);
228             }
229         }
230         if (count($aHierarchyLines) >= 500) {
231             echo '<p>There are more child objects which are not shown.</p>';
232         }
233     }
234
235     echo "</table>\n";
236 ?>
237
238             </div>
239         </div>
240     </div>
241
242     <script type="text/javascript">
243     <?php
244
245         $aNominatimMapInit = array(
246           'tile_url' => $sTileURL,
247           'tile_attribution' => $sTileAttribution
248         );
249         echo 'var nominatim_map_init = ' . json_encode($aNominatimMapInit, JSON_PRETTY_PRINT) . ';';
250
251         $aPlace = array(
252                 'asgeojson' => $aPointDetails['asgeojson'],
253                 'lon' => $aPointDetails['lon'],
254                 'lat' => $aPointDetails['lat'],
255         );
256         echo 'var nominatim_result = ' . json_encode($aPlace, JSON_PRETTY_PRINT) . ';';
257
258
259     ?>
260     </script>
261
262
263
264     <?php include(CONST_BasePath.'/lib/template/includes/html-footer.php'); ?>
265 </body>
266 </html>