2 import { onDestroy } from 'svelte';
3 import UrlSubmitForm from '../components/UrlSubmitForm.svelte';
5 import { zoomLevels } from '../lib/helpers.js';
6 import { map_store, refresh_page } from '../lib/stores.js';
11 export let api_request_params = {};
13 function gotoCoordinates(newlat, newlon, newzoom) {
14 if (newlat === null || newlon === null) return;
16 let params = new URLSearchParams();
17 params.set('lat', newlat);
18 params.set('lon', newlon);
19 params.set('zoom', newzoom || zoom);
20 refresh_page('reverse', params);
23 const unsubscribe = map_store.subscribe(map => {
25 map.on('click', (e) => {
26 let coords = e.latlng.wrap();
27 gotoCoordinates(coords.lat.toFixed(5), coords.lng.toFixed(5));
32 // common mistake is to copy&paste latitude and longitude into the 'lat' search box
33 function maybeSplitLatitude(e) {
34 var coords_split = e.target.value.split(/,|%2C/);
35 if (coords_split.length === 2) {
36 document.querySelector('input[name=lat]').value = L.Util.trim(coords_split[0]);
37 document.querySelector('input[name=lon]').value = L.Util.trim(coords_split[1]);
41 function set_api_param(e) {
42 document.querySelector('input[name=' + e.target.dataset.apiParam + ']').value = e.target.value;
45 onDestroy(unsubscribe);
48 <UrlSubmitForm page="reverse">
49 <div class="col-auto">
50 <label for="reverse-lat">lat</label>
52 <div class="col-auto">
53 <input id="reverse-lat"
56 class="form-control form-control-sm d-inline"
57 placeholder="latitude"
58 pattern="^-?\d+(\.\d+)?$"
60 on:change={maybeSplitLatitude} />
62 <div class="col-auto">
63 <button id="switch-coords"
64 on:click|preventDefault|stopPropagation={() => gotoCoordinates(lon, lat)}
65 class="btn btn-outline-secondary btn-sm"
66 title="switch lat and lon"><></button>
68 <div class="col-auto">
69 <label for="reverse-lon">lon</label>
71 <div class="col-auto">
72 <input id="reverse-lon"
75 class="form-control form-control-sm"
76 placeholder="longitude"
77 pattern="^-?\d+(\.\d+)?$"
80 <div class="col-auto">
81 <label for="reverse-zoom">max zoom</label>
83 <div class="col-auto">
84 <select id="reverse-zoom" name="zoom" class="form-select form-select-sm" bind:value={zoom}>
85 <option value="">---</option>
86 {#each zoomLevels() as zoomTitle, i}
87 <option value="{i}">{i} - {zoomTitle}</option>
92 name="layer" value="{api_request_params.layer || ''}" />
93 <div class="col-auto">
94 <button type="submit" class="btn btn-primary btn-sm mx-1">Search</button>
98 <!-- Additional options -->
99 <details id="searchAdvancedOptions" class="mt-2">
100 <summary><small>Advanced options</small></summary>
103 <label for="option_layer">Layer</label>
104 <input id="option_layer" name="layer" placeholder="e.g. address,poi,railway,natural,manmade"
105 value="{api_request_params.layer || ''}"
106 data-api-param="layer" on:change={set_api_param}
107 class="form-control form-control-sm d-inline w-auto api-param-setting">
126 #searchAdvancedOptions ul {
127 list-style-type: none;
132 #searchAdvancedOptions li {
133 display: inline-block;
136 border: 1px dotted #ccc;
140 #searchAdvancedOptions label {
144 @media (max-width: 850px) {
145 #reverse-lon, #reverse-lat, #reverse-zoom {