From 8c8d837fe3135ff47595776b158162f7cfe5b8a6 Mon Sep 17 00:00:00 2001 From: Pauliina Ilmanen Date: Tue, 27 Aug 2024 14:13:42 +0300 Subject: [PATCH] Embed view: filter search results by bbox Filter search results by bbox if embedded and bbox is provided. --- src/views/SearchView/SearchView.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/views/SearchView/SearchView.js b/src/views/SearchView/SearchView.js index 6feb250e6..af20f4176 100644 --- a/src/views/SearchView/SearchView.js +++ b/src/views/SearchView/SearchView.js @@ -257,6 +257,14 @@ const SearchView = () => { } } + function reorderBbox(bbox) { + if (bbox.length !== 4) { + throw new Error('Invalid bbox length. Expected an array of 4 elements.'); + } + // Reorder the bbox coordinates to match the order that the API requires + return [bbox[1], bbox[0], bbox[3], bbox[2]]; + } + useEffect(() => { if (embed) { // Do not mess with settings when embedded @@ -284,6 +292,13 @@ const SearchView = () => { useEffect(() => { const options = getSearchParamData(); if (shouldFetch() && Object.keys(options).length) { + const bbox = parseBboxFromLocation(location); + if (embed && bbox) { + // Filter search results by bbox if embedded and bbox is provided + const reorderedBbox = reorderBbox(bbox); + options.bbox = reorderedBbox; + options.bbox_srid = 4326; + } dispatch(fetchSearchResults(options)); } }, [match.params]);