]> git.openstreetmap.org Git - nominatim-ui.git/blobdiff - src/components/SearchBar.svelte
Add eslint linter (#52)
[nominatim-ui.git] / src / components / SearchBar.svelte
index 507bffc985a382e957fac189b3d847964791bc6f..879eacdb4356aa2b5ab27e78c9c16382e41ad9d5 100644 (file)
@@ -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 = '';
     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() {
 
 {#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"
            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>
         <a href="details.html" class="mr-2">search by id</a>
         <a href="search.html">forward search</a>
       </div>
-    </form>
+    </UrlSubmitForm>
   </div>
 
 {:else}
     </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"
             <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 || ''}" />
             <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">
     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 {
     padding: 4px 10px;
   }
 
-  form label {
-    margin-left: 0.4rem;
-    margin-right: 0.4rem;
-  }
-  
-
   .search-type-link {
     display: inline;
     margin-right: 2em;
       display: inline;
     }
   }
-</style>
\ No newline at end of file
+</style>