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