]> git.openstreetmap.org Git - nominatim-ui.git/blobdiff - src/pages/DetailsPage.svelte
svelte 4.x => 5.0
[nominatim-ui.git] / src / pages / DetailsPage.svelte
index 1f6d84e079ff61be6922a711576828ddc64a9ac7..a8bb120b44b907b2475b9186552756defc51f53e 100644 (file)
 
   function place_has_keywords(aThisPlace) {
     // Return false if Nominatim API sends 'keywords: { name: [], address: [] }'
+    // Like no longer needed after Nominatim version 4.3
     return (
       aThisPlace.keywords && aThisPlace.keywords.name && aThisPlace.keywords.address
       && (aThisPlace.keywords.name.length > 0 || aThisPlace.keywords.address.length > 0)
     );
   }
 
+  function country_code(aThisPlace) {
+    let aLine = aThisPlace.address.find((address_line) => address_line.type === 'country_code');
+    return aLine ? aLine.localname : null;
+  }
+
   $: {
     let pageinfo = $page;
     if (pageinfo.tab === 'details') {
         <table id="locationdetails" class="table table-striped table-responsive">
           <tbody>
             <InfoRow title="Name">
-            {#if (Array.isArray(aPlace.names)) }
-              <span class="noname fw-bold">No Name</span>
-            {:else}
+            {#if aPlace.names && typeof (aPlace.names) === 'object'
+              && Object.keys(aPlace.names).length}
               <InfoRowList items={aPlace.names} />
+            {:else}
+              <span class="noname fw-bold">No Name</span>
             {/if}
             </InfoRow>
             <InfoRow title="Type">{aPlace.category}:{aPlace.type}</InfoRow>
             <InfoRow title="Centre Point (lat,lon)">
                 {aPlace.centroid.coordinates[1]},{aPlace.centroid.coordinates[0]}
             </InfoRow>
+            <!-- eslint-disable-next-line svelte/no-at-html-tags -->
             <InfoRow title="OSM">{@html osmLink(aPlace)}</InfoRow>
             <InfoRow title="Place Id">
                {aPlace.place_id}
                </a>)
             </InfoRow>
             {#if aPlace.calculated_wikipedia}
+              <!-- eslint-disable-next-line svelte/no-at-html-tags -->
               <InfoRow title="Wikipedia Calculated">{@html wikipediaLink(aPlace)}</InfoRow>
             {/if}
             <InfoRow title="Computed Postcode">
     <div class="row">
       <div class="col-md-12">
         <h2>Address</h2>
-         <table id="address" class="table table-striped table-small">
+        <table id="address" class="table table-striped table-small">
           <thead>
             <tr>
               <th>Local name</th>
               {#each aPlace.address as addressLine}
                 <DetailsOneRow addressLine={addressLine}
                                bMarkUnusedLines={true}
-                               bDistanceInMeters={false} />
+                               bDistanceInMeters={false}
+                               sCountryCode={country_code(aPlace)} />
               {/each}
             {/if}
 
 
             <tr class="all-columns"><td colspan="7"><h2>Parent Of</h2></td></tr>
             {#if api_request_params.hierarchy}
-              {#if aPlace.hierarchy && typeof (aPlace.hierarchy) === 'object' && Object.keys(aPlace.hierarchy).length}
+              {#if aPlace.hierarchy && typeof (aPlace.hierarchy) === 'object'
+                && Object.keys(aPlace.hierarchy).length}
                 {#each Object.keys(aPlace.hierarchy) as type}
                   <tr class="all-columns"><td colspan="7"><h3>{type}</h3></td></tr>
                   {#each aPlace.hierarchy[type] as line}
                 {/each}
 
                 {#if Object.keys(aPlace.hierarchy) > 500}
-                  <p>There are more child objects which are not shown.</p>
+                  <tr><td><p>There are more child objects which are not shown.</p></td></tr>
                 {/if}
               {:else}
                 <tr><td>Place is not parent of other places</td></tr>