2 import { formatLabel } from '../lib/helpers.js';
3 import { SvelteURLSearchParams } from 'svelte/reactivity';
5 import DetailsLink from './DetailsLink.svelte';
6 import Welcome from './Welcome.svelte';
7 import MapIcon from './MapIcon.svelte';
9 let { results, reverse_search = false, current_result = $bindable() } = $props();
11 let iHighlightNum = $state();
13 let sMoreURL = $derived.by(() => {
14 const search_params = new URLSearchParams(window.location.search);
15 const aResults = results;
16 // lonvia wrote: https://github.com/osm-search/nominatim-ui/issues/24
17 // I would suggest to remove the guessing and always show the link. Nominatim only returns
18 // one or two results when it believes the result to be a good enough match.
19 // if (aResults.length >= 10) {
20 let aExcludePlaceIds = [];
21 if (search_params.has('exclude_place_ids')) {
22 aExcludePlaceIds = search_params.get('exclude_place_ids').split(',');
24 for (var i = 0; i < aResults.length; i += 1) {
25 aExcludePlaceIds.push(aResults[i].place_id);
27 var parsed_url = new SvelteURLSearchParams(window.location.search);
28 parsed_url.set('exclude_place_ids', aExcludePlaceIds.join(','));
29 return '?' + parsed_url.toString();
32 function handleClick(e) {
34 let result_el = e.target;
35 if (!result_el.className.match('result')) {
36 result_el = result_el.parentElement;
38 let pos = Number(result_el.dataset.position);
50 current_result = (results && results.length > iHighlightNum) ? results[iHighlightNum] : null;
55 {#if results && results.length > 0}
56 <div id="searchresults" role="list">
58 {#each results as aResult, iResNum}
59 <!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
61 class:highlight={iResNum === iHighlightNum}
63 data-position="{iResNum}"
65 onkeypress={handleClick}>
66 <div style="float:right">
67 <MapIcon aPlace={aResult} />
69 <span class="name">{aResult.display_name}</span>
70 <span class="type">{formatLabel(aResult)}</span>
71 <p class="coords">{aResult.lat},{aResult.lon}</p>
73 <DetailsLink extra_classes="btn btn-outline-secondary btn-sm" feature={aResult} />
77 {#if sMoreURL && !reverse_search}
79 <a class="btn btn-primary" href="{sMoreURL}">
80 Search for more results
87 <div id="intro" class="sidebar">Search for coordinates or click anywhere on the map.</div>
89 <div class="noresults">No search results found</div>
102 background: var(--bs-secondary-bg);
103 border: 1px solid var(--bs-secondary-color);
109 background-color: var(--bs-primary-bg-subtle);
110 border-color: var(--bs-primary-color-subtle);
112 .result.highlight :global(a) {
117 color: var(--bs-secondary-color);
118 background-color: var(--bs-secondary-bg);
121 color: var(--bs-secondary-color);
142 .result.highlight :global(a):hover {
143 background-color: var(--bs-primary-bg-subtle);