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">Simple</a>
85 <a class="nav-link" class:active={bStructuredSearch} data-bs-toggle="tab" href="#structured">Structured</a>
89 <div class="tab-content py-2">
90 <div class="tab-pane" class:active={!bStructuredSearch} id="simple" role="tabpanel">
91 <UrlSubmitForm page="search">
92 <div class="col-auto">
96 class="form-control form-control-sm"
98 value="{api_request_params.q || ''}"
101 <div class="col-auto">
102 <button type="submit" class="btn btn-primary btn-sm mx-1">Search</button>
103 <input type="hidden" name="viewbox" value="{sViewBox || ''}" />
104 <input type="hidden" name="dedupe" value="{api_request_params.dedupe === 0 ? 0 : 1}" />
105 <input type="hidden" name="bounded" value="{api_request_params.bounded ? 1 : ''}" />
106 <input type="hidden" name="accept-language" value="{api_request_params['accept-language'] || ''}" />
107 <input type="hidden" name="countrycodes" value="{api_request_params.countrycodes || ''}"
108 pattern="^[a-zA-Z]{'{2}'}(,[a-zA-Z]{'{2}'})*$" />
109 <input type="hidden" name="limit" value="{api_request_params.limit || ''}" />
110 <input type="hidden" name="polygon_threshold" value="{api_request_params.polygon_threshold || ''}" />
114 <div class="tab-pane" class:active={bStructuredSearch} id="structured" role="tabpanel">
115 <UrlSubmitForm page="search">
116 <div class="col-auto">
117 <input name="street" type="text" class="form-control form-control-sm me-1"
118 placeholder="House number/Street"
119 value="{api_request_params.street || ''}" />
121 <div class="col-auto">
122 <input name="city" type="text" class="form-control form-control-sm me-1"
124 value="{api_request_params.city || ''}" />
126 <div class="col-auto">
127 <input id="county" name="county" type="text" class="form-control form-control-sm me-1"
129 value="{api_request_params.county || ''}" />
131 <div class="col-auto">
132 <input name="state" type="text" class="form-control form-control-sm me-1"
134 value="{api_request_params.state || ''}" />
136 <div class="col-auto">
137 <input name="country" type="text" class="form-control form-control-sm me-1"
138 placeholder="Country"
139 value="{api_request_params.country || ''}" />
141 <div class="col-auto">
142 <input name="postalcode" type="text" class="form-control form-control-sm me-1"
143 placeholder="Postal Code"
144 value="{api_request_params.postalcode || ''}" />
146 <div class="col-auto">
147 <button type="submit" class="btn btn-primary btn-sm">Search</button>
148 <input type="hidden" name="viewbox" value="{sViewBox || ''}" />
149 <input type="hidden" name="dedupe" value="{api_request_params.dedupe === 0 ? 0 : 1}" />
150 <input type="hidden" name="bounded" value="{api_request_params.bounded ? 1 : ''}" />
151 <input type="hidden" name="accept-language" value="{api_request_params['accept-language'] || ''}" />
152 <input type="hidden" name="countrycodes" value="{api_request_params.countrycodes || ''}"
153 pattern="^[a-zA-Z]{'{2}'}(,[a-zA-Z]{'{2}'})*$" />
154 <input type="hidden" name="limit" value="{api_request_params.limit || ''}" />
155 <input type="hidden" name="polygon_threshold" value="{api_request_params.polygon_threshold || ''}" />
159 </div> <!-- /tab-content -->
161 <!-- Additional options -->
162 <details id="searchAdvancedOptions">
163 <summary><small>Advanced options</small></summary>
166 <div class="form-check form-check-inline">
167 <label class="form-check-label" for="use_viewbox">apply viewbox</label>
168 <input type="checkbox" class="form-check-input api-param-setting"
169 id="use_viewbox" checked={api_request_params.viewbox} on:change={reset_viewbox}>
174 <div class="form-check form-check-inline">
175 <label class="form-check-label" for="option_bounded">bounded to viewbox</label>
176 <input type="checkbox" class="form-check-input api-param-setting"
177 id="option_bounded" checked={!!api_request_params.bounded} on:change={set_bounded}>
182 <div class="form-check form-check-inline">
183 <label class="form-check-label" for="option_dedupe">deduplicate results</label>
184 <input type="checkbox" class="form-check-input api-param-setting"
185 id="option_dedupe" checked={api_request_params.dedupe === 0 ? 0 : 1} on:change={set_dedupe}>
190 <label for="option_limit">Maximum number of results</label>
191 <input type="number" class="form-control form-control-sm d-inline w-auto api-param-setting"
192 data-api-param="limit" id="option_limit" min="1" max="50"
193 value="{api_request_params.limit || ''}"
194 on:change={set_api_param}>
198 <label for="option_polygon_threshold">Polygon simplification</label>
199 <input type="number" class="form-control form-control-sm d-inline w-auto api-param-setting"
200 data-api-param="polygon_threshold" id="option_polygon_threshold" min="0.0" max="1.0" step="0.001"
201 value="{api_request_params.polygon_threshold || ''}"
202 on:change={set_api_param}>
206 <label for="accept_lang">Languages</label>
207 <input type="text" placeholder="e.g. en,zh-Hant" class="form-control form-control-sm d-inline w-auto api-param-setting"
208 data-api-param="accept-language" id="accept_lang" size="15"
209 value="{api_request_params['accept-language'] || ''}"
210 on:change={set_api_param}>
214 <label for="option_ccode">Country Codes</label>
215 <input type="text" placeholder="e.g. de,gb" class="form-control form-control-sm d-inline w-auto api-param-setting"
216 data-api-param="countrycodes" id="option_ccode" size="15"
217 value="{api_request_params.countrycodes || ''}"
218 pattern="^[a-zA-Z]{'{2}'}(,[a-zA-Z]{'{2}'})*$"
219 on:change={set_api_param}>
231 padding: 0.1rem 1rem;
239 #searchAdvancedOptions ul {
240 list-style-type: none;
245 #searchAdvancedOptions li {
246 display: inline-block;
249 border: 1px dotted #ccc;
253 #searchAdvancedOptions label {