1 import { writable } from 'svelte/store';
3 export const map_store = writable();
4 export const results_store = writable();
5 export const last_api_request_url_store = writable();
6 export const error_store = writable();
7 export const page = writable();
10 * Update the global page state.
12 * When called without a parameter, then the current window.location is
13 * parsed and the page state is set accordingly. Otherwise the page state
14 * is set from the parameters. 'pagename' is the overall subpage (without
15 * .html extension). 'params' must be an URLSearchParams object and contain
16 * the requested query parameters. It may also be omitted completely for a
17 * link without query parameters.
19 const default_pagename = Nominatim_Config.Reverse_Only ? 'reverse' : 'search';
30 export function refresh_page(pagename, params) {
31 if (typeof pagename === 'undefined') {
32 pagename = window.location.pathname.replace('.html', '').replace(/^.*\//, '');
34 if (!pagenames.includes(pagename)) pagename = default_pagename;
36 params = new URLSearchParams(window.location.search);
38 if (!pagenames.includes(pagename)) pagename = default_pagename;
40 if (typeof params === 'undefined') {
41 params = new URLSearchParams();
44 let param_str = params.toString();
46 param_str = '?' + param_str;
48 let new_url = pagename + '.html' + param_str;
50 if (window.location.protocol.match(/^http/)) {
51 window.history.pushState([], '', new_url);
53 window.location.href = new_url;
57 page.set({ tab: pagename, params: params });
58 last_api_request_url_store.set(null);
59 error_store.set(null);