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 = {};
11 function map_viewbox_as_string(map) {
12 var bounds = map.getBounds();
13 var west = bounds.getWest();
14 var east = bounds.getEast();
16 if ((east - west) >= 360) { // covers more than whole planet
17 west = map.getCenter().lng - 179.999;
18 east = map.getCenter().lng + 179.999;
20 east = L.latLng(77, east).wrap().lng;
21 west = L.latLng(77, west).wrap().lng;
24 west.toFixed(5), // left
25 bounds.getNorth().toFixed(5), // top
26 east.toFixed(5), // right
27 bounds.getSouth().toFixed(5) // bottom
31 function set_viewbox(map) {
32 let use_viewbox = document.getElementById('use_viewbox');
33 if (use_viewbox && use_viewbox.checked) {
34 sViewBox = map_viewbox_as_string(map);
40 function update_reverse_link(map) {
41 let link = document.getElementById('switch-to-reverse');
43 let center_lat_lng = map.wrapLatLng(map.getCenter());
44 link.href = 'reverse.html?lat=' + center_lat_lng.lat.toFixed(5)
45 + '&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 console.log('setting', e.target);
70 document.querySelector('input[name=bounded]').value = e.target.checked ? 1 : '';
73 function set_dedupe(e) {
74 document.querySelector('input[name=dedupe]').value = e.target.checked ? 1 : '';
77 function set_api_param(e) {
78 document.querySelector('input[name=' + e.target.dataset.apiParam + ']').value = e.target.value;
83 <ul class="nav nav-tabs">
85 <a class="nav-link" class:active={!bStructuredSearch} data-toggle="tab" href="#simple">simple</a>
88 <a class="nav-link" class:active={bStructuredSearch} data-toggle="tab" href="#structured">structured</a>
90 <div class="search-type-link">
91 <a href="details.html" class="mr-2">search by id</a>
92 <a id="switch-to-reverse" href="reverse.html">reverse search</a>
95 <div class="tab-content p-2">
96 <div class="tab-pane" class:active={!bStructuredSearch} id="simple" role="tabpanel">
101 class="form-control form-control-sm"
103 value="{api_request_params.q || ''}" />
105 <div class="form-group search-button-group">
106 <button type="submit" class="btn btn-primary btn-sm mx-1">Search</button>
107 <input type="hidden" name="viewbox" value="{sViewBox || ''}" />
108 <input type="hidden" name="dedupe" value="{!api_request_params.dedupe ? '' : 1}" />
109 <input type="hidden" name="bounded" value="{api_request_params.bounded ? 1 : ''}" />
110 <input type="hidden" name="accept-language" value="{api_request_params['accept-language'] || ''}" />
111 <input type="hidden" name="countrycodes" value="{api_request_params.countrycodes || ''}" />
112 <input type="hidden" name="limit" value="{api_request_params.limit || ''}" />
113 <input type="hidden" name="polygon_threshold" value="{api_request_params.polygon_threshold || ''}" />
117 <div class="tab-pane" class:active={bStructuredSearch} id="structured" role="tabpanel">
119 <input name="street" type="text" class="form-control form-control-sm mr-1"
120 placeholder="House number/Street"
121 value="{api_request_params.street || ''}" />
122 <input name="city" type="text" class="form-control form-control-sm mr-1"
124 value="{api_request_params.city || ''}" />
125 <input id="county" name="county" type="text" class="form-control form-control-sm mr-1"
127 value="{api_request_params.county || ''}" />
128 <input name="state" type="text" class="form-control form-control-sm mr-1"
130 value="{api_request_params.state || ''}" />
131 <input name="country" type="text" class="form-control form-control-sm mr-1"
132 placeholder="Country"
133 value="{api_request_params.country || ''}" />
134 <input name="postalcode" type="text" class="form-control form-control-sm mr-1"
135 placeholder="Postal Code"
136 value="{api_request_params.postalcode || ''}" />
138 <div class="form-group search-button-group">
139 <button type="submit" class="btn btn-primary btn-sm mx-1">Search</button>
140 <input type="hidden" name="viewbox" value="{sViewBox || ''}" />
141 <input type="hidden" name="dedupe" value="{!api_request_params.dedupe ? '' : 1}" />
142 <input type="hidden" name="bounded" value="{api_request_params.bounded ? 1 : ''}" />
143 <input type="hidden" name="accept-language" value="{api_request_params['accept-language'] || ''}" />
144 <input type="hidden" name="countrycodes" value="{api_request_params.countrycodes || ''}" />
145 <input type="hidden" name="limit" value="{api_request_params.limit || ''}" />
146 <input type="hidden" name="polygon_threshold" value="{api_request_params.polygon_threshold || ''}" />
150 <!-- Additional options -->
151 <a href="#advanced" class="btn btn-outline-secondary btn-sm" data-toggle="collapse" data-target="#searchAdvancedOptions" role="button" aria-expanded="false" aria-controls="collapseAdvancedOptions">
154 <div class="collapse" id="searchAdvancedOptions">
155 <div id="searchAdvancedOptionsContent">
156 <div class="form-check form-check-inline">
157 <span><input type="checkbox" class="form-check-input api-param-setting"
158 id="use_viewbox" checked={api_request_params.viewbox} on:change={reset_viewbox}>
159 <label class="form-check-label" for="use_viewbox">apply viewbox</label></span>
160 <span><input type="checkbox" class="form-check-input api-param-setting"
161 id="option_bounded" checked={!!api_request_params.bounded} on:change={set_bounded}>
162 <label class="form-check-label" for="option_bounded">bounded to viewbox</label></span>
163 <span><input type="checkbox" class="form-check-input api-param-setting"
164 id="option_dedupe" checked={!!api_request_params.dedupe} on:change={set_dedupe}>
165 <label class="form-check-label" for="option_dedupe">deduplicate results</label></span>
167 <div class="form-check form-check-inline">
168 <span><label class="form-check-label" for="option_limit">Maximum number of results: </label>
169 <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>
170 <span><label class="form-check-label" for="option_polygon_threashold">Polygon simplification: </label>
171 <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>
173 <div class="form-check form-check-inline">
174 <span><label class="form-check-label" for="accept_lang">Languages: </label>
175 <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>
176 <span><label class="form-check-label" for="option_ccode">Countries: </label>
177 <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>
181 </div> <!-- /tab-content -->
182 </div> <!-- /top-bar -->
195 border: 1px solid #ddd;
198 align-items: baseline
204 @media (max-width: 850px) {
213 margin-right: 0.4rem;
216 #searchAdvancedOptionsContent {
218 flex-direction: column;
222 #searchAdvancedOptionsContent label {
226 #searchAdvancedOptionsContent span {
237 @media (max-width: 768px) {
238 .search-button-group {