]> git.openstreetmap.org Git - nominatim-ui.git/blobdiff - src/pages/DetailsPage.svelte
hierarchy in details response is hash, not array (#156)
[nominatim-ui.git] / src / pages / DetailsPage.svelte
index bb72e14fd8800abccfec4cfbcaec181133b6525d..f824602bb732b3afd78331b9de5c259baaade800 100644 (file)
@@ -4,19 +4,20 @@
 
   import {
     osmLink, wikipediaLink, coverageType, isAdminBoundary,
-    formatAddressRank, formatKeywordToken
+    formatAddressRank, formatKeywordToken, formatOSMType
   } from '../lib/helpers.js';
   import Header from '../components/Header.svelte';
   import MapIcon from '../components/MapIcon.svelte';
   import SearchSectionDetails from '../components/SearchSectionDetails.svelte';
   import DetailsOneRow from '../components/DetailsOneRow.svelte';
   import DetailsLink from '../components/DetailsLink.svelte';
+  import DetailsPostcodeHint from '../components/DetailsPostcodeHint.svelte';
   import InfoRow from '../components/DetailsInfoRow.svelte';
   import InfoRowList from '../components/DetailsInfoRowList.svelte';
   import Map from '../components/Map.svelte';
 
   let aPlace;
-  let base_url = window.location.search;
+  let base_url;
   let api_request_params;
   let api_request_finished = false;
 
@@ -57,6 +58,7 @@
     let pageinfo = $page;
     if (pageinfo.tab === 'details') {
       loaddata(pageinfo.params);
+      base_url = window.location.search;
     }
   }
 </script>
@@ -70,7 +72,7 @@
     <div class="row">
       <div class="col-sm-10">
         <h1>
-          {aPlace.localname}
+          {aPlace.localname || `${formatOSMType(aPlace.osm_type)} ${aPlace.osm_id}` }
           <small><DetailsLink feature={aPlace}>link to this page</DetailsLink></small>
         </h1>
       </div>
       <div class="col-md-6">
         <table id="locationdetails" class="table table-striped table-responsive">
           <tbody>
-            <InfoRow title="Name"><InfoRowList items={aPlace.names} /></InfoRow>
+            <InfoRow title="Name">
+            {#if (Array.isArray(aPlace.names)) }
+              <span class="noname font-weight-bold">No Name</span>
+            {:else}
+              <InfoRowList items={aPlace.names} />
+            {/if}
+            </InfoRow>
             <InfoRow title="Type">{aPlace.category}:{aPlace.type}</InfoRow>
             <InfoRow title="Last Updated">{aPlace.indexed_date}</InfoRow>
             {#if (isAdminBoundary(aPlace)) }
             {#if aPlace.calculated_wikipedia}
               <InfoRow title="Wikipedia Calculated">{@html wikipediaLink(aPlace)}</InfoRow>
             {/if}
-            <InfoRow title="Computed Postcode">{aPlace.calculated_postcode || ''}</InfoRow>
+            <InfoRow title="Computed Postcode">
+              {#if aPlace.calculated_postcode}
+                {aPlace.calculated_postcode}
+                <DetailsPostcodeHint postcode={aPlace.calculated_postcode} lat={aPlace.centroid.coordinates[1]} lon={aPlace.centroid.coordinates[0]} />
+              {/if}
+            </InfoRow>
             <InfoRow title="Address Tags"><InfoRowList items={aPlace.addresstags} /></InfoRow>
             <InfoRow title="Extra Tags"><InfoRowList items={aPlace.extratags} /></InfoRow>
           </tbody>
           <tbody>
             {#if aPlace.address}
               {#each aPlace.address as addressLine}
-                <DetailsOneRow addressLine={addressLine} bDistanceInMeters=false />
+                <DetailsOneRow addressLine={addressLine} bMarkUnusedLines=true bDistanceInMeters=false />
               {/each}
             {/if}
 
             {#if aPlace.linked_places}
               <tr class="all-columns"><td colspan="6"><h2>Linked Places</h2></td></tr>
               {#each aPlace.linked_places as addressLine}
-                <DetailsOneRow addressLine={addressLine} bDistanceInMeters=true />
+                <DetailsOneRow addressLine={addressLine} bMarkUnusedLines=true bDistanceInMeters=true />
               {/each}
             {/if}
 
             <tr class="all-columns"><td colspan="6"><h2>Keywords</h2></td></tr>
-            {#if aPlace.keywords}
-              <tr class="all-columns"><td colspan="6"><h3>Name Keywords</h3></td></tr>
-              {#each aPlace.keywords.name as keyword}
-                <tr>
-                  <td>{formatKeywordToken(keyword.token)}</td>
-                  {#if keyword.id}
-                    <td>word id: {keyword.id}</td>
-                  {/if}
-                </tr>
-              {/each}
+            {#if api_request_params.keywords}
 
-              <tr class="all-columns"><td colspan="6"><h3>Address Keywords</h3></td></tr>
-              {#each aPlace.keywords.address as keyword}
-                <tr>
-                  <td>{formatKeywordToken(keyword.token)}</td>
-                  {#if keyword.id}
-                    <td>word id: {keyword.id}</td>
-                  {/if}
-              </tr>
-              {/each}
+              {#if aPlace.keywords && (aPlace.keywords.name || aPlace.keywords.address) }
+                <tr class="all-columns"><td colspan="6"><h3>Name Keywords</h3></td></tr>
+                {#each aPlace.keywords.name as keyword}
+                  <tr>
+                    <td>{formatKeywordToken(keyword.token)}</td>
+                    {#if keyword.id}
+                      <td>word id: {keyword.id}</td>
+                    {/if}
+                  </tr>
+                {/each}
+
+                {#if aPlace.keywords.address}
+                  <tr class="all-columns"><td colspan="6"><h3>Address Keywords</h3></td></tr>
+                  {#each aPlace.keywords.address as keyword}
+                    <tr>
+                      <td>{formatKeywordToken(keyword.token)}</td>
+                      {#if keyword.id}
+                        <td>word id: {keyword.id}</td>
+                      {/if}
+                    </tr>
+                  {/each}
+                {/if}
+              {:else}
+                <tr><td>Place has no keywords</td></tr>
+              {/if}
             {:else}
               <tr>
                 <td>
             {/if}
 
             <tr class="all-columns"><td colspan="6"><h2>Parent Of</h2></td></tr>
-            {#if aPlace.hierarchy}
+            {#if api_request_params.hierarchy}
+              {#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="6"><h3>{type}</h3></td></tr>
+                  {#each aPlace.hierarchy[type] as line}
+                    <DetailsOneRow addressLine={line} bDistanceInMeters=true />
+                 {/each}
+                {/each}
 
-              {#each Object.keys(aPlace.hierarchy) as type}
-                <tr class="all-columns"><td colspan="6"><h3>{type}</h3></td></tr>
-                {#each aPlace.hierarchy[type] as line}
-                  <DetailsOneRow addressLine={line} bDistanceInMeters=true />
-               {/each}
-              {/each}
-
-              {#if Object.keys(aPlace.hierarchy) > 500}
-                <p>There are more child objects which are not shown.</p>
+                {#if Object.keys(aPlace.hierarchy) > 500}
+                  <p>There are more child objects which are not shown.</p>
+                {/if}
+              {:else}
+                <tr><td>Place is not parent of other places</td></tr>
               {/if}
             {:else}
               <tr>
     border-top: none !important;
     padding-left: 0 !important;
   }
+  :global(span.noname){
+    color:#800;
+  }
 
   #map-wrapper {
     width:100%;