]> git.openstreetmap.org Git - nominatim.git/blob - lib/template/details-html.php
adapt test results to new ranking
[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($aPlace)
61     {
62         $sIcon = Nominatim\ClassTypes\getIconFile($aPlace);
63         if (isset($sIcon)) {
64             $sLabel = Nominatim\ClassTypes\getIcon($aPlace);
65             echo '<img id="mapicon" src="'.$sIcon.'" alt="'.$sLabel.'" />';
66         }
67     }
68
69
70     function _one_row($aAddressLine, $bDistanceInMeters = false){
71         $bNotUsed = isset($aAddressLine['isaddress']) && !$aAddressLine['isaddress'];
72
73         echo '<tr class="' . ($bNotUsed?'notused':'') . '">'."\n";
74         echo '  <td class="name">'.(trim($aAddressLine['localname'])!==null?$aAddressLine['localname']:'<span class="noname">No Name</span>')."</td>\n";
75         echo '  <td>' . $aAddressLine['class'].':'.$aAddressLine['type'];
76         if ($aAddressLine['type'] == 'administrative'
77             && isset($aAddressLine['place_type']))
78         {
79             echo '('.$aAddressLine['place_type'].')';
80         }
81         echo "</td>\n";
82         echo '  <td>' . osmLink($aAddressLine) . "</td>\n";
83         echo '  <td>' . (isset($aAddressLine['rank_address']) ? $aAddressLine['rank_address'] : '') . "</td>\n";
84         echo '  <td>' . ($aAddressLine['admin_level'] < 15 ? $aAddressLine['admin_level'] : '') . "</td>\n";
85         echo '  <td>' . format_distance($aAddressLine['distance'], $bDistanceInMeters)."</td>\n";
86         echo '  <td>' . detailsPermaLink($aAddressLine,'details &gt;') . "</td>\n";
87         echo "</tr>\n";
88     }
89
90     function _one_keyword_row($keyword_token,$word_id){
91         echo "<tr>\n";
92         echo '<td>';
93         // mark partial tokens (those starting with a space) with a star for readability
94         echo ($keyword_token[0]==' '?'*':'');
95         echo $keyword_token;
96         if (isset($word_id))
97         {
98             echo '</td><td>word id: '.$word_id;
99         }
100         echo "</td></tr>\n";
101     }
102
103 ?>
104
105
106
107 <body id="details-page">
108     <?php include(CONST_BasePath.'/lib/template/includes/html-top-navigation.php'); ?>
109     <div class="container">
110         <div class="row">
111             <div class="col-sm-10">
112                 <h1>
113                     <?php echo $aPointDetails['localname'] ?>
114                 </h1>
115             </div>
116             <div class="col-sm-2 text-right">
117                 <?php map_icon($aPointDetails) ?>
118             </div>
119         </div>
120         <div class="row">
121             <div class="col-md-6">
122                 <table id="locationdetails" class="table table-striped">
123
124                 <?php
125
126                     kv('Name'            , hash_to_subtable($aPointDetails['aNames']) );
127                     kv('Type'            , $aPointDetails['class'].':'.$aPointDetails['type'] );
128                     kv('Last Updated'    , (new DateTime('@'.$aPointDetails['indexed_epoch']))->format(DateTime::RFC822) );
129                     kv('Admin Level'     , $aPointDetails['admin_level'] );
130                     kv('Rank'            , $aPointDetails['rank_search_label'] );
131                     if ($aPointDetails['calculated_importance']) {
132                         kv('Importance'    , $aPointDetails['calculated_importance'].($aPointDetails['importance']?'':' (estimated)') );
133                     }
134                     kv('Coverage'        , ($aPointDetails['isarea']?'Polygon':'Point') );
135                     kv('Centre Point'    , $aPointDetails['lat'].','.$aPointDetails['lon'] );
136                     kv('OSM'             , osmLink($aPointDetails) );
137                     kv('Place Id (<a href="https://nominatim.org/release-docs/develop/api/Output/#place_id-is-not-a-persistent-id">on this server</a>)'
138                                          , $aPointDetails['place_id'] );
139                     if ($aPointDetails['wikipedia'])
140                     {
141                         kv('Wikipedia Calculated' , wikipediaLink($aPointDetails) );
142                     }
143
144                     kv('Computed Postcode', $aPointDetails['postcode']);
145                     kv('Address Tags'    , hash_to_subtable($aPointDetails['aAddressTags']) );
146                     kv('Extra Tags'      , hash_to_subtable($aPointDetails['aExtraTags']) );
147
148                 ?>
149
150                 </table>
151             </div>
152
153             <div class="col-md-6">
154                 <div id="map"></div>
155             </div>
156
157         </div>
158         <div class="row">
159             <div class="col-md-12">
160
161             <h2>Address</h2>
162
163             <table id="address" class="table table-striped table-responsive">
164                 <thead>
165                     <tr>
166                       <td>Local name</td>
167                       <td>Type</td>
168                       <td>OSM</td>
169                       <td>Address rank</td>
170                       <td>Admin level</td>
171                       <td>Distance</td>
172                       <td></td>
173                     </tr>
174                 </thead>
175                 <tbody>
176
177                 <?php
178                     foreach ($aAddressLines as $aAddressLine) {
179                         _one_row($aAddressLine);
180                     }
181                 ?>
182
183
184 <?php
185
186     if ($aLinkedLines)
187     {
188         headline('Linked Places');
189         foreach ($aLinkedLines as $aAddressLine) {
190             _one_row($aAddressLine, true);
191         }
192     }
193
194     if ($bIncludeKeywords)
195     {
196         headline('Name Keywords');
197         if ($aPlaceSearchNameKeywords) {
198             foreach ($aPlaceSearchNameKeywords as $aRow) {
199                 _one_keyword_row($aRow['word_token'], $aRow['word_id']);
200             }
201         }
202
203         headline('Address Keywords');
204         if ($aPlaceSearchAddressKeywords) {
205             foreach ($aPlaceSearchAddressKeywords as $aRow) {
206                 _one_keyword_row($aRow['word_token'], $aRow['word_id']);
207             }
208         }
209     }
210
211     if (!empty($aHierarchyLines))
212     {
213         headline('Parent Of');
214
215         $aGroupedAddressLines = array();
216         foreach ($aHierarchyLines as $aAddressLine) {
217             if ($aAddressLine['type'] == 'yes') $sType = $aAddressLine['class'];
218             else $sType = $aAddressLine['type'];
219
220             if (!isset($aGroupedAddressLines[$sType]))
221                 $aGroupedAddressLines[$sType] = array();
222             $aGroupedAddressLines[$sType][] = $aAddressLine;
223         }
224         foreach ($aGroupedAddressLines as $sGroupHeading => $aHierarchyLines) {
225             $sGroupHeading = ucwords($sGroupHeading);
226             headline3($sGroupHeading);
227
228             foreach ($aHierarchyLines as $aAddressLine) {
229                 _one_row($aAddressLine, true);
230             }
231         }
232         if (count($aHierarchyLines) >= 500) {
233             echo '<p>There are more child objects which are not shown.</p>';
234         }
235     }
236
237     echo "</table>\n";
238 ?>
239
240             </div>
241         </div>
242     </div>
243
244     <script type="text/javascript">
245     <?php
246
247         $aNominatimMapInit = array(
248           'tile_url' => $sTileURL,
249           'tile_attribution' => $sTileAttribution
250         );
251         echo 'var nominatim_map_init = ' . json_encode($aNominatimMapInit, JSON_PRETTY_PRINT) . ';';
252
253         $aPlace = array(
254                 'asgeojson' => $aPointDetails['asgeojson'],
255                 'lon' => $aPointDetails['lon'],
256                 'lat' => $aPointDetails['lat'],
257         );
258         echo 'var nominatim_result = ' . json_encode($aPlace, JSON_PRETTY_PRINT) . ';';
259
260
261     ?>
262     </script>
263
264
265
266     <?php include(CONST_BasePath.'/lib/template/includes/html-footer.php'); ?>
267 </body>
268 </html>