X-Git-Url: https://git.openstreetmap.org./nominatim-ui.git/blobdiff_plain/c9687b102bb6f544a034dc4d508bf0ae4a5fc221..c636646759d9c541f7baf19812be18d002a8ce1d:/src/components/SearchBar.svelte

diff --git a/src/components/SearchBar.svelte b/src/components/SearchBar.svelte
index 507bffc..879eacd 100644
--- a/src/components/SearchBar.svelte
+++ b/src/components/SearchBar.svelte
@@ -1,4 +1,5 @@
 <script>
+  import UrlSubmitForm from '../components/UrlSubmitForm.svelte';
 
   import { zoomLevels } from '../lib/helpers.js';
   import { map_store } from '../lib/stores.js';
@@ -30,8 +31,8 @@
   }
 
   function set_viewbox(map) {
-    let set_viewbox = document.getElementById('use_viewbox');
-    if (set_viewbox && set_viewbox.checked) {
+    let use_viewbox = document.getElementById('use_viewbox');
+    if (use_viewbox && use_viewbox.checked) {
       sViewBox = map_viewbox_as_string(map);
     } else {
       sViewBox = '';
@@ -42,27 +43,36 @@
     let link = document.getElementById('switch-to-reverse');
     if (link) {
       let center_lat_lng = map.wrapLatLng(map.getCenter());
-      link.href = 'reverse.html?lat=' + center_lat_lng.lat.toFixed(5) + '&lon=' + center_lat_lng.lng.toFixed(5);
+      link.href = 'reverse.html?lat=' + center_lat_lng.lat.toFixed(5)
+                   + '&lon=' + center_lat_lng.lng.toFixed(5);
     }
   }
 
   map_store.subscribe(map => {
-    if(!map) { return; }
+    if (!map) { return; }
 
     map.on('move', function () {
       set_viewbox(map);
-      update_reverse_link(map) 
+      update_reverse_link(map);
     });
 
     map.on('load', function () {
       set_viewbox(map);
-      update_reverse_link(map) 
+      update_reverse_link(map);
+    });
+
+    map.on('click', function (e) {
+      if (reverse_search) {
+        document.querySelector('input[name=lat]').value = e.latlng.lat.toFixed(5);
+        document.querySelector('input[name=lon]').value = e.latlng.wrap().lng.toFixed(5);
+        document.querySelector('form').submit();
+      }
     });
   });
 
   function reset_viewbox() {
     let map = get(map_store);
-    if (map) { set_viewbox(map) };
+    if (map) { set_viewbox(map); }
   }
 
   function set_bounded(e) {
@@ -74,8 +84,8 @@
     document.querySelector('input[name=dedupe]').value = e.target.checked ? 1 : '';
   }
 
-  function set_api_param(e){
-    document.querySelector('input[name=' + e.target.dataset['apiParam'] + ']').value = e.target.value;
+  function set_api_param(e) {
+    document.querySelector('input[name=' + e.target.dataset.apiParam + ']').value = e.target.value;
   }
 
   function handleSwitchCoords() {
@@ -89,11 +99,12 @@
 
 {#if reverse_search}
   <div class="top-bar">
-    <form class="form-inline" role="search" accept-charset="UTF-8" action="">
+    <UrlSubmitForm>
       <div class="form-group">
         <input name="format" type="hidden" value="html">
-        <label>lat</label>
-        <input name="lat"
+        <label for="reverse-lat">lat</label>
+        <input id="reverse-lat"
+               name="lat"
                type="text"
                class="form-control form-control-sm"
                placeholder="latitude"
@@ -102,14 +113,15 @@
            on:click|preventDefault|stopPropagation={handleSwitchCoords}
            class="btn btn-outline-secondary btn-sm"
            title="switch lat and lon">&lt;&gt;</a>
-        <label>lon</label>
-        <input name="lon"
+        <label for="reverse-lon">lon</label>
+        <input id="reverse-lon"
+               name="lon"
                type="text"
                class="form-control form-control-sm"
                placeholder="longitude"
                value="{api_request_params.lon || ''}" />
-        <label>max zoom</label>
-        <select name="zoom" class="form-control form-control-sm" value="{api_request_params.zoom}">
+        <label for="reverse-zoom">max zoom</label>
+        <select id="reverse-zoom" name="zoom" class="form-control form-control-sm" value="{api_request_params.zoom}">
           <option value="" selected={!api_request_params.zoom}>---</option>
           {#each zoomLevels() as zoomTitle, i}
             <option value="{i}" selected={i === api_request_params.zoom}>{i} - {zoomTitle}</option>
@@ -123,7 +135,7 @@
         <a href="details.html" class="mr-2">search by id</a>
         <a href="search.html">forward search</a>
       </div>
-    </form>
+    </UrlSubmitForm>
   </div>
 
 {:else}
@@ -143,7 +155,7 @@
     </ul>
     <div class="tab-content p-2">
       <div class="tab-pane" class:active={!bStructuredSearch} id="simple" role="tabpanel">
-        <form class="form-inline" role="search" accept-charset="UTF-8" action="">
+        <UrlSubmitForm>
           <input id="q"
                  name="q"
                  type="text"
@@ -161,10 +173,10 @@
             <input type="hidden" name="limit" value="{api_request_params.limit || ''}" />
             <input type="hidden" name="polygon_threshold" value="{api_request_params.polygon_threshold || ''}" />
           </div>
-        </form>
+        </UrlSubmitForm>
       </div>
       <div class="tab-pane" class:active={bStructuredSearch} id="structured" role="tabpanel">
-        <form class="form-inline" role="search" accept-charset="UTF-8" action="">
+        <UrlSubmitForm>
           <input name="street" type="text" class="form-control form-control-sm mr-1"
                  placeholder="House number/Street"
                  value="{api_request_params.street || ''}" />
@@ -194,7 +206,7 @@
             <input type="hidden" name="limit" value="{api_request_params.limit || ''}" />
             <input type="hidden" name="polygon_threshold" value="{api_request_params.polygon_threshold || ''}" />
           </div>
-        </form>
+        </UrlSubmitForm>
       </div>
       <!-- Additional options -->
       <a href="#advanced" class="btn btn-outline-secondary btn-sm" data-toggle="collapse" data-target="#searchAdvancedOptions" role="button" aria-expanded="false" aria-controls="collapseAdvancedOptions">
@@ -248,17 +260,19 @@
     align-items: baseline
   }
 
-  form #q {
+  #q {
     min-width: 500px;
   }
   @media (max-width: 850px) {
-    form #q {
+    #q {
       min-width: 400px;
     }
   }
 
   label {
     font-weight: normal;
+    margin-left: 0.4rem;
+    margin-right: 0.4rem;
   }
 
   #searchAdvancedOptionsContent {
@@ -275,12 +289,6 @@
     padding: 4px 10px;
   }
 
-  form label {
-    margin-left: 0.4rem;
-    margin-right: 0.4rem;
-  }
-  
-
   .search-type-link {
     display: inline;
     margin-right: 2em;
@@ -304,4 +312,4 @@
       display: inline;
     }
   }
-</style>
\ No newline at end of file
+</style>
