]> git.openstreetmap.org Git - nominatim-ui.git/blob - src/components/SearchSectionDetails.svelte
nodejs package updates
[nominatim-ui.git] / src / components / SearchSectionDetails.svelte
1 <script>
2   import { refresh_page } from '../lib/stores.js';
3
4   export let api_request_params = {};
5
6   function handleFormSubmit(event) {
7     let form_el = event.target;
8     let val = form_el.querySelector('input[type=edit]').value.trim();
9     let type_and_id_match = val.match(/^\s*([NWR])(\d+)\s*$/i)
10                             || val.match(/\/(relation|way|node)\/(\d+)\s*$/);
11
12     var params = new URLSearchParams();
13     if (type_and_id_match) {
14       params.set('osmtype', type_and_id_match[1].charAt(0).toUpperCase());
15       params.set('osmid', type_and_id_match[2]);
16     } else if (val.match(/^\d+$/)) {
17       params.set('place_id', val);
18     } else {
19       alert('invalid input');
20       return;
21     }
22
23     refresh_page('details', params);
24   }
25 </script>
26
27 <form on:submit|preventDefault={handleFormSubmit} class="form-inline" action="details.html">
28   <div class="row g-1">
29     <div class="col-auto">
30       <!-- eslint-disable-next-line max-len -->
31       <input type="edit"
32              class="form-control form-control-sm me-1"
33              pattern="^[NWRnwr]?[0-9]+$|.*openstreetmap.*"
34              value="{
35               (api_request_params.osmtype || '')
36               + (api_request_params.osmid || '')
37               + (api_request_params.place_id || '')
38             }" />
39       </div>
40     <div class="col-auto">
41       <button type="submit" class="btn btn-primary btn-sm">Show</button>
42     </div>
43   </div>
44 </form>
45 <small class="form-text text-muted">
46   OSM type+id (<em>N123</em>,
47                <em>n123</em>,
48                <em>W123</em>,
49                <em>w123</em>,
50                <em>R123</em>,
51                <em>r123</em>),
52   Place id (<em>1234</em>) or
53   URL (<em>https://openstreetmap.org/way/123</em>)
54 </small>
55
56 <style>
57   form .form-control{
58     width: 500px;
59     max-width: 100%;
60   }
61   .form-text em {
62     font-family: monospace;
63     font-style: normal;
64   }
65 </style>