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 : '';
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-toggle="tab" href="#simple">Simple</a>
85 <a class="nav-link" class:active={bStructuredSearch} data-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">
95 class="form-control form-control-sm"
97 value="{api_request_params.q || ''}" />
99 <button type="submit" class="btn btn-primary btn-sm mx-1">Search</button>
100 <input type="hidden" name="viewbox" value="{sViewBox || ''}" />
101 <input type="hidden" name="dedupe" value="{!api_request_params.dedupe ? '' : 1}" />
102 <input type="hidden" name="bounded" value="{api_request_params.bounded ? 1 : ''}" />
103 <input type="hidden" name="accept-language" value="{api_request_params['accept-language'] || ''}" />
104 <input type="hidden" name="countrycodes" value="{api_request_params.countrycodes || ''}" />
105 <input type="hidden" name="limit" value="{api_request_params.limit || ''}" />
106 <input type="hidden" name="polygon_threshold" value="{api_request_params.polygon_threshold || ''}" />
109 <div class="tab-pane" class:active={bStructuredSearch} id="structured" role="tabpanel">
110 <UrlSubmitForm page="search">
111 <input name="street" type="text" class="form-control form-control-sm mr-1"
112 placeholder="House number/Street"
113 value="{api_request_params.street || ''}" />
114 <input name="city" type="text" class="form-control form-control-sm mr-1"
116 value="{api_request_params.city || ''}" />
117 <input id="county" name="county" type="text" class="form-control form-control-sm mr-1"
119 value="{api_request_params.county || ''}" />
120 <input name="state" type="text" class="form-control form-control-sm mr-1"
122 value="{api_request_params.state || ''}" />
123 <input name="country" type="text" class="form-control form-control-sm mr-1"
124 placeholder="Country"
125 value="{api_request_params.country || ''}" />
126 <input name="postalcode" type="text" class="form-control form-control-sm mr-1"
127 placeholder="Postal Code"
128 value="{api_request_params.postalcode || ''}" />
130 <button type="submit" class="btn btn-primary btn-sm">Search</button>
131 <input type="hidden" name="viewbox" value="{sViewBox || ''}" />
132 <input type="hidden" name="dedupe" value="{!api_request_params.dedupe ? '' : 1}" />
133 <input type="hidden" name="bounded" value="{api_request_params.bounded ? 1 : ''}" />
134 <input type="hidden" name="accept-language" value="{api_request_params['accept-language'] || ''}" />
135 <input type="hidden" name="countrycodes" value="{api_request_params.countrycodes || ''}" />
136 <input type="hidden" name="limit" value="{api_request_params.limit || ''}" />
137 <input type="hidden" name="polygon_threshold" value="{api_request_params.polygon_threshold || ''}" />
140 </div> <!-- /tab-content -->
142 <!-- Additional options -->
143 <details id="searchAdvancedOptions">
144 <summary><small>Advanced options</small></summary>
147 <div class="form-check form-check-inline">
148 <label class="form-check-label" for="use_viewbox">apply viewbox</label>
149 <input type="checkbox" class="form-check-input api-param-setting"
150 id="use_viewbox" checked={api_request_params.viewbox} on:change={reset_viewbox}>
155 <div class="form-check form-check-inline">
156 <label class="form-check-label" for="option_bounded">bounded to viewbox</label>
157 <input type="checkbox" class="form-check-input api-param-setting"
158 id="option_bounded" checked={!!api_request_params.bounded} on:change={set_bounded}>
163 <div class="form-check form-check-inline">
164 <label class="form-check-label" for="option_dedupe">deduplicate results</label>
165 <input type="checkbox" class="form-check-input api-param-setting"
166 id="option_dedupe" checked={!!api_request_params.dedupe} on:change={set_dedupe}>
171 <label for="option_limit">Maximum number of results</label>
172 <input type="number" class="form-control form-control-sm d-inline w-auto api-param-setting"
173 data-api-param="limit" id="option_limit" size="5" min="1" max="50"
174 value="{api_request_params.limit || ''}"
175 on:change={set_api_param}>
179 <label for="option_polygon_threshold">Polygon simplification</label>
180 <input type="number" class="form-control form-control-sm d-inline w-auto api-param-setting"
181 data-api-param="polygon_threshold" id="option_polygon_threshold" size="5" min="0.0" step="0.01"
182 value="{api_request_params.polygon_threshold || ''}"
183 on:change={set_api_param}>
187 <label for="accept_lang">Languages</label>
188 <input type="text" placeholder="e.g. en,zh-Hant" class="form-control form-control-sm d-inline w-auto api-param-setting"
189 data-api-param="accept-language" id="accept_lang" size="15"
190 value="{api_request_params['accept-language'] || ''}"
191 on:change={set_api_param}>
195 <label for="option_ccode">Countries</label>
196 <input type="text" placeholder="e.g. de,gb" class="form-control form-control-sm d-inline w-auto api-param-setting"
197 data-api-param="countrycodes" id="option_ccode" size="15"
198 value="{api_request_params.countrycodes || ''}"
199 on:change={set_api_param}>
211 padding: 0.1rem 1rem;
219 #searchAdvancedOptions ul {
220 list-style-type: none;
225 #searchAdvancedOptions li {
226 display: inline-block;
229 border: 1px dotted #ccc;
233 #searchAdvancedOptions label {