2 import { results_store } from '../lib/stores.js';
3 import { formatLabel } from '../lib/helpers.js';
5 import DetailsLink from './DetailsLink.svelte';
6 import Welcome from './Welcome.svelte';
7 import MapIcon from './MapIcon.svelte';
9 export let reverse_search = false;
10 export let current_result = null;
16 results_store.subscribe(data => {
17 if (!data) { return; }
18 aSearchResults = data;
20 current_result = aSearchResults[0];
23 let search_params = new URLSearchParams(window.location.search);
26 // lonvia wrote: https://github.com/osm-search/nominatim-ui/issues/24
27 // I would suggest to remove the guessing and always show the link. Nominatim only returns
28 // one or two results when it believes the result to be a good enough match.
29 // if (aResults.length >= 10) {
30 var aExcludePlaceIds = [];
31 if (search_params.has('exclude_place_ids')) {
32 aExcludePlaceIds = search_params.get('exclude_place_ids').split(',');
34 for (var i = 0; i < aResults.length; i += 1) {
35 aExcludePlaceIds.push(aResults[i].place_id);
37 var parsed_url = new URLSearchParams(window.location.search);
38 parsed_url.set('exclude_place_ids', aExcludePlaceIds.join(','));
39 sMoreURL = '?' + parsed_url.toString();
42 function handleClick(e) {
43 let result_el = e.target;
44 if (!result_el.className.match('result')) {
45 result_el = result_el.parentElement;
47 let pos = Number(result_el.dataset.position);
49 current_result = aSearchResults[pos];
55 {#if aSearchResults && aSearchResults.length > 0}
56 <div id="searchresults">
58 {#each aSearchResults as aResult, iResNum}
60 class:highlight={iResNum === iHighlightNum}
61 data-position="{iResNum}"
62 on:click|stopPropagation={handleClick}
63 on:keypress|stopPropagation={handleClick}>
64 <div style="float:right">
65 <MapIcon aPlace={aResult} />
67 <span class="name">{aResult.display_name}</span>
68 <span class="type">{formatLabel(aResult)}</span>
69 <p class="coords">{aResult.lat},{aResult.lon}</p>
71 <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
85 {:else if aSearchResults}
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>
103 border: 2px solid #D7E7FF;
109 background-color: #D9E7F7;
110 border-color: #9DB9E4;
112 .result.highlight :global(a) {
117 background-color: white;
141 .result.highlight :global(a):hover {