]> git.openstreetmap.org Git - nominatim-ui.git/blobdiff - src/components/SearchSectionReverse.svelte
Svelte 3.x -> 4.x
[nominatim-ui.git] / src / components / SearchSectionReverse.svelte
index 108e3b6903b0574e295793a8e57d4ac4d9614ff8..46bb2b9d11a850b6f99fa6e01d7723b76d9f3eff 100644 (file)
@@ -9,6 +9,8 @@
   export let zoom = '';
 
   function gotoCoordinates(newlat, newlon, newzoom) {
+    if (newlat === null || newlon === null) return;
+
     let params = new URLSearchParams();
     params.set('lat', newlat);
     params.set('lon', newlon);
@@ -27,7 +29,7 @@
 
   // common mistake is to copy&paste latitude and longitude into the 'lat' search box
   function maybeSplitLatitude(e) {
-    var coords_split = e.target.value.split(',');
+    var coords_split = e.target.value.split(/,|%2C/);
     if (coords_split.length === 2) {
       document.querySelector('input[name=lat]').value = L.Util.trim(coords_split[0]);
       document.querySelector('input[name=lon]').value = L.Util.trim(coords_split[1]);
 </script>
 
 <UrlSubmitForm page="reverse">
-  <div class="form-group">
-    <input name="format" type="hidden" value="html">
+  <div class="col-auto">
     <label for="reverse-lat">lat</label>
+  </div>
+  <div class="col-auto">
     <input id="reverse-lat"
            name="lat"
            type="text"
-           class="form-control form-control-sm"
+           class="form-control form-control-sm d-inline"
            placeholder="latitude"
+           pattern="^-?\d+(\.\d+)?$"
            bind:value={lat}
            on:change={maybeSplitLatitude} />
-    <a id="switch-coords"
+  </div>
+  <div class="col-auto">
+    <button id="switch-coords"
        on:click|preventDefault|stopPropagation={() => gotoCoordinates(lon, lat)}
        class="btn btn-outline-secondary btn-sm"
-       title="switch lat and lon">&lt;&gt;</a>
+       title="switch lat and lon">&lt;&gt;</button>
+  </div>
+  <div class="col-auto">
     <label for="reverse-lon">lon</label>
+  </div>
+  <div class="col-auto">
     <input id="reverse-lon"
            name="lon"
            type="text"
            class="form-control form-control-sm"
            placeholder="longitude"
+           pattern="^-?\d+(\.\d+)?$"
            bind:value={lon} />
+  </div>
+  <div class="col-auto">
     <label for="reverse-zoom">max zoom</label>
-    <select id="reverse-zoom" name="zoom" class="form-control form-control-sm" bind:value={zoom}>
+  </div>
+  <div class="col-auto">
+    <select id="reverse-zoom" name="zoom" class="form-select form-select-sm" bind:value={zoom}>
       <option value="">---</option>
       {#each zoomLevels() as zoomTitle, i}
         <option value="{i}">{i} - {zoomTitle}</option>
       {/each}
     </select>
-    <button type="submit" class="btn btn-primary btn-sm mx-1">
-      Search
-    </button>
+  </div>
+  <div class="col-auto">
+    <button type="submit" class="btn btn-primary btn-sm mx-1">Search</button>
   </div>
 </UrlSubmitForm>
 
 <style>
   label {
-    font-weight: normal;
-    margin-left: 0.4rem;
-    margin-right: 0.4rem;
+    font-size: 0.9rem;
+    margin-top: 0.3rem;
   }
 
   #switch-coords {
     padding: 2px;
     margin: 5px;
   }
+
+  @media (max-width: 850px) {
+    #reverse-lon, #reverse-lat, #reverse-zoom {
+      width: 8em;
+    }
+  }
 </style>