X-Git-Url: https://git.openstreetmap.org./nominatim-ui.git/blobdiff_plain/f51f2a70794858f9c8fb5d75ecd40fd1e4ec3897..21bcfb32a13839ff8c69a452d09e294da800a15a:/src/components/DetailsLink.svelte diff --git a/src/components/DetailsLink.svelte b/src/components/DetailsLink.svelte index 51a0c8c..fbeb4f1 100644 --- a/src/components/DetailsLink.svelte +++ b/src/components/DetailsLink.svelte @@ -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'; @@ -14,29 +15,35 @@ } function handleClick() { - window.history.pushState([], '', 'details.html' + url_params); - refresh_page(); + refresh_page('details', url_params); } $: { + let new_params = new URLSearchParams(); + if (feature !== null && feature.osm_type) { - let param = '?osmtype='; - if (feature.osm_type.length == 1) { - param += encodeURIComponent(feature.osm_type); + if (feature.osm_type.length === 1) { + new_params.set('osmtype', feature.osm_type); } else { - param += formatShortOSMType(feature.osm_type); + new_params.set('osmtype', formatShortOSMType(feature.osm_type)); } - param += '&osmid=' + encodeURIComponent(feature.osm_id); + + new_params.set('osmid', feature.osm_id); + if (feature.class) { - param += '&class=' + encodeURIComponent(feature.class); + new_params.set('class', feature.class); } else if (feature.category) { - param += '&class=' + encodeURIComponent(feature.category); + new_params.set('class', feature.category); } - url_params = param - } else { - url_params = ''; } - } + + url_params = new_params; + } + + $: { + let param_str = url_params.toString(); + href = 'details.html' + (param_str ? '?' : '') + param_str; + } - +