2 import UrlSubmitForm from '../components/UrlSubmitForm.svelte';
4 import { map_store } from '../lib/stores.js';
5 import { get } from 'svelte/store';
7 export let bStructuredSearch = false;
8 export let api_request_params = {};
10 // lat,lon are later set in update_reverse_link()
11 let lat; // eslint-disable-line no-unused-vars
12 let lon; // eslint-disable-line no-unused-vars
14 function map_viewbox_as_string(map) {
15 var bounds = map.getBounds();
16 var west = bounds.getWest();
17 var east = bounds.getEast();
19 if ((east - west) >= 360) { // covers more than whole planet
20 west = map.getCenter().lng - 179.999;
21 east = map.getCenter().lng + 179.999;
23 east = L.latLng(77, east).wrap().lng;
24 west = L.latLng(77, west).wrap().lng;
27 west.toFixed(5), // left
28 bounds.getNorth().toFixed(5), // top
29 east.toFixed(5), // right
30 bounds.getSouth().toFixed(5) // bottom
34 function set_viewbox(map) {
35 let use_viewbox = document.getElementById('use_viewbox');
36 if (use_viewbox && use_viewbox.checked) {
37 sViewBox = map_viewbox_as_string(map);
43 function update_reverse_link(map) {
44 let center_lat_lng = map.wrapLatLng(map.getCenter());
45 lat = center_lat_lng.lat.toFixed(5);
46 lon = center_lat_lng.lng.toFixed(5);
49 map_store.subscribe(map => {
52 map.on('move', function () {
54 update_reverse_link(map);
57 map.on('load', function () {
59 update_reverse_link(map);
63 function reset_viewbox() {
64 let map = get(map_store);
65 if (map) { set_viewbox(map); }
68 function set_bounded(e) {
69 document.querySelector('input[name=bounded]').value = e.target.checked ? 1 : '';
72 function set_dedupe(e) {
73 document.querySelector('input[name=dedupe]').value = e.target.checked ? 1 : 0;
76 function set_api_param(e) {
77 document.querySelector('input[name=' + e.target.dataset.apiParam + ']').value = e.target.value;
81 <ul class="nav nav-tabs">
83 <a class="nav-link" class:active={!bStructuredSearch} data-bs-toggle="tab" href="#simple">
88 <a class="nav-link" class:active={bStructuredSearch} data-bs-toggle="tab" href="#structured">
94 <div class="tab-content py-2">
95 <div class="tab-pane" class:active={!bStructuredSearch} id="simple" role="tabpanel">
96 <UrlSubmitForm page="search">
97 <div class="col-auto">
101 class="form-control form-control-sm"
103 value="{api_request_params.q || ''}" />
105 <div class="col-auto">
106 <button type="submit" class="btn btn-primary btn-sm mx-1">Search</button>
108 name="viewbox" value="{sViewBox || ''}" />
110 name="dedupe" value="{api_request_params.dedupe === 0 ? 0 : 1}" />
112 name="bounded" value="{api_request_params.bounded ? 1 : ''}" />
114 name="accept-language"value="{api_request_params['accept-language'] || ''}" />
116 name="countrycodes" value="{api_request_params.countrycodes || ''}"
117 pattern="^[a-zA-Z]{'{2}'}(,[a-zA-Z]{'{2}'})*$" />
119 name="limit" value="{api_request_params.limit || ''}" />
121 name="polygon_threshold" value="{api_request_params.polygon_threshold || ''}" />
123 name="layer" value="{api_request_params.layer || ''}" />
127 <div class="tab-pane" class:active={bStructuredSearch} id="structured" role="tabpanel">
128 <UrlSubmitForm page="search">
129 <div class="col-auto">
130 <input name="street" type="text" class="form-control form-control-sm me-1"
131 placeholder="House number/Street"
132 value="{api_request_params.street || ''}" />
134 <div class="col-auto">
135 <input name="city" type="text" class="form-control form-control-sm me-1"
137 value="{api_request_params.city || ''}" />
139 <div class="col-auto">
140 <input id="county" name="county" type="text" class="form-control form-control-sm me-1"
142 value="{api_request_params.county || ''}" />
144 <div class="col-auto">
145 <input name="state" type="text" class="form-control form-control-sm me-1"
147 value="{api_request_params.state || ''}" />
149 <div class="col-auto">
150 <input name="country" type="text" class="form-control form-control-sm me-1"
151 placeholder="Country"
152 value="{api_request_params.country || ''}" />
154 <div class="col-auto">
155 <input name="postalcode" type="text" class="form-control form-control-sm me-1"
156 placeholder="Postal Code"
157 value="{api_request_params.postalcode || ''}" />
159 <div class="col-auto">
160 <button type="submit" class="btn btn-primary btn-sm">Search</button>
162 name="viewbox" value="{sViewBox || ''}" />
164 name="dedupe" value="{api_request_params.dedupe === 0 ? 0 : 1}" />
166 name="bounded" value="{api_request_params.bounded ? 1 : ''}" />
168 name="accept-language" value="{api_request_params['accept-language'] || ''}" />
170 name="countrycodes" value="{api_request_params.countrycodes || ''}"
171 pattern="^[a-zA-Z]{'{2}'}(,[a-zA-Z]{'{2}'})*$" />
173 name="limit" value="{api_request_params.limit || ''}" />
175 name="polygon_threshold" value="{api_request_params.polygon_threshold || ''}" />
177 name="layer" value="{api_request_params.layer || ''}" />
181 </div> <!-- /tab-content -->
183 <!-- Additional options -->
184 <details id="searchAdvancedOptions">
185 <summary><small>Advanced options</small></summary>
188 <div class="form-check form-check-inline">
189 <label class="form-check-label" for="use_viewbox">apply viewbox</label>
190 <input type="checkbox" class="form-check-input api-param-setting"
191 id="use_viewbox" checked={api_request_params.viewbox} on:change={reset_viewbox}>
196 <div class="form-check form-check-inline">
197 <label class="form-check-label" for="option_bounded">bounded to viewbox</label>
198 <input type="checkbox" class="form-check-input api-param-setting"
199 id="option_bounded" checked={!!api_request_params.bounded} on:change={set_bounded}>
204 <div class="form-check form-check-inline">
205 <label class="form-check-label" for="option_dedupe">deduplicate results</label>
206 <input type="checkbox"
207 class="form-check-input api-param-setting"
209 checked={api_request_params.dedupe === 0 ? 0 : 1}
210 on:change={set_dedupe}>
215 <label for="option_limit">Maximum number of results</label>
217 class="form-control form-control-sm d-inline w-auto api-param-setting"
218 data-api-param="limit" id="option_limit" min="1" max="50"
219 value="{api_request_params.limit || ''}"
220 on:change={set_api_param}>
224 <label for="option_polygon_threshold">Polygon simplification</label>
226 class="form-control form-control-sm d-inline w-auto api-param-setting"
227 data-api-param="polygon_threshold" id="option_polygon_threshold"
228 min="0.0" max="1.0" step="0.001"
229 value="{api_request_params.polygon_threshold || ''}"
230 on:change={set_api_param}>
234 <label for="accept_lang">Languages</label>
235 <input type="text" placeholder="e.g. en,zh-Hant"
236 class="form-control form-control-sm d-inline w-auto api-param-setting"
237 data-api-param="accept-language" id="accept_lang" size="15"
238 value="{api_request_params['accept-language'] || ''}"
239 on:change={set_api_param}>
243 <label for="option_ccode">Country Codes</label>
244 <input type="text" placeholder="e.g. de,gb"
245 class="form-control form-control-sm d-inline w-auto api-param-setting"
246 data-api-param="countrycodes" id="option_ccode" size="15"
247 value="{api_request_params.countrycodes || ''}"
248 pattern="^[a-zA-Z]{'{2}'}(,[a-zA-Z]{'{2}'})*$"
249 on:change={set_api_param}>
252 <label for="option_layer">Layer</label>
253 <input id="option_layer" name="layer" placeholder="e.g. address,poi,railway,natural,manmade"
254 value="{api_request_params.layer || ''}"
255 data-api-param="layer" on:change={set_api_param}
256 class="form-control form-control-sm d-inline w-auto api-param-setting">
268 padding: 0.1rem 1rem;
276 #searchAdvancedOptions ul {
277 list-style-type: none;
282 #searchAdvancedOptions li {
283 display: inline-block;
286 border: 1px dotted #ccc;
290 #searchAdvancedOptions label {