]> git.openstreetmap.org Git - nominatim-ui.git/blob - src/pages/DetailsPage.svelte
Bump word-wrap from 1.2.3 to 1.2.4
[nominatim-ui.git] / src / pages / DetailsPage.svelte
1 <script>
2   import { fetch_from_api, update_html_title } from '../lib/api_utils.js';
3   import { page } from '../lib/stores.js';
4
5   import {
6     osmLink, wikipediaLink, coverageType, isAdminBoundary,
7     formatAddressRank, formatKeywordToken, formatOSMType
8   } from '../lib/helpers.js';
9   import Header from '../components/Header.svelte';
10   import MapIcon from '../components/MapIcon.svelte';
11   import SearchSectionDetails from '../components/SearchSectionDetails.svelte';
12   import DetailsOneRow from '../components/DetailsOneRow.svelte';
13   import DetailsLink from '../components/DetailsLink.svelte';
14   import DetailsPostcodeHint from '../components/DetailsPostcodeHint.svelte';
15   import InfoRow from '../components/DetailsInfoRow.svelte';
16   import InfoRowList from '../components/DetailsInfoRowList.svelte';
17   import Map from '../components/Map.svelte';
18
19   let aPlace;
20   let base_url;
21   let api_request_params;
22   let api_request_finished = false;
23
24   function loaddata(search_params) {
25     api_request_params = {
26       place_id: search_params.get('place_id'),
27       osmtype: search_params.get('osmtype'),
28       osmid: search_params.get('osmid'),
29       class: search_params.get('class'),
30       keywords: search_params.get('keywords'),
31       addressdetails: 1,
32       hierarchy: (search_params.get('hierarchy') === '1' ? 1 : 0),
33       group_hierarchy: 1,
34       polygon_geojson: 1,
35       format: 'json'
36     };
37     api_request_finished = false;
38
39     if (api_request_params.place_id || (api_request_params.osmtype && api_request_params.osmid)) {
40
41       if (api_request_params.place_id) {
42         update_html_title('Details for ' + api_request_params.place_id);
43       } else {
44         update_html_title('Details for ' + api_request_params.osmtype + api_request_params.osmid);
45       }
46
47       fetch_from_api('details', api_request_params, function (data) {
48         window.scrollTo(0, 0);
49         api_request_finished = true;
50         aPlace = (data && !data.error) ? data : undefined;
51       });
52     } else {
53       aPlace = undefined;
54     }
55   }
56
57   function place_has_keywords(aThisPlace) {
58     // Return false if Nominatim API sends 'keywords: { name: [], address: [] }'
59     return (
60       aThisPlace.keywords && aThisPlace.keywords.name && aThisPlace.keywords.address
61       && (aThisPlace.keywords.name.length > 0 || aThisPlace.keywords.address.length > 0)
62     );
63   }
64
65   $: {
66     let pageinfo = $page;
67     if (pageinfo.tab === 'details') {
68       loaddata(pageinfo.params);
69       base_url = window.location.search;
70     }
71   }
72   $: reverse_only = Nominatim_Config.Reverse_Only;
73 </script>
74
75 <Header>
76   <SearchSectionDetails api_request_params={api_request_params}/>
77 </Header>
78
79 <div class="container">
80   {#if aPlace}
81     <div class="row">
82       <div class="col-sm-10">
83         <h1>
84           {aPlace.localname || `${formatOSMType(aPlace.osm_type)} ${aPlace.osm_id}` }
85           <small><DetailsLink feature={aPlace}>link to this page</DetailsLink></small>
86         </h1>
87       </div>
88       <div class="col-sm-2 text-end">
89         <MapIcon aPlace={aPlace} />
90       </div>
91     </div>
92     <div class="row">
93       <div class="col-md-6">
94         <table id="locationdetails" class="table table-striped table-responsive">
95           <tbody>
96             <InfoRow title="Name">
97             {#if (Array.isArray(aPlace.names)) }
98               <span class="noname fw-bold">No Name</span>
99             {:else}
100               <InfoRowList items={aPlace.names} />
101             {/if}
102             </InfoRow>
103             <InfoRow title="Type">{aPlace.category}:{aPlace.type}</InfoRow>
104             <InfoRow title="Last Updated">{aPlace.indexed_date}</InfoRow>
105             {#if (isAdminBoundary(aPlace)) }
106               <InfoRow title="Admin Level">{aPlace.admin_level}</InfoRow>
107             {/if}
108             <InfoRow title="Search Rank">{aPlace.rank_search}</InfoRow>
109             <InfoRow title="Address Rank">
110               {aPlace.rank_address} ({formatAddressRank(aPlace.rank_address)})
111             </InfoRow>
112             {#if aPlace.calculated_importance}
113               <InfoRow title="Importance">
114                   {aPlace.calculated_importance}
115                   {#if !aPlace.importance} (estimated){/if}
116               </InfoRow>
117             {/if}
118             <InfoRow title="Coverage">{coverageType(aPlace)}</InfoRow>
119             <InfoRow title="Centre Point (lat,lon)">
120                 {aPlace.centroid.coordinates[1]},{aPlace.centroid.coordinates[0]}
121             </InfoRow>
122             <!-- eslint-disable-next-line svelte/no-at-html-tags -->
123             <InfoRow title="OSM">{@html osmLink(aPlace)}</InfoRow>
124             <InfoRow title="Place Id">
125                {aPlace.place_id}
126                (<a href="https://nominatim.org/release-docs/develop/api/Output/#place_id-is-not-a-persistent-id">
127                  on this server
128                </a>)
129             </InfoRow>
130             {#if aPlace.calculated_wikipedia}
131               <!-- eslint-disable-next-line svelte/no-at-html-tags -->
132               <InfoRow title="Wikipedia Calculated">{@html wikipediaLink(aPlace)}</InfoRow>
133             {/if}
134             <InfoRow title="Computed Postcode">
135               {#if aPlace.calculated_postcode}
136                 {aPlace.calculated_postcode}
137                 <DetailsPostcodeHint postcode={aPlace.calculated_postcode}
138                                      lat={aPlace.centroid.coordinates[1]}
139                                      lon={aPlace.centroid.coordinates[0]} />
140               {/if}
141             </InfoRow>
142             <InfoRow title="Address Tags"><InfoRowList items={aPlace.addresstags} /></InfoRow>
143             <InfoRow title="Extra Tags"><InfoRowList items={aPlace.extratags} /></InfoRow>
144           </tbody>
145         </table>
146       </div>
147       <div class="col-md-6">
148         <div id="map-wrapper">
149           <Map current_result={aPlace} />
150         </div>
151       </div>
152     </div>
153     <div class="row">
154       <div class="col-md-12">
155         <h2>Address</h2>
156          <table id="address" class="table table-striped table-small">
157           <thead>
158             <tr>
159               <th>Local name</th>
160               <th>Type</th>
161               <th>OSM</th>
162               <th>Address rank</th>
163               <th>Admin level</th>
164               <th>Distance</th>
165               <th></th>
166             </tr>
167           </thead>
168           <tbody>
169             {#if aPlace.address}
170               {#each aPlace.address as addressLine}
171                 <DetailsOneRow addressLine={addressLine}
172                                bMarkUnusedLines={true}
173                                bDistanceInMeters={false} />
174               {/each}
175             {/if}
176
177             {#if aPlace.linked_places}
178               <tr class="all-columns"><td colspan="7"><h2>Linked Places</h2></td></tr>
179               {#each aPlace.linked_places as addressLine}
180                 <DetailsOneRow addressLine={addressLine}
181                                bMarkUnusedLines={true}
182                                bDistanceInMeters={true} />
183               {/each}
184             {/if}
185
186             {#if !reverse_only}
187               <tr class="all-columns"><td colspan="7"><h2>Keywords</h2></td></tr>
188               {#if api_request_params.keywords}
189
190                 {#if place_has_keywords(aPlace)}
191                   <tr class="all-columns"><td colspan="7"><h3>Name Keywords</h3></td></tr>
192                   {#each aPlace.keywords.name as keyword}
193                     <tr>
194                       <td>{formatKeywordToken(keyword.token)}</td>
195                       {#if keyword.id}
196                         <td>word id: {keyword.id}</td>
197                       {/if}
198                     </tr>
199                   {/each}
200
201                   {#if aPlace.keywords.address}
202                     <tr class="all-columns"><td colspan="7"><h3>Address Keywords</h3></td></tr>
203                     {#each aPlace.keywords.address as keyword}
204                       <tr>
205                         <td>{formatKeywordToken(keyword.token)}</td>
206                         {#if keyword.id}
207                           <td>word id: {keyword.id}</td>
208                         {/if}
209                       </tr>
210                     {/each}
211                   {/if}
212                 {:else}
213                   <tr><td>Place has no keywords</td></tr>
214                 {/if}
215               {:else}
216                 <tr>
217                   <td>
218                      <a class="btn btn-outline-secondary btn-sm"
219                       href="{base_url}&keywords=1">display keywords</a>
220                   </td>
221                 </tr>
222               {/if}
223             {/if}
224
225             <tr class="all-columns"><td colspan="7"><h2>Parent Of</h2></td></tr>
226             {#if api_request_params.hierarchy}
227               {#if aPlace.hierarchy && typeof (aPlace.hierarchy) === 'object'
228                 && Object.keys(aPlace.hierarchy).length}
229                 {#each Object.keys(aPlace.hierarchy) as type}
230                   <tr class="all-columns"><td colspan="7"><h3>{type}</h3></td></tr>
231                   {#each aPlace.hierarchy[type] as line}
232                     <DetailsOneRow addressLine={line} bDistanceInMeters={true} />
233                  {/each}
234                 {/each}
235
236                 {#if Object.keys(aPlace.hierarchy) > 500}
237                   <p>There are more child objects which are not shown.</p>
238                 {/if}
239               {:else}
240                 <tr><td>Place is not parent of other places</td></tr>
241               {/if}
242             {:else}
243               <tr>
244                 <td>
245                    <a class="btn btn-outline-secondary btn-sm"
246                     href="{base_url}&hierarchy=1">display child places</a>
247                 </td>
248               </tr>
249             {/if}
250           </tbody>
251         </table>
252       </div>
253     </div>
254   {:else if (window.location.search !== '' && api_request_finished)}
255     No such place found.
256   {/if}
257 </div>
258
259
260
261 <style>
262   h1 {
263     margin: 10px 0;
264     padding-left: 8px;
265   }
266
267   h1 small :global(a) {
268     font-size: 0.5em;
269     white-space: nowrap;
270   }
271
272   h2 {
273     font-size: 2em;
274     padding-left: 8px;
275     background-color: white;
276   }
277   h3 {
278     font-size: 1.5em;
279     padding-left: 8px;
280   }
281
282   tr.all-columns {
283     background-color: white !important;
284     border: none;
285   }
286   tr.all-columns td {
287     border-top: none !important;
288     padding-left: 0 !important;
289   }
290   :global(span.noname){
291     color:#800;
292   }
293
294   #map-wrapper {
295     position: relative;
296     width:100%;
297     min-height: auto;
298     height:300px;
299     border: 1px solid #666;
300   }
301 </style>