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}
59 <div class="result" class:highlight={iResNum === iHighlightNum} data-position="{iResNum}" on:click|stopPropagation={handleClick}>
60 <div style="float:right">
61 <MapIcon aPlace={aResult} />
63 <span class="name">{aResult.display_name}</span>
64 <span class="type">{formatLabel(aResult)}</span>
65 <p class="coords">{aResult.lat},{aResult.lon}</p>
67 <DetailsLink extra_classes="btn btn-outline-secondary btn-sm" feature={aResult}>details</DetailsLink>
71 {#if sMoreURL && !reverse_search}
73 <a class="btn btn-primary" href="{sMoreURL}">
74 Search for more results
79 {:else if aSearchResults}
81 <div id="intro" class="sidebar">Search for coordinates or click anywhere on the map.</div>
83 <div class="noresults">No search results found</div>
97 border: 2px solid #D7E7FF;
103 background-color: #D9E7F7;
104 border-color: #9DB9E4;
106 .result.highlight :global(a) {
111 background-color: white;
135 .result.highlight :global(a):hover {