2 import { untrack } from 'svelte';
3 import { update_html_title } from '../lib/api_utils.js';
4 import { appState } from '../state/AppState.svelte.js';
7 coverageType, isAdminBoundary,
8 formatAddressRank, formatKeywordToken, formatOSMType
9 } from '../lib/helpers.js';
10 import Header from '../components/Header.svelte';
11 import MapIcon from '../components/MapIcon.svelte';
12 import SearchSectionDetails from '../components/SearchSectionDetails.svelte';
13 import DetailsTableHeader from '../components/DetailsTableHeader.svelte';
14 import DetailsOneRow from '../components/DetailsOneRow.svelte';
15 import DetailsLink from '../components/DetailsLink.svelte';
16 import DetailsPostcodeHint from '../components/DetailsPostcodeHint.svelte';
17 import InfoRowList from '../components/DetailsInfoRowList.svelte';
18 import WikipediaLink from '../components/WikipediaLink.svelte';
19 import OsmLink from '../components/OsmLink.svelte';
20 import Map from '../components/Map.svelte';
22 let aPlace = $state();
23 let base_url = $state();
24 let api_request_params = $state.raw();
25 let api_request_finished = $state(false);
27 function loaddata(search_params) {
28 api_request_params = {
29 place_id: search_params.get('place_id'),
30 osmtype: search_params.get('osmtype'),
31 osmid: search_params.get('osmid'),
32 class: search_params.get('class'),
33 keywords: search_params.get('keywords'),
36 hierarchy: (search_params.get('hierarchy') === '1' ? 1 : 0),
41 api_request_finished = false;
43 if (api_request_params.place_id || (api_request_params.osmtype && api_request_params.osmid)) {
45 if (api_request_params.place_id) {
46 update_html_title('Details for ' + api_request_params.place_id);
48 update_html_title('Details for ' + api_request_params.osmtype + api_request_params.osmid);
51 appState.fetchFromApi('details', api_request_params, function (data) {
52 window.scrollTo(0, 0);
53 api_request_finished = true;
54 aPlace = (data && !data.error) ? data : undefined;
61 function place_has_keywords(aThisPlace) {
62 // Return false if Nominatim API sends 'keywords: { name: [], address: [] }'
63 // Like no longer needed after Nominatim version 4.3
65 aThisPlace.keywords && aThisPlace.keywords.name && aThisPlace.keywords.address
66 && (aThisPlace.keywords.name.length > 0 || aThisPlace.keywords.address.length > 0)
70 function country_code(aThisPlace) {
71 let aLine = aThisPlace.address.find((address_line) => address_line.type === 'country_code');
72 return aLine ? aLine.localname : null;
76 if (appState.page.tab === 'details') {
77 const params = appState.page.params;
80 base_url = window.location.search;
85 const reverse_only = Nominatim_Config.Reverse_Only;
88 {#snippet subheader()}
89 <SearchSectionDetails api_request_params={api_request_params}/>
91 <Header {subheader} />
93 <div class="container">
96 <div class="col-sm-10">
98 {aPlace.localname || `${formatOSMType(aPlace.osm_type)} ${aPlace.osm_id}` }
99 <small><DetailsLink feature={aPlace} text="link to this page" /></small>
102 <div class="col-sm-2 text-end">
103 <MapIcon aPlace={aPlace} />
107 <div class="col-md-6">
108 <table id="locationdetails" class="table table-striped table-responsive">
110 <tr><td>Name</td><td>
111 {#if aPlace.names && typeof (aPlace.names) === 'object'
112 && Object.keys(aPlace.names).length}
113 <InfoRowList items={aPlace.names} />
115 <span class="noname fw-bold">No Name</span>
118 <tr><td>Type</td><td>{aPlace.category}:{aPlace.type}</td></tr>
119 <tr><td>Last Updated</td><td>{aPlace.indexed_date}</td></tr>
120 {#if (isAdminBoundary(aPlace)) }
121 <tr><td>Admin Level</td><td>{aPlace.admin_level}</td></tr>
123 <tr><td>Search Rank</td><td>{aPlace.rank_search}</td></tr>
124 <tr><td>Address Rank</td><td>
125 {aPlace.rank_address} ({formatAddressRank(aPlace.rank_address)})
127 {#if aPlace.calculated_importance}
128 <tr><td>Importance</td><td>
129 {aPlace.calculated_importance}
130 {#if !aPlace.importance} (estimated){/if}
133 <tr><td>Coverage</td><td>{coverageType(aPlace)}</td></tr>
134 <tr><td>Centre Point (lat,lon)</td><td>
135 {aPlace.centroid.coordinates[1]},{aPlace.centroid.coordinates[0]}
138 <OsmLink osmType={aPlace.osm_type} osmId={aPlace.osm_id}/>
140 <tr><td>Place Id</td><td>
142 (<a href="https://nominatim.org/release-docs/develop/api/Output/#place_id-is-not-a-persistent-id">
146 {#if aPlace.calculated_wikipedia}
147 <tr><td>Wikipedia Calculated</td><td>
148 <WikipediaLink wikipedia={aPlace.calculated_wikipedia} />
151 <tr><td>Computed Postcode</td><td>
152 {#if aPlace.calculated_postcode}
153 {aPlace.calculated_postcode}
154 <DetailsPostcodeHint postcode={aPlace.calculated_postcode}
155 lat={aPlace.centroid.coordinates[1]}
156 lon={aPlace.centroid.coordinates[0]} />
159 <tr><td>Address Tags</td><td>
160 <InfoRowList items={aPlace.addresstags} />
162 <tr><td>Extra Tags</td><td>
163 <InfoRowList items={aPlace.extratags} />
168 <div class="col-md-6">
169 <div id="map-wrapper">
170 <Map current_result={aPlace} />
174 {:else if (window.location.search !== '' && api_request_finished)}
180 <div class="col-md-12">
184 <table id="address" class="table table-striped table-small">
185 <DetailsTableHeader />
187 {#each aPlace.address as addressLine}
188 <DetailsOneRow addressLine={addressLine}
189 bMarkUnusedLines={true}
190 bDistanceInMeters={false}
191 sCountryCode={country_code(aPlace)} />
197 <h2>Linked Places</h2>
198 {#if aPlace.linked_places}
199 <table class="table table-striped table-small">
200 <DetailsTableHeader />
202 {#each aPlace.linked_places as addressLine}
203 <DetailsOneRow addressLine={addressLine}
204 bMarkUnusedLines={true}
205 bDistanceInMeters={true} />
212 {#if aPlace.entrances && aPlace.entrances.length}
213 <table class="table table-striped table-small">
217 <th>Entrance Type</th>
223 {#each aPlace.entrances as entrance, i}
224 <tr class="all-columns">
226 <td>{entrance.type}</td>
227 <td><OsmLink osmType='N' osmId={entrance.osm_id} /></td>
228 <td><InfoRowList items={entrance.extratags || {}} /></td>
234 <p>Place does not have entrances</p>
239 {#if api_request_params.keywords}
240 {#if place_has_keywords(aPlace)}
241 <h3>Name Keywords</h3>
243 <table class="table table-striped table-small">
245 {#each aPlace.keywords.name as keyword}
247 <td>{formatKeywordToken(keyword.token)}</td>
249 <td>word id: {keyword.id}</td>
255 {#if aPlace.keywords.address}
256 <h3>Address Keywords</h3>
258 <table class="table table-striped table-small">
260 {#each aPlace.keywords.address as keyword}
262 <td>{formatKeywordToken(keyword.token)}</td>
263 <td>word id: {keyword.id || '?'}</td>
270 <p>Place has no keywords</p>
273 <a class="btn btn-outline-secondary btn-sm"
274 href="{base_url}&keywords=1">display keywords</a>
279 {#if api_request_params.hierarchy}
280 {#if aPlace.hierarchy && typeof (aPlace.hierarchy) === 'object'
281 && Object.keys(aPlace.hierarchy).length}
283 {#each Object.keys(aPlace.hierarchy) as type}
285 <table class="table table-striped table-small">
286 <DetailsTableHeader />
288 {#each aPlace.hierarchy[type] as line}
289 <DetailsOneRow addressLine={line} bDistanceInMeters={true} />
294 {#if Object.keys(aPlace.hierarchy) > 500}
295 <p>There are more child objects which are not shown.</p>
298 <p>Place is not parent of other places</p>
301 <a class="btn btn-outline-secondary btn-sm"
302 href="{base_url}&hierarchy=1">display child places</a>
317 h1 small :global(a) {
324 background-color: var(--bs-body-bg);
325 border-bottom: 2px solid silver;
327 margin-bottom: 0.5em;
333 table#locationdetails td {
339 background-color: var(--bs-body-bg) !important;
343 border-top: none !important;
344 padding-left: 0 !important;
346 :global(span.noname){
347 color: var(--bs-danger);
355 border: 1px solid #666;