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(',');
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="form-group">
43 <label for="reverse-lat">lat</label>
44 <input id="reverse-lat"
47 class="form-control form-control-sm"
48 placeholder="latitude"
49 pattern="^-?\d+(\.\d+)?$"
51 on:change={maybeSplitLatitude} />
53 <div class="form-group">
55 on:click|preventDefault|stopPropagation={() => gotoCoordinates(lon, lat)}
56 class="btn btn-outline-secondary btn-sm"
57 title="switch lat and lon"><></a>
59 <div class="form-group">
60 <label for="reverse-lon">lon</label>
61 <input id="reverse-lon"
64 class="form-control form-control-sm"
65 placeholder="longitude"
66 pattern="^-?\d+(\.\d+)?$"
69 <div class="form-group">
70 <label for="reverse-zoom">max zoom</label>
71 <select id="reverse-zoom" name="zoom" class="form-control form-control-sm" bind:value={zoom}>
72 <option value="">---</option>
73 {#each zoomLevels() as zoomTitle, i}
74 <option value="{i}">{i} - {zoomTitle}</option>
78 <div class="form-group">
79 <button type="submit" class="btn btn-primary btn-sm mx-1">Search</button>
98 @media (max-width: 850px) {
99 #reverse-lon, #reverse-lat, #reverse-zoom {