]> git.openstreetmap.org Git - nominatim-ui.git/blobdiff - src/components/DetailsLink.svelte
Merge remote-tracking branch 'upstream/master'
[nominatim-ui.git] / src / components / DetailsLink.svelte
index 51a0c8ce8004cd0c49d1a724a3f78d30bfcea7de..d91407945207b2399f25132b7bfb0bd003663b5c 100644 (file)
@@ -4,7 +4,8 @@
   export let extra_classes = '';
   export let feature = null;
 
-  let url_params = '';
+  let url_params = new URLSearchParams();
+  let href = 'details.html';
 
   function formatShortOSMType(sType) {
     if (sType === 'node') return 'N';
   }
 
   function handleClick() {
-    window.history.pushState([], '', 'details.html' + url_params);
-    refresh_page();
+    refresh_page('details', url_params);
   }
 
   $: {
-    if (feature !== null && feature.osm_type) {
-      let param = '?osmtype=';
-      if (feature.osm_type.length == 1) {
-        param += encodeURIComponent(feature.osm_type);
-      } else {
-        param += formatShortOSMType(feature.osm_type);
-      }
-      param += '&osmid=' + encodeURIComponent(feature.osm_id);
-      if (feature.class) {
-        param += '&class=' + encodeURIComponent(feature.class);
-      } else if (feature.category) {
-        param += '&class=' + encodeURIComponent(feature.category);
+    let new_params = new URLSearchParams();
+
+    if (feature !== null) {
+      if (feature.osm_type) {
+        if (feature.osm_type.length === 1) {
+          new_params.set('osmtype', feature.osm_type);
+        } else {
+          new_params.set('osmtype', formatShortOSMType(feature.osm_type));
+        }
+
+        new_params.set('osmid', feature.osm_id);
+
+        if (feature.class) {
+          new_params.set('class', feature.class);
+        } else if (feature.category) {
+          new_params.set('class', feature.category);
+        }
+      } else if (feature.place_id) {
+        new_params.set('place_id', feature.place_id);
       }
-      url_params = param
-    } else {
-        url_params = '';
     }
- }
+    url_params = new_params;
+  }
+
+  $: {
+    let param_str = url_params.toString();
+    href = 'details.html' + (param_str ? '?' : '') + param_str;
+  }
 </script>
 
-<a on:click|preventDefault|stopPropagation={handleClick} href="details.html{url_params}" class={extra_classes}><slot></slot></a>
+<a on:click|preventDefault|stopPropagation={handleClick} href={href} class={extra_classes}><slot></slot></a>