2 import { results_store } from '../lib/stores.js';
3 import { formatLabel, detailsURL } from '../lib/helpers.js';
5 import Welcome from './Welcome.svelte';
6 import MapIcon from './MapIcon.svelte';
8 export let reverse_search = false;
9 export let current_result = {};
15 results_store.subscribe(data => {
16 if (!data) { return; }
17 aSearchResults = data;
19 current_result = aSearchResults[0];
22 let search_params = new URLSearchParams(window.location.search);
25 // lonvia wrote: https://github.com/osm-search/nominatim-ui/issues/24
26 // I would suggest to remove the guessing and always show the link. Nominatim only returns
27 // one or two results when it believes the result to be a good enough match.
28 // if (aResults.length >= 10) {
29 var aExcludePlaceIds = [];
30 if (search_params.has('exclude_place_ids')) {
31 aExcludePlaceIds = search_params.get('exclude_place_ids').split(',');
33 for (var i = 0; i < aResults.length; i += 1) {
34 aExcludePlaceIds.push(aResults[i].place_id);
36 var parsed_url = new URLSearchParams(window.location.search);
37 parsed_url.set('exclude_place_ids', aExcludePlaceIds.join(','));
38 sMoreURL = '?' + parsed_url.toString();
41 function handleClick(e) {
42 let result_el = e.target;
43 if (!result_el.className.match('result')) {
44 result_el = result_el.parentElement;
46 let pos = Number(result_el.dataset.position);
48 current_result = aSearchResults[pos];
54 {#if aSearchResults && aSearchResults.length > 0}
55 <div id="searchresults">
57 {#each aSearchResults as aResult, iResNum}
58 <div class="result" class:highlight={iResNum === iHighlightNum} data-position="{iResNum}" on:click|stopPropagation={handleClick}>
59 <div style="float:right">
60 <MapIcon aPlace={aResult} />
62 <span class="name">{aResult.display_name}</span>
63 <span class="type">{formatLabel(aResult)}</span>
64 <p class="coords">{aResult.lat},{aResult.lon}</p>
66 <a class="details btn btn-outline-secondary btn-sm" href="{detailsURL(aResult)}">details</a>
70 {#if sMoreURL && !reverse_search}
72 <a class="btn btn-primary" href="{sMoreURL}">
73 Search for more results
78 {:else if aSearchResults}
80 <div id="intro" class="sidebar">Search for coordinates or click anywhere on the map.</div>
82 <div class="noresults">No search results found</div>
96 border: 2px solid #D7E7FF;
102 background-color: #D9E7F7;
103 border-color: #9DB9E4;
105 .result.highlight .details {
133 .btn-outline-secondary {
134 background-color: white;
137 .btn-outline-secondary:hover {