diff --git a/src/app/pages/portal/panels/panels-handler/panels/search-results/search-results-panel.component.html b/src/app/pages/portal/panels/panels-handler/panels/search-results/search-results-panel.component.html index e881886b..d7009251 100644 --- a/src/app/pages/portal/panels/panels-handler/panels/search-results/search-results-panel.component.html +++ b/src/app/pages/portal/panels/panels-handler/panels/search-results/search-results-panel.component.html @@ -1,15 +1,33 @@ - - +@if (searchState.store.empty$ | async) { +
+
+
+ {{ 'igo.integration.searchResultsTool.noResults' | translate }} +
+
+ {{ 'igo.integration.searchResultsTool.doSearch' | translate }} +
+

+
+
+} + +@if ((searchState.store.empty$ | async) === false) { + + +} diff --git a/src/app/pages/portal/panels/panels-handler/panels/search-results/search-results-panel.component.ts b/src/app/pages/portal/panels/panels-handler/panels/search-results/search-results-panel.component.ts index 1958fe1b..afbe2185 100644 --- a/src/app/pages/portal/panels/panels-handler/panels/search-results/search-results-panel.component.ts +++ b/src/app/pages/portal/panels/panels-handler/panels/search-results/search-results-panel.component.ts @@ -1,7 +1,9 @@ import { AsyncPipe } from '@angular/common'; import { ChangeDetectionStrategy, + ChangeDetectorRef, Component, + ElementRef, EventEmitter, Input, OnDestroy, @@ -12,17 +14,23 @@ import { MatIconButton } from '@angular/material/button'; import { MatIcon } from '@angular/material/icon'; import { MatTooltip } from '@angular/material/tooltip'; -import { IgoMap, Layer, SearchResultsComponent } from '@igo2/geo'; +import { + FeatureMotion, + IgoMap, + Layer, + Research, + SearchResult, + SearchResultsComponent +} from '@igo2/geo'; import { SearchState } from '@igo2/integration'; import { TranslateModule } from '@ngx-translate/core'; +import { Subscription } from 'rxjs'; import { SearchResultAction } from '../../panels-handler.enum'; import { - onResultFocus, - onResultSelect, - onResultUnfocus, - onSearch + onResultSelectOrFocus, + onResultUnfocus } from './search-results-panel.utils'; @Component({ @@ -42,40 +50,58 @@ import { }) export class SearchResultPanelComponent implements OnInit, OnDestroy { public searchResultActions = SearchResultAction; + private empty$$: Subscription; @Input() map: IgoMap; @Input() searchState: SearchState; + @Input() expanded: boolean; + @Output() opened = new EventEmitter(); @Output() closed = new EventEmitter(); constructor() {} - ngOnInit() {} + ngOnInit() { + this.empty$$ = this.searchState.store.empty$.subscribe((e) => { + if (!e && !this.expanded) { + this.opened.emit(); + } + }); + } - ngOnDestroy() {} + ngOnDestroy() { + this.empty$$.unsubscribe(); + } onSearchTermChange(term: string) { this.searchState.setSearchTerm(term); } - onResult(searchResultAction: SearchResultAction, event) { - console.log('searchResultAction', searchResultAction, event); + onResult(searchResultAction: SearchResultAction, searchResult: SearchResult) { switch (searchResultAction) { case SearchResultAction.Focus: - onResultFocus(); - break; - case SearchResultAction.Search: - onSearch(); + onResultSelectOrFocus(searchResult, this.map, this.searchState, { + featureMotion: FeatureMotion.None + }); break; case SearchResultAction.Select: - onResultSelect(); + onResultSelectOrFocus(searchResult, this.map, this.searchState); this.close(); break; case SearchResultAction.Unfocus: - onResultUnfocus(); + onResultUnfocus(searchResult, this.map, this.searchState); break; } } + onMoreResults(event: { research: Research; results: SearchResult[] }) { + const results = event.results; + this.searchState.store.state.updateAll({ focused: false, selected: false }); + const newResults = this.searchState.store.entities$.value + .filter((result: SearchResult) => result.source !== event.research.source) + .concat(results); + this.searchState.store.updateMany(newResults); + // todo scroll into view + } close() { this.closed.emit(); diff --git a/src/app/pages/portal/panels/panels-handler/panels/search-results/search-results-panel.utils.ts b/src/app/pages/portal/panels/panels-handler/panels/search-results/search-results-panel.utils.ts index f1e51588..161062f8 100644 --- a/src/app/pages/portal/panels/panels-handler/panels/search-results/search-results-panel.utils.ts +++ b/src/app/pages/portal/panels/panels-handler/panels/search-results/search-results-panel.utils.ts @@ -1,12 +1,71 @@ -export function onResultFocus() { - console.log('onResultFocus'); +import { + FEATURE, + Feature, + FeatureMotion, + IgoMap, + SearchResult, + getCommonVectorSelectedStyle +} from '@igo2/geo'; +import { SearchState } from '@igo2/integration'; + +import olFeature from 'ol/Feature'; +import type { default as OlGeometry } from 'ol/geom/Geometry'; + +export function onResultSelectOrFocus( + result: SearchResult, + map: IgoMap, + searchState: SearchState, + options?: { featureMotion?: FeatureMotion } +) { + if (result.meta.dataType === FEATURE && result.data.geometry) { + result.data.meta.style = getCommonVectorSelectedStyle( + Object.assign( + {}, + { feature: result.data as Feature | olFeature }, + searchState.searchOverlayStyleFocus, + result.style?.focus ? result.style.focus : {} + ) + ); + + const feature = map.searchResultsOverlay.dataSource.ol.getFeatureById( + result.meta.id + ); + if (feature) { + feature.setStyle(result.data.meta.style); + return; + } + map.searchResultsOverlay.addFeature( + result.data as Feature, + options?.featureMotion + ); + } } -export function onResultSelect() { - console.log('onResultSelect'); -} -export function onResultUnfocus() { - console.log('onResultUnfocus'); -} -export function onSearch() { - console.log('onSearch'); + +export function onResultUnfocus( + result: SearchResult, + map: IgoMap, + searchState: SearchState +) { + if (result.meta.dataType !== FEATURE) { + return; + } + + if (searchState.store.state.get(result).selected) { + const feature = map.searchResultsOverlay.dataSource.ol.getFeatureById( + result.meta.id + ); + if (feature) { + const style = getCommonVectorSelectedStyle( + Object.assign( + {}, + { feature: result.data as Feature | olFeature }, + searchState.searchOverlayStyleFocus, + result.style?.focus ? result.style.focus : {} + ) + ); + feature.setStyle(style); + } + return; + } + map.searchResultsOverlay.removeFeature(result.data as Feature); }