2 import UrlSubmitForm from '../components/UrlSubmitForm.svelte';
4 import { zoomLevels } from '../lib/helpers.js';
5 import { map_store, refresh_page } from '../lib/stores.js';
11 function gotoCoordinates(newlat, newlon, newzoom) {
12 if (newlat === null || newlon === null) return;
14 let params = new URLSearchParams();
15 params.set('lat', newlat);
16 params.set('lon', newlon);
17 params.set('zoom', newzoom || zoom);
18 refresh_page('reverse', params);
21 map_store.subscribe(map => {
23 map.on('click', (e) => {
24 let coords = e.latlng.wrap();
25 gotoCoordinates(coords.lat.toFixed(5), coords.lng.toFixed(5));
30 // common mistake is to copy&paste latitude and longitude into the 'lat' search box
31 function maybeSplitLatitude(e) {
32 var coords_split = e.target.value.split(/,|%2C/);
33 if (coords_split.length === 2) {
34 document.querySelector('input[name=lat]').value = L.Util.trim(coords_split[0]);
35 document.querySelector('input[name=lon]').value = L.Util.trim(coords_split[1]);
41 <UrlSubmitForm page="reverse">
42 <div class="col-auto">
43 <label for="reverse-lat">lat</label>
45 <div class="col-auto">
46 <input id="reverse-lat"
49 class="form-control form-control-sm d-inline"
50 placeholder="latitude"
51 pattern="^-?\d+(\.\d+)?$"
54 on:change={maybeSplitLatitude} />
56 <div class="col-auto">
58 on:click|preventDefault|stopPropagation={() => gotoCoordinates(lon, lat)}
59 class="btn btn-outline-secondary btn-sm"
60 title="switch lat and lon"><></a>
62 <div class="col-auto">
63 <label for="reverse-lon">lon</label>
65 <div class="col-auto">
66 <input id="reverse-lon"
69 class="form-control form-control-sm"
70 placeholder="longitude"
71 pattern="^-?\d+(\.\d+)?$"
74 <div class="col-auto">
75 <label for="reverse-zoom">max zoom</label>
77 <div class="col-auto">
78 <select id="reverse-zoom" name="zoom" class="form-select form-select-sm" bind:value={zoom}>
79 <option value="">---</option>
80 {#each zoomLevels() as zoomTitle, i}
81 <option value="{i}">{i} - {zoomTitle}</option>
85 <div class="col-auto">
86 <button type="submit" class="btn btn-primary btn-sm mx-1">Search</button>
104 @media (max-width: 850px) {
105 #reverse-lon, #reverse-lat, #reverse-zoom {