-
Notifications
You must be signed in to change notification settings - Fork 9
feat(search): 22291 select area when location chosen #1194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
164af39
feat(search): 22291 highlight hovered result geometry
Komzpa 56339c9
test(search): 22291 add unit test for highlighted atom
Komzpa 74c1322
fix(search): 22291 clean highlight layer lifecycle
Komzpa f5712b6
fix(search): 22291 clean highlight layer cleanup
Komzpa 29c97c2
test(search): 22291 broaden highlighted atom cases
Komzpa 05b9304
test(search): 22291 add coverage for search features
Komzpa 783e529
fix(search): 22291 clear highlight on selection
Komzpa 494a168
Delete src/features/search/tests/initSearchHighlightLayer.test.ts
vkozio 66cb1fd
Delete src/features/search/tests/highlightedAtom.test.ts
vkozio ecb1508
Delete src/features/search/tests/searchAtoms.test.ts
vkozio f4ab61b
Delete src/features/search/tests/searchLocationAtoms.test.ts
vkozio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { atom } from '@reatom/framework'; | ||
| import type { Feature, FeatureCollection } from 'geojson'; | ||
|
|
||
| export const searchHighlightedGeometryAtom = atom<FeatureCollection | Feature>( | ||
| { | ||
| type: 'FeatureCollection', | ||
| features: [], | ||
| }, | ||
| 'searchHighlightedGeometryAtom', | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export const SEARCH_HIGHLIGHT_LAYER_ID = 'search-highlight'; | ||
| export const SEARCH_HIGHLIGHT_COLOR = '#000000'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { currentMapAtom } from '~core/shared_state'; | ||
| import { store } from '~core/store/store'; | ||
| import type { LogicalLayerState } from '~core/logical_layers/types/logicalLayer'; | ||
| import type { Feature, FeatureCollection } from 'geojson'; | ||
| import { | ||
| SEARCH_HIGHLIGHT_LAYER_ID, | ||
| SEARCH_HIGHLIGHT_COLOR, | ||
| } from './constants'; | ||
| import { searchHighlightedGeometryAtom } from './atoms/highlightedGeometry'; | ||
| import { SearchHighlightRenderer } from './renderers/SearchHighlightRenderer'; | ||
|
|
||
| let cleanUp: (() => void) | null = null; | ||
|
|
||
| export function initSearchHighlightLayer() { | ||
| if (cleanUp) return cleanUp; | ||
|
|
||
| const ctx = store.v3ctx; | ||
| const map = ctx.get(currentMapAtom.v3atom); | ||
| if (!map) return () => {}; | ||
|
|
||
| const sourceId = `${SEARCH_HIGHLIGHT_LAYER_ID}-source`; | ||
| const renderer = new SearchHighlightRenderer({ | ||
| layerId: SEARCH_HIGHLIGHT_LAYER_ID, | ||
| sourceId, | ||
| color: SEARCH_HIGHLIGHT_COLOR, | ||
| }); | ||
|
|
||
| const state: LogicalLayerState = { | ||
| id: SEARCH_HIGHLIGHT_LAYER_ID, | ||
| isDownloadable: false, | ||
| isVisible: true, | ||
| isLoading: false, | ||
| isEnabled: true, | ||
| isEditable: false, | ||
| isMounted: true, | ||
| source: { | ||
| id: sourceId, | ||
| source: { type: 'geojson', data: { type: 'FeatureCollection', features: [] } }, | ||
| }, | ||
| legend: null, | ||
| meta: null, | ||
| settings: null, | ||
| error: null, | ||
| contextMenu: null, | ||
| style: null, | ||
| editor: null, | ||
| }; | ||
Komzpa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| renderer.willMount({ map, state }); | ||
|
|
||
| const unsubscribe = ctx.subscribe( | ||
| searchHighlightedGeometryAtom, | ||
| (geometry: FeatureCollection | Feature) => { | ||
| renderer.willSourceUpdate({ | ||
| map, | ||
| state: { | ||
| ...state, | ||
| source: { | ||
| id: sourceId, | ||
| source: { type: 'geojson', data: geometry }, | ||
| }, | ||
| }, | ||
| }); | ||
| }, | ||
| ); | ||
|
|
||
| cleanUp = () => { | ||
| unsubscribe(); | ||
| renderer.willUnMount({ map }); | ||
| cleanUp = null; | ||
| }; | ||
|
|
||
| return cleanUp; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Search feature | ||
|
|
||
| This feature provides a search bar to find locations or MCDA analysis suggestions. | ||
| Selected locations become the focused area on the map. | ||
| While hovering over location results the geometry is highlighted on the map with a black outline. | ||
|
|
||
| ## Main parts | ||
| - `SearchBar` - UI component with dropdown results. | ||
| - `searchLocationAtoms.ts` - handles locations fetching and selection. | ||
| - `searchAtoms.ts` - aggregates MCDA and location results. | ||
| - `atoms/highlightedGeometry.ts` - stores geometry highlighted on hover. | ||
| - `initSearchHighlightLayer` - registers temporary map layer for hovered geometries. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { BoundarySelectorRenderer } from '~features/boundary_selector/renderers/BoundarySelectorRenderer'; | ||
|
|
||
| export class SearchHighlightRenderer extends BoundarySelectorRenderer {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import { createStore } from '@reatom/core-v2'; | ||
| import { test, expect } from 'vitest'; | ||
| import { searchHighlightedGeometryAtom } from '../atoms/highlightedGeometry'; | ||
| import type { Feature, FeatureCollection } from 'geojson'; | ||
|
|
||
| const store = createStore(); | ||
|
|
||
| const ctx = store.v3ctx; | ||
|
|
||
| test('searchHighlightedGeometryAtom stores highlighted geometry', () => { | ||
| expect(ctx.get(searchHighlightedGeometryAtom)).toEqual({ | ||
| type: 'FeatureCollection', | ||
| features: [], | ||
| }); | ||
| const geom: Feature = { | ||
| type: 'Feature', | ||
| geometry: { type: 'Point', coordinates: [0, 0] }, | ||
| properties: {}, | ||
| }; | ||
| searchHighlightedGeometryAtom(ctx, geom); | ||
| expect(ctx.get(searchHighlightedGeometryAtom)).toEqual(geom); | ||
| }); | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| test('searchHighlightedGeometryAtom stores various geometry types', () => { | ||
| const polygon: Feature = { | ||
| type: 'Feature', | ||
| geometry: { | ||
| type: 'Polygon', | ||
| coordinates: [ | ||
| [ | ||
| [0, 0], | ||
| [1, 0], | ||
| [1, 1], | ||
| [0, 1], | ||
| [0, 0], | ||
| ], | ||
| ], | ||
| }, | ||
| properties: {}, | ||
| }; | ||
| searchHighlightedGeometryAtom(ctx, polygon); | ||
| expect(ctx.get(searchHighlightedGeometryAtom)).toEqual(polygon); | ||
|
|
||
| const line: Feature = { | ||
| type: 'Feature', | ||
| geometry: { | ||
| type: 'LineString', | ||
| coordinates: [ | ||
| [0, 0], | ||
| [1, 1], | ||
| ], | ||
| }, | ||
| properties: {}, | ||
| }; | ||
| searchHighlightedGeometryAtom(ctx, line); | ||
| expect(ctx.get(searchHighlightedGeometryAtom)).toEqual(line); | ||
| }); | ||
|
|
||
| test('searchHighlightedGeometryAtom handles feature collections and empty geometries', () => { | ||
| const polygon: Feature = { | ||
| type: 'Feature', | ||
| geometry: { | ||
| type: 'Polygon', | ||
| coordinates: [ | ||
| [ | ||
| [0, 0], | ||
| [1, 0], | ||
| [1, 1], | ||
| [0, 1], | ||
| [0, 0], | ||
| ], | ||
| ], | ||
| }, | ||
| properties: {}, | ||
| }; | ||
| const line: Feature = { | ||
| type: 'Feature', | ||
| geometry: { | ||
| type: 'LineString', | ||
| coordinates: [ | ||
| [0, 0], | ||
| [1, 1], | ||
| ], | ||
| }, | ||
| properties: {}, | ||
| }; | ||
| const fc: FeatureCollection = { type: 'FeatureCollection', features: [polygon, line] }; | ||
| searchHighlightedGeometryAtom(ctx, fc); | ||
| expect(ctx.get(searchHighlightedGeometryAtom)).toEqual(fc); | ||
|
|
||
| const emptyFc: FeatureCollection = { type: 'FeatureCollection', features: [] }; | ||
| searchHighlightedGeometryAtom(ctx, emptyFc); | ||
| expect(ctx.get(searchHighlightedGeometryAtom)).toEqual(emptyFc); | ||
| }); | ||
|
|
||
| test('searchHighlightedGeometryAtom accepts null values', () => { | ||
| searchHighlightedGeometryAtom(ctx, null as unknown as Feature); | ||
| expect(ctx.get(searchHighlightedGeometryAtom)).toBeNull(); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.