return '';
}
+// https://www.openstreetmap.org/relation/123 => ['R', 123]
+// w123 => ['W', 123]
+export function identifyLinkInQuery(query) {
+ if (!query) return undefined;
+ const m = query.match(/\/(relation|way|node)\/(\d+)/) || query.match(/^([nwr])(\d+)$/i);
+ if (!m) return undefined;
+ return [m[1][0].toUpperCase(), Number(m[2])];
+}
+
export function osmLink(aPlace) {
if (!aPlace.osm_type) return '';
var sOSMType = formatOSMType(aPlace.osm_type, false);
import { writable } from 'svelte/store';
+import { identifyLinkInQuery } from './helpers.js';
export const map_store = writable();
export const results_store = writable();
}
}
+ if (pagename === 'search' && params.has('q')) {
+ const arrTypeAndId = identifyLinkInQuery(params.get('q'));
+ if (arrTypeAndId instanceof Array) {
+ pagename = 'details';
+ params = new URLSearchParams();
+ params.set('osmtype', arrTypeAndId[0]);
+ params.set('osmid', arrTypeAndId[1]);
+ }
+ }
+
page.set({ tab: pagename, params: params });
last_api_request_url_store.set(null);
error_store.set(null);
assert.ok(page_header.includes('Paris'));
});
});
+
+ describe('Search for OSM URL', function () {
+ before(async function () {
+ page = await browser.newPage();
+ await page.goto('http://localhost:9999/search.html');
+ await page.type('input[name=q]', 'https://www.openstreetmap.org/relation/3459013#map=11/41.2388/-8.3867');
+ await page.click('button[type=submit]');
+ await page.waitForSelector('table#address');
+ });
+
+ after(async function () {
+ await page.close();
+ });
+
+ it('should redirect to detail page search', async function () {
+ assert.equal(await page.title(), 'Details for R3459013 | Nominatim Demo');
+ assert.ok((await page.$eval('.container h1', el => el.textContent)).includes('Porto'));
+ });
+ });
});
import assert from 'assert';
-import { formatLabel, wikipediaLink } from '../../src/lib/helpers.js';
+import { identifyLinkInQuery, formatLabel, wikipediaLink } from '../../src/lib/helpers.js';
describe('Helpers', function () {
+ it('.identifyLinkInQuery', function () {
+ assert.equal(identifyLinkInQuery(''), undefined);
+ assert.equal(identifyLinkInQuery('http://example.com'), undefined);
+
+ assert.deepStrictEqual(identifyLinkInQuery('https://www.openstreetmap.org/relation/1234#map=11/41.2388/-8.3867'), ['R', 1234]);
+ assert.deepStrictEqual(identifyLinkInQuery('n1234'), ['N', 1234]);
+ assert.deepStrictEqual(identifyLinkInQuery('W1234'), ['W', 1234]);
+ });
+
it('.formatLabel', function () {
// not enough data
assert.equal(formatLabel({}), '');