2 import UrlSubmitForm from '../components/UrlSubmitForm.svelte';
3 import DetailsLink from '../components/DetailsLink.svelte';
4 import ReverseLink from '../components/ReverseLink.svelte';
6 import { map_store } from '../lib/stores.js';
7 import { get } from 'svelte/store';
9 export let bStructuredSearch = false;
10 export let api_request_params = {};
15 function map_viewbox_as_string(map) {
16 var bounds = map.getBounds();
17 var west = bounds.getWest();
18 var east = bounds.getEast();
20 if ((east - west) >= 360) { // covers more than whole planet
21 west = map.getCenter().lng - 179.999;
22 east = map.getCenter().lng + 179.999;
24 east = L.latLng(77, east).wrap().lng;
25 west = L.latLng(77, west).wrap().lng;
28 west.toFixed(5), // left
29 bounds.getNorth().toFixed(5), // top
30 east.toFixed(5), // right
31 bounds.getSouth().toFixed(5) // bottom
35 function set_viewbox(map) {
36 let use_viewbox = document.getElementById('use_viewbox');
37 if (use_viewbox && use_viewbox.checked) {
38 sViewBox = map_viewbox_as_string(map);
44 function update_reverse_link(map) {
45 let center_lat_lng = map.wrapLatLng(map.getCenter());
46 lat = center_lat_lng.lat.toFixed(5);
47 lon = center_lat_lng.lng.toFixed(5);
50 map_store.subscribe(map => {
53 map.on('move', function () {
55 update_reverse_link(map);
58 map.on('load', function () {
60 update_reverse_link(map);
64 function reset_viewbox() {
65 let map = get(map_store);
66 if (map) { set_viewbox(map); }
69 function set_bounded(e) {
70 console.log('setting', e.target);
71 document.querySelector('input[name=bounded]').value = e.target.checked ? 1 : '';
74 function set_dedupe(e) {
75 document.querySelector('input[name=dedupe]').value = e.target.checked ? 1 : '';
78 function set_api_param(e) {
79 document.querySelector('input[name=' + e.target.dataset.apiParam + ']').value = e.target.value;
84 <ul class="nav nav-tabs">
86 <a class="nav-link" class:active={!bStructuredSearch} data-toggle="tab" href="#simple">simple</a>
89 <a class="nav-link" class:active={bStructuredSearch} data-toggle="tab" href="#structured">structured</a>
91 <div class="search-type-link">
92 <DetailsLink extra_classes="mr-2">search by id</DetailsLink>
93 <ReverseLink lat={lat} lon={lon}>reverse search</ReverseLink>
96 <div class="tab-content p-2">
97 <div class="tab-pane" class:active={!bStructuredSearch} id="simple" role="tabpanel">
102 class="form-control form-control-sm"
104 value="{api_request_params.q || ''}" />
106 <div class="form-group search-button-group">
107 <button type="submit" class="btn btn-primary btn-sm mx-1">Search</button>
108 <input type="hidden" name="viewbox" value="{sViewBox || ''}" />
109 <input type="hidden" name="dedupe" value="{!api_request_params.dedupe ? '' : 1}" />
110 <input type="hidden" name="bounded" value="{api_request_params.bounded ? 1 : ''}" />
111 <input type="hidden" name="accept-language" value="{api_request_params['accept-language'] || ''}" />
112 <input type="hidden" name="countrycodes" value="{api_request_params.countrycodes || ''}" />
113 <input type="hidden" name="limit" value="{api_request_params.limit || ''}" />
114 <input type="hidden" name="polygon_threshold" value="{api_request_params.polygon_threshold || ''}" />
118 <div class="tab-pane" class:active={bStructuredSearch} id="structured" role="tabpanel">
120 <input name="street" type="text" class="form-control form-control-sm mr-1"
121 placeholder="House number/Street"
122 value="{api_request_params.street || ''}" />
123 <input name="city" type="text" class="form-control form-control-sm mr-1"
125 value="{api_request_params.city || ''}" />
126 <input id="county" name="county" type="text" class="form-control form-control-sm mr-1"
128 value="{api_request_params.county || ''}" />
129 <input name="state" type="text" class="form-control form-control-sm mr-1"
131 value="{api_request_params.state || ''}" />
132 <input name="country" type="text" class="form-control form-control-sm mr-1"
133 placeholder="Country"
134 value="{api_request_params.country || ''}" />
135 <input name="postalcode" type="text" class="form-control form-control-sm mr-1"
136 placeholder="Postal Code"
137 value="{api_request_params.postalcode || ''}" />
139 <div class="form-group search-button-group">
140 <button type="submit" class="btn btn-primary btn-sm mx-1">Search</button>
141 <input type="hidden" name="viewbox" value="{sViewBox || ''}" />
142 <input type="hidden" name="dedupe" value="{!api_request_params.dedupe ? '' : 1}" />
143 <input type="hidden" name="bounded" value="{api_request_params.bounded ? 1 : ''}" />
144 <input type="hidden" name="accept-language" value="{api_request_params['accept-language'] || ''}" />
145 <input type="hidden" name="countrycodes" value="{api_request_params.countrycodes || ''}" />
146 <input type="hidden" name="limit" value="{api_request_params.limit || ''}" />
147 <input type="hidden" name="polygon_threshold" value="{api_request_params.polygon_threshold || ''}" />
151 <!-- Additional options -->
152 <a href="#advanced" class="btn btn-outline-secondary btn-sm" data-toggle="collapse" data-target="#searchAdvancedOptions" role="button" aria-expanded="false" aria-controls="collapseAdvancedOptions">
155 <div class="collapse" id="searchAdvancedOptions">
156 <div id="searchAdvancedOptionsContent">
157 <div class="form-check form-check-inline">
158 <span><input type="checkbox" class="form-check-input api-param-setting"
159 id="use_viewbox" checked={api_request_params.viewbox} on:change={reset_viewbox}>
160 <label class="form-check-label" for="use_viewbox">apply viewbox</label></span>
161 <span><input type="checkbox" class="form-check-input api-param-setting"
162 id="option_bounded" checked={!!api_request_params.bounded} on:change={set_bounded}>
163 <label class="form-check-label" for="option_bounded">bounded to viewbox</label></span>
164 <span><input type="checkbox" class="form-check-input api-param-setting"
165 id="option_dedupe" checked={!!api_request_params.dedupe} on:change={set_dedupe}>
166 <label class="form-check-label" for="option_dedupe">deduplicate results</label></span>
168 <div class="form-check form-check-inline">
169 <span><label class="form-check-label" for="option_limit">Maximum number of results: </label>
170 <input type="number" class="form-check-input api-param-setting" data-api-param="limit" id="option_limit" size="5" min="1" max="50" value="{api_request_params.limit || ''}" on:change={set_api_param}></span>
171 <span><label class="form-check-label" for="option_polygon_threashold">Polygon simplification: </label>
172 <input type="number" class="form-check-input api-param-setting" data-api-param="polygon_threshold" id="option_polygon_threshold" size="5" min="0.0" step="0.01" value="{api_request_params.polygon_threshold || ''}" on:change={set_api_param}></span>
174 <div class="form-check form-check-inline">
175 <span><label class="form-check-label" for="accept_lang">Languages: </label>
176 <input type="text" placeholder="e.g. en,zh-Hant" class="form-check-input api-param-setting" data-api-param="accept-language" id="accept_lang" size="15" value="{api_request_params['accept-language'] || ''}" on:change={set_api_param}></span>
177 <span><label class="form-check-label" for="option_ccode">Countries: </label>
178 <input type="text" placeholder="e.g. de,gb" class="form-check-input api-param-setting" data-api-param="countrycodes" id="option_ccode" size="15" value="{api_request_params.countrycodes || ''}" on:change={set_api_param}></span>
182 </div> <!-- /tab-content -->
183 </div> <!-- /top-bar -->
196 border: 1px solid #ddd;
199 align-items: baseline
205 @media (max-width: 850px) {
214 margin-right: 0.4rem;
217 #searchAdvancedOptionsContent {
219 flex-direction: column;
223 #searchAdvancedOptionsContent label {
227 #searchAdvancedOptionsContent span {
238 @media (max-width: 768px) {
239 .search-button-group {