X-Git-Url: https://git.openstreetmap.org./nominatim-ui.git/blobdiff_plain/f51f2a70794858f9c8fb5d75ecd40fd1e4ec3897..c0d1fb859fee050373df1fa77d03cb2c1a8cde91:/src/components/ReverseLink.svelte

diff --git a/src/components/ReverseLink.svelte b/src/components/ReverseLink.svelte
index 5289999..bbd54d7 100644
--- a/src/components/ReverseLink.svelte
+++ b/src/components/ReverseLink.svelte
@@ -1,31 +1,33 @@
 <script>
 import { refresh_page } from '../lib/stores.js';
 
-export let lat;
-export let lon;
+export let lat = null;
+export let lon = null;
 export let zoom = null;
+export let extra_classes = '';
 
-let params = '';
+let params = new URLSearchParams();
+let href = 'reverse.html';
 
 $: {
+  let new_params = new URLSearchParams();
+
   if (lat && lon) {
-    let new_params = '?lat=' + encodeURIComponent(lat);
-    new_params += '&lon=' + encodeURIComponent(lon);
+    new_params.set('lat', lat);
+    new_params.set('lon', lon);
 
     if (zoom) {
-      new_params += '&zoom=' + encodeURIComponent(zoom);
+      new_params.set('zoom', zoom);
     }
-
-    params = new_params;
-  } else {
-    params = '';
   }
+
+  params = new_params;
 }
 
-function handleClick() {
-  window.history.pushState([], '', 'reverse.html' + params);
-  refresh_page();
+$: {
+  let param_str = params.toString();
+  href = 'reverse.html' + (param_str ? '?' : '') + param_str;
 }
 </script>
 
-<a on:click|preventDefault|stopPropagation={handleClick} href="reverse.html{params}"><slot></slot></a>
+<a on:click|preventDefault|stopPropagation={() => refresh_page('reverse', params)} href={href} class={extra_classes}><slot></slot></a>
