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 = {};
13 function map_viewbox_as_string(map) {
14 var bounds = map.getBounds();
15 var west = bounds.getWest();
16 var east = bounds.getEast();
18 if ((east - west) >= 360) { // covers more than whole planet
19 west = map.getCenter().lng - 179.999;
20 east = map.getCenter().lng + 179.999;
22 east = L.latLng(77, east).wrap().lng;
23 west = L.latLng(77, west).wrap().lng;
26 west.toFixed(5), // left
27 bounds.getNorth().toFixed(5), // top
28 east.toFixed(5), // right
29 bounds.getSouth().toFixed(5) // bottom
33 function set_viewbox(map) {
34 let use_viewbox = document.getElementById('use_viewbox');
35 if (use_viewbox && use_viewbox.checked) {
36 sViewBox = map_viewbox_as_string(map);
42 function update_reverse_link(map) {
43 let center_lat_lng = map.wrapLatLng(map.getCenter());
44 lat = center_lat_lng.lat.toFixed(5);
45 lon = center_lat_lng.lng.toFixed(5);
48 map_store.subscribe(map => {
51 map.on('move', function () {
53 update_reverse_link(map);
56 map.on('load', function () {
58 update_reverse_link(map);
62 function reset_viewbox() {
63 let map = get(map_store);
64 if (map) { set_viewbox(map); }
67 function set_bounded(e) {
68 document.querySelector('input[name=bounded]').value = e.target.checked ? 1 : '';
71 function set_dedupe(e) {
72 document.querySelector('input[name=dedupe]').value = e.target.checked ? 1 : 0;
75 function set_api_param(e) {
76 document.querySelector('input[name=' + e.target.dataset.apiParam + ']').value = e.target.value;
80 <ul class="nav nav-tabs">
82 <a class="nav-link" class:active={!bStructuredSearch} data-bs-toggle="tab" href="#simple">
87 <a class="nav-link" class:active={bStructuredSearch} data-bs-toggle="tab" href="#structured">
93 <div class="tab-content py-2">
94 <div class="tab-pane" class:active={!bStructuredSearch} id="simple" role="tabpanel">
95 <UrlSubmitForm page="search">
96 <div class="col-auto">
100 class="form-control form-control-sm"
102 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 || ''}" />
125 <div class="tab-pane" class:active={bStructuredSearch} id="structured" role="tabpanel">
126 <UrlSubmitForm page="search">
127 <div class="col-auto">
128 <input name="street" type="text" class="form-control form-control-sm me-1"
129 placeholder="House number/Street"
130 value="{api_request_params.street || ''}" />
132 <div class="col-auto">
133 <input name="city" type="text" class="form-control form-control-sm me-1"
135 value="{api_request_params.city || ''}" />
137 <div class="col-auto">
138 <input id="county" name="county" type="text" class="form-control form-control-sm me-1"
140 value="{api_request_params.county || ''}" />
142 <div class="col-auto">
143 <input name="state" type="text" class="form-control form-control-sm me-1"
145 value="{api_request_params.state || ''}" />
147 <div class="col-auto">
148 <input name="country" type="text" class="form-control form-control-sm me-1"
149 placeholder="Country"
150 value="{api_request_params.country || ''}" />
152 <div class="col-auto">
153 <input name="postalcode" type="text" class="form-control form-control-sm me-1"
154 placeholder="Postal Code"
155 value="{api_request_params.postalcode || ''}" />
157 <div class="col-auto">
158 <button type="submit" class="btn btn-primary btn-sm">Search</button>
160 name="viewbox" value="{sViewBox || ''}" />
162 name="dedupe" value="{api_request_params.dedupe === 0 ? 0 : 1}" />
164 name="bounded" value="{api_request_params.bounded ? 1 : ''}" />
166 name="accept-language" value="{api_request_params['accept-language'] || ''}" />
168 name="countrycodes" value="{api_request_params.countrycodes || ''}"
169 pattern="^[a-zA-Z]{'{2}'}(,[a-zA-Z]{'{2}'})*$" />
171 name="limit" value="{api_request_params.limit || ''}" />
173 name="polygon_threshold" value="{api_request_params.polygon_threshold || ''}" />
177 </div> <!-- /tab-content -->
179 <!-- Additional options -->
180 <details id="searchAdvancedOptions">
181 <summary><small>Advanced options</small></summary>
184 <div class="form-check form-check-inline">
185 <label class="form-check-label" for="use_viewbox">apply viewbox</label>
186 <input type="checkbox" class="form-check-input api-param-setting"
187 id="use_viewbox" checked={api_request_params.viewbox} on:change={reset_viewbox}>
192 <div class="form-check form-check-inline">
193 <label class="form-check-label" for="option_bounded">bounded to viewbox</label>
194 <input type="checkbox" class="form-check-input api-param-setting"
195 id="option_bounded" checked={!!api_request_params.bounded} on:change={set_bounded}>
200 <div class="form-check form-check-inline">
201 <label class="form-check-label" for="option_dedupe">deduplicate results</label>
202 <input type="checkbox"
203 class="form-check-input api-param-setting"
205 checked={api_request_params.dedupe === 0 ? 0 : 1}
206 on:change={set_dedupe}>
211 <label for="option_limit">Maximum number of results</label>
213 class="form-control form-control-sm d-inline w-auto api-param-setting"
214 data-api-param="limit" id="option_limit" min="1" max="50"
215 value="{api_request_params.limit || ''}"
216 on:change={set_api_param}>
220 <label for="option_polygon_threshold">Polygon simplification</label>
222 class="form-control form-control-sm d-inline w-auto api-param-setting"
223 data-api-param="polygon_threshold" id="option_polygon_threshold"
224 min="0.0" max="1.0" step="0.001"
225 value="{api_request_params.polygon_threshold || ''}"
226 on:change={set_api_param}>
230 <label for="accept_lang">Languages</label>
231 <input type="text" placeholder="e.g. en,zh-Hant"
232 class="form-control form-control-sm d-inline w-auto api-param-setting"
233 data-api-param="accept-language" id="accept_lang" size="15"
234 value="{api_request_params['accept-language'] || ''}"
235 on:change={set_api_param}>
239 <label for="option_ccode">Country Codes</label>
240 <input type="text" placeholder="e.g. de,gb"
241 class="form-control form-control-sm d-inline w-auto api-param-setting"
242 data-api-param="countrycodes" id="option_ccode" size="15"
243 value="{api_request_params.countrycodes || ''}"
244 pattern="^[a-zA-Z]{'{2}'}(,[a-zA-Z]{'{2}'})*$"
245 on:change={set_api_param}>
257 padding: 0.1rem 1rem;
265 #searchAdvancedOptions ul {
266 list-style-type: none;
271 #searchAdvancedOptions li {
272 display: inline-block;
275 border: 1px dotted #ccc;
279 #searchAdvancedOptions label {