2 import { onMount, onDestroy } from 'svelte';
5 page, results_store, current_request_latlon
6 } from '../lib/stores.js';
7 import { get_config_value } from '../lib/config_reader.js';
8 import { fetch_from_api, update_html_title } from '../lib/api_utils.js';
10 import SearchBar from '../components/SearchBar.svelte';
11 import ResultsList from '../components/ResultsList.svelte';
12 import Map from '../components/Map.svelte';
14 export let reverse_search = false;
16 let api_request_params;
17 let bStructuredSearch;
20 let search_params = new URLSearchParams(window.location.search);
25 api_request_params = {
26 lat: search_params.get('lat'),
27 lon: search_params.get('lon'),
28 zoom: (search_params.get('zoom') > 1
29 ? Number(search_params.get('zoom'))
30 : Number(get_config_value('Reverse_Default_Search_Zoom'))),
34 if (api_request_params.lat || api_request_params.lat) {
36 fetch_from_api('reverse', api_request_params, function (data) {
37 if (data && !data.error) {
38 current_request_latlon.set([api_request_params.lat, api_request_params.lon]);
39 results_store.set([data]);
41 results_store.set([]);
44 update_html_title('Reverse result for '
45 + api_request_params.lat
47 + api_request_params.lon);
48 document.querySelector('input[name=lat]').focus();
52 api_request_params = {
53 q: search_params.get('q'),
54 street: search_params.get('street'),
55 city: search_params.get('city'),
56 county: search_params.get('county'),
57 state: search_params.get('state'),
58 country: search_params.get('country'),
59 postalcode: search_params.get('postalcode'),
60 polygon_geojson: get_config_value('Search_AreaPolygons', false) ? 1 : 0,
61 viewbox: search_params.get('viewbox'),
62 bounded: search_params.get('bounded'),
63 dedupe: search_params.get('dedupe'),
64 'accept-language': search_params.get('accept-language'),
65 countrycodes: search_params.get('countrycodes'),
66 limit: search_params.get('limit'),
67 polygon_threshold: search_params.get('polygon_threshold'),
68 exclude_place_ids: search_params.get('exclude_place_ids'),
72 let anyStructuredFieldsSet = (api_request_params.street
73 || api_request_params.city
74 || api_request_params.county
75 || api_request_params.state
76 || api_request_params.country
77 || api_request_params.postalcode);
79 if (api_request_params.q || anyStructuredFieldsSet) {
80 fetch_from_api('search', api_request_params, function (data) {
81 results_store.set(data);
83 update_html_title('Result for ' + api_request_params.q);
85 document.querySelector('input[name=q]').focus();
91 let page_subscription;
92 onMount(() => { page_subscription = page.subscribe(loaddata); });
93 onDestroy(() => { page_subscription(); });
96 <SearchBar reverse_search={reverse_search} api_request_params={api_request_params} bStructuredSearch={bStructuredSearch} />
100 <ResultsList reverse_search={reverse_search} />
102 <div id="map-wrapper">
103 <Map display_minimap={true} />
113 display: inline-block;
120 height: calc(100vh - 250pt);
123 display: inline-block;
127 @media (max-width: 768px) {