2 import UrlSubmitForm from '../components/UrlSubmitForm.svelte';
4 import { zoomLevels } from '../lib/helpers.js';
5 import { map_store, refresh_page } from '../lib/stores.js';
10 export let api_request_params = {};
12 function gotoCoordinates(newlat, newlon, newzoom) {
13 if (newlat === null || newlon === null) return;
15 let params = new URLSearchParams();
16 params.set('lat', newlat);
17 params.set('lon', newlon);
18 params.set('zoom', newzoom || zoom);
19 refresh_page('reverse', params);
22 map_store.subscribe(map => {
24 map.on('click', (e) => {
25 let coords = e.latlng.wrap();
26 gotoCoordinates(coords.lat.toFixed(5), coords.lng.toFixed(5));
31 // common mistake is to copy&paste latitude and longitude into the 'lat' search box
32 function maybeSplitLatitude(e) {
33 var coords_split = e.target.value.split(/,|%2C/);
34 if (coords_split.length === 2) {
35 document.querySelector('input[name=lat]').value = L.Util.trim(coords_split[0]);
36 document.querySelector('input[name=lon]').value = L.Util.trim(coords_split[1]);
40 function set_api_param(e) {
41 document.querySelector('input[name=' + e.target.dataset.apiParam + ']').value = e.target.value;
45 <UrlSubmitForm page="reverse">
46 <div class="col-auto">
47 <label for="reverse-lat">lat</label>
49 <div class="col-auto">
50 <input id="reverse-lat"
53 class="form-control form-control-sm d-inline"
54 placeholder="latitude"
55 pattern="^-?\d+(\.\d+)?$"
57 on:change={maybeSplitLatitude} />
59 <div class="col-auto">
60 <button id="switch-coords"
61 on:click|preventDefault|stopPropagation={() => gotoCoordinates(lon, lat)}
62 class="btn btn-outline-secondary btn-sm"
63 title="switch lat and lon"><></button>
65 <div class="col-auto">
66 <label for="reverse-lon">lon</label>
68 <div class="col-auto">
69 <input id="reverse-lon"
72 class="form-control form-control-sm"
73 placeholder="longitude"
74 pattern="^-?\d+(\.\d+)?$"
77 <div class="col-auto">
78 <label for="reverse-zoom">max zoom</label>
80 <div class="col-auto">
81 <select id="reverse-zoom" name="zoom" class="form-select form-select-sm" bind:value={zoom}>
82 <option value="">---</option>
83 {#each zoomLevels() as zoomTitle, i}
84 <option value="{i}">{i} - {zoomTitle}</option>
89 name="layer" value="{api_request_params.layer || ''}" />
90 <div class="col-auto">
91 <button type="submit" class="btn btn-primary btn-sm mx-1">Search</button>
95 <!-- Additional options -->
96 <details id="searchAdvancedOptions" class="mt-2">
97 <summary><small>Advanced options</small></summary>
100 <label for="option_layer">Layer</label>
101 <input id="option_layer" name="layer" placeholder="e.g. address,poi,railway,natural,manmade"
102 value="{api_request_params.layer || ''}"
103 data-api-param="layer" on:change={set_api_param}
104 class="form-control form-control-sm d-inline w-auto api-param-setting">
123 #searchAdvancedOptions ul {
124 list-style-type: none;
129 #searchAdvancedOptions li {
130 display: inline-block;
133 border: 1px dotted #ccc;
137 #searchAdvancedOptions label {
141 @media (max-width: 850px) {
142 #reverse-lon, #reverse-lat, #reverse-zoom {