]> git.openstreetmap.org Git - nominatim-ui.git/blob - src/pages/DetailsPage.svelte
Helper check for details keywords (#160)
[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 </script>
73
74 <Header>
75   <SearchSectionDetails api_request_params={api_request_params}/>
76 </Header>
77
78 <div class="container">
79   {#if aPlace}
80     <div class="row">
81       <div class="col-sm-10">
82         <h1>
83           {aPlace.localname || `${formatOSMType(aPlace.osm_type)} ${aPlace.osm_id}` }
84           <small><DetailsLink feature={aPlace}>link to this page</DetailsLink></small>
85         </h1>
86       </div>
87       <div class="col-sm-2 text-end">
88         <MapIcon aPlace={aPlace} />
89       </div>
90     </div>
91     <div class="row">
92       <div class="col-md-6">
93         <table id="locationdetails" class="table table-striped table-responsive">
94           <tbody>
95             <InfoRow title="Name">
96             {#if (Array.isArray(aPlace.names)) }
97               <span class="noname fw-bold">No Name</span>
98             {:else}
99               <InfoRowList items={aPlace.names} />
100             {/if}
101             </InfoRow>
102             <InfoRow title="Type">{aPlace.category}:{aPlace.type}</InfoRow>
103             <InfoRow title="Last Updated">{aPlace.indexed_date}</InfoRow>
104             {#if (isAdminBoundary(aPlace)) }
105               <InfoRow title="Admin Level">{aPlace.admin_level}</InfoRow>
106             {/if}
107             <InfoRow title="Search Rank">{aPlace.rank_search}</InfoRow>
108             <InfoRow title="Address Rank">{aPlace.rank_address} ({formatAddressRank(aPlace.rank_address)})</InfoRow>
109             {#if aPlace.calculated_importance}
110               <InfoRow title="Importance">
111                   {aPlace.calculated_importance}
112                   {#if !aPlace.importance} (estimated){/if}
113               </InfoRow>
114             {/if}
115             <InfoRow title="Coverage">{coverageType(aPlace)}</InfoRow>
116             <InfoRow title="Centre Point (lat,lon)">
117                 {aPlace.centroid.coordinates[1]},{aPlace.centroid.coordinates[0]}
118             </InfoRow>
119             <InfoRow title="OSM">{@html osmLink(aPlace)}</InfoRow>
120             <InfoRow title="Place Id">
121                {aPlace.place_id}
122                (<a href="https://nominatim.org/release-docs/develop/api/Output/#place_id-is-not-a-persistent-id">on this server</a>)
123             </InfoRow>
124             {#if aPlace.calculated_wikipedia}
125               <InfoRow title="Wikipedia Calculated">{@html wikipediaLink(aPlace)}</InfoRow>
126             {/if}
127             <InfoRow title="Computed Postcode">
128               {#if aPlace.calculated_postcode}
129                 {aPlace.calculated_postcode}
130                 <DetailsPostcodeHint postcode={aPlace.calculated_postcode} lat={aPlace.centroid.coordinates[1]} lon={aPlace.centroid.coordinates[0]} />
131               {/if}
132             </InfoRow>
133             <InfoRow title="Address Tags"><InfoRowList items={aPlace.addresstags} /></InfoRow>
134             <InfoRow title="Extra Tags"><InfoRowList items={aPlace.extratags} /></InfoRow>
135           </tbody>
136         </table>
137       </div>
138       <div class="col-md-6">
139         <div id="map-wrapper">
140           <Map current_result={aPlace} />
141         </div>
142       </div>
143     </div>
144     <div class="row">
145       <div class="col-md-12">
146         <h2>Address</h2>
147          <table id="address" class="table table-striped table-small">
148           <thead>
149             <tr>
150               <th>Local name</th>
151               <th>Type</th>
152               <th>OSM</th>
153               <th>Address rank</th>
154               <th>Admin level</th>
155               <th>Distance</th>
156               <th></th>
157             </tr>
158           </thead>
159           <tbody>
160             {#if aPlace.address}
161               {#each aPlace.address as addressLine}
162                 <DetailsOneRow addressLine={addressLine} bMarkUnusedLines=true bDistanceInMeters=false />
163               {/each}
164             {/if}
165
166             {#if aPlace.linked_places}
167               <tr class="all-columns"><td colspan="6"><h2>Linked Places</h2></td></tr>
168               {#each aPlace.linked_places as addressLine}
169                 <DetailsOneRow addressLine={addressLine} bMarkUnusedLines=true bDistanceInMeters=true />
170               {/each}
171             {/if}
172
173             <tr class="all-columns"><td colspan="6"><h2>Keywords</h2></td></tr>
174             {#if api_request_params.keywords}
175
176               {#if place_has_keywords(aPlace)}
177                 <tr class="all-columns"><td colspan="6"><h3>Name Keywords</h3></td></tr>
178                 {#each aPlace.keywords.name as keyword}
179                   <tr>
180                     <td>{formatKeywordToken(keyword.token)}</td>
181                     {#if keyword.id}
182                       <td>word id: {keyword.id}</td>
183                     {/if}
184                   </tr>
185                 {/each}
186
187                 {#if aPlace.keywords.address}
188                   <tr class="all-columns"><td colspan="6"><h3>Address Keywords</h3></td></tr>
189                   {#each aPlace.keywords.address as keyword}
190                     <tr>
191                       <td>{formatKeywordToken(keyword.token)}</td>
192                       {#if keyword.id}
193                         <td>word id: {keyword.id}</td>
194                       {/if}
195                     </tr>
196                   {/each}
197                 {/if}
198               {:else}
199                 <tr><td>Place has no keywords</td></tr>
200               {/if}
201             {:else}
202               <tr>
203                 <td>
204                    <a class="btn btn-outline-secondary btn-sm"
205                     href="{base_url}&keywords=1">display keywords</a>
206                 </td>
207               </tr>
208             {/if}
209
210             <tr class="all-columns"><td colspan="6"><h2>Parent Of</h2></td></tr>
211             {#if api_request_params.hierarchy}
212               {#if aPlace.hierarchy && typeof (aPlace.hierarchy) === 'object' && Object.keys(aPlace.hierarchy).length}
213                 {#each Object.keys(aPlace.hierarchy) as type}
214                   <tr class="all-columns"><td colspan="6"><h3>{type}</h3></td></tr>
215                   {#each aPlace.hierarchy[type] as line}
216                     <DetailsOneRow addressLine={line} bDistanceInMeters=true />
217                  {/each}
218                 {/each}
219
220                 {#if Object.keys(aPlace.hierarchy) > 500}
221                   <p>There are more child objects which are not shown.</p>
222                 {/if}
223               {:else}
224                 <tr><td>Place is not parent of other places</td></tr>
225               {/if}
226             {:else}
227               <tr>
228                 <td>
229                    <a class="btn btn-outline-secondary btn-sm"
230                     href="{base_url}&hierarchy=1">display child places</a>
231                 </td>
232               </tr>
233             {/if}
234           </tbody>
235         </table>
236       </div>
237     </div>
238   {:else if (window.location.search !== '' && api_request_finished)}
239     No such place found.
240   {/if}
241 </div>
242
243
244
245 <style>
246   h1 {
247     margin: 10px 0;
248     padding-left: 8px;
249   }
250
251   h1 small :global(a) {
252     font-size: 0.5em;
253     white-space: nowrap;
254   }
255
256   h2 {
257     font-size: 2em;
258     padding-left: 8px;
259     background-color: white;
260   }
261   h3 {
262     font-size: 1.5em;
263     padding-left: 8px;
264   }
265
266   tr.all-columns {
267     background-color: white !important; 
268     border: none;
269   }
270   tr.all-columns td {
271     border-top: none !important;
272     padding-left: 0 !important;
273   }
274   :global(span.noname){
275     color:#800;
276   }
277
278   #map-wrapper {
279     width:100%;
280     min-height: auto;
281     height:300px;
282     border: 1px solid #666;
283   }
284 </style>