]> git.openstreetmap.org Git - nominatim-ui.git/blob - src/pages/SearchPage.svelte
remove search-url-params polyfill. Svelte doesnt support MSIE11 either
[nominatim-ui.git] / src / pages / SearchPage.svelte
1 <script>
2   import { onMount } from 'svelte';
3
4   import { results_store, current_result_store, current_request_latlon } from '../lib/stores.js';
5   import { get_config_value } from '../lib/config_reader.js'
6   import { fetch_from_api, update_html_title } from '../lib/api_utils.js';
7
8   import SearchBar from '../components/SearchBar.svelte';
9   import ResultsList from '../components/ResultsList.svelte';
10   import Map from '../components/Map.svelte';
11
12   export let reverse_search = false;
13
14   let api_request_params;
15   let bStructuredSearch;
16
17   function loaddata() {
18     let search_params = new URLSearchParams(window.location.search);
19
20     update_html_title();
21
22     if (reverse_search) {
23       api_request_params = {
24         lat: search_params.get('lat'),
25         lon: search_params.get('lon'),
26         zoom: (search_params.get('zoom') > 1
27           ? Number(search_params.get('zoom'))
28           : Number(get_config_value('Reverse_Default_Search_Zoom'))),
29         format: 'jsonv2'
30       };
31
32       if (api_request_params.lat || api_request_params.lat) {
33
34         fetch_from_api('reverse', api_request_params, function(data){
35           if (data && !data.error){
36             current_request_latlon.set([api_request_params.lat, api_request_params.lon]);
37             results_store.set([data]);
38           } else {
39             results_store.set([]);
40           }
41
42           update_html_title('Reverse result for '
43                               + api_request_params.lat
44                               + ','
45                               + api_request_params.lon);
46           document.querySelector('input[name=lat]').focus();
47         });
48       }
49     } else {
50       api_request_params = {
51         q: search_params.get('q'),
52         street: search_params.get('street'),
53         city: search_params.get('city'),
54         county: search_params.get('county'),
55         state: search_params.get('state'),
56         country: search_params.get('country'),
57         postalcode: search_params.get('postalcode'),
58         polygon_geojson: get_config_value('Search_AreaPolygons', false) ? 1 : 0,
59         viewbox: search_params.get('viewbox'),
60         bounded: search_params.get('bounded'),
61         dedupe: search_params.get('dedupe'),
62         'accept-language': search_params.get('accept-language'),
63         countrycodes: search_params.get('countrycodes'),
64         limit: search_params.get('limit'),
65         polygon_threshold: search_params.get('polygon_threshold'),
66         exclude_place_ids: search_params.get('exclude_place_ids'),
67         format: 'jsonv2'
68       };
69
70       let bStructuredSearch = (api_request_params.street ||
71                                api_request_params.city ||
72                                api_request_params.county ||
73                                api_request_params.state ||
74                                api_request_params.country ||
75                                api_request_params.postalcode);
76
77       if (api_request_params.q || bStructuredSearch) {
78         fetch_from_api('search', api_request_params, function(data){
79           results_store.set(data);
80
81           update_html_title('Result for ' + api_request_params.q);
82
83           document.querySelector('input[name=q]').focus();
84         });
85       }
86     }
87   }
88   onMount(loaddata);
89 </script>
90
91 <SearchBar reverse_search={reverse_search} api_request_params={api_request_params} bStructuredSearch={bStructuredSearch} />
92
93 <div id="content">
94   <div class="sidebar">
95     <ResultsList reverse_search={reverse_search} />
96   </div>
97   <div id="map-wrapper">
98     <Map display_minimap={true} />
99   </div>
100 </div>
101
102
103 <style>
104   .sidebar {
105     width: 25%;
106     padding: 15px;
107     padding-top: 0;
108     display: inline-block;
109     float: left;
110   }
111
112   #map-wrapper {
113     position: relative;
114     min-height: 300px;
115     height: calc(100vh - 250pt);
116     width: 75%;
117     padding-right: 20px;
118     display: inline-block;
119     float: left;
120   }
121
122   @media (max-width: 768px) {
123     #content {
124       top: 0;
125       position: relative;
126     }
127     .sidebar {
128       width: 100%;
129     }
130     #map-wrapper {
131       height: 300px;
132     }
133   }
134 </style>