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 let params = new URLSearchParams();
13 params.set('lat', newlat);
14 params.set('lon', newlon);
15 params.set('zoom', newzoom || zoom);
16 refresh_page('reverse', params);
19 map_store.subscribe(map => {
21 map.on('click', (e) => {
22 let coords = e.latlng.wrap();
23 gotoCoordinates(coords.lat.toFixed(5), coords.lng.toFixed(5));
28 // common mistake is to copy&paste latitude and longitude into the 'lat' search box
29 function maybeSplitLatitude(e) {
30 var coords_split = e.target.value.split(',');
31 if (coords_split.length === 2) {
32 document.querySelector('input[name=lat]').value = L.Util.trim(coords_split[0]);
33 document.querySelector('input[name=lon]').value = L.Util.trim(coords_split[1]);
39 <UrlSubmitForm page="reverse">
40 <div class="form-group">
41 <label for="reverse-lat">lat</label>
42 <input id="reverse-lat"
45 class="form-control form-control-sm"
46 placeholder="latitude"
47 pattern="^-?\d+(\.\d+)?$"
49 on:change={maybeSplitLatitude} />
51 <div class="form-group">
53 on:click|preventDefault|stopPropagation={() => gotoCoordinates(lon, lat)}
54 class="btn btn-outline-secondary btn-sm"
55 title="switch lat and lon"><></a>
57 <div class="form-group">
58 <label for="reverse-lon">lon</label>
59 <input id="reverse-lon"
62 class="form-control form-control-sm"
63 placeholder="longitude"
64 pattern="^-?\d+(\.\d+)?$"
67 <div class="form-group">
68 <label for="reverse-zoom">max zoom</label>
69 <select id="reverse-zoom" name="zoom" class="form-control form-control-sm" bind:value={zoom}>
70 <option value="">---</option>
71 {#each zoomLevels() as zoomTitle, i}
72 <option value="{i}">{i} - {zoomTitle}</option>
76 <div class="form-group">
77 <button type="submit" class="btn btn-primary btn-sm mx-1">Search</button>
96 @media (max-width: 850px) {
97 #reverse-lon, #reverse-lat, #reverse-zoom {