diff --git a/packages/geo/src/lib/overlay/shared/overlay.ts b/packages/geo/src/lib/overlay/shared/overlay.ts index 2b50adae9a..efc758b6c0 100644 --- a/packages/geo/src/lib/overlay/shared/overlay.ts +++ b/packages/geo/src/lib/overlay/shared/overlay.ts @@ -82,7 +82,7 @@ export class Overlay { /** * Add a feature to the overlay and, optionally, move to it * @param feature Feature - * @param motion Optional: Apply this motion to the map view + * @param motion Optional: Apply this motion to the map view (default on FeatureMotion.Default) */ addFeature(feature: Feature, motion: FeatureMotion = FeatureMotion.Default) { this.addFeatures([feature], motion); diff --git a/packages/integration/src/lib/search/search-results-tool/search-results-tool.component.ts b/packages/integration/src/lib/search/search-results-tool/search-results-tool.component.ts index a457241269..21261fe78e 100644 --- a/packages/integration/src/lib/search/search-results-tool/search-results-tool.component.ts +++ b/packages/integration/src/lib/search/search-results-tool/search-results-tool.component.ts @@ -394,7 +394,7 @@ export class SearchResultsToolComponent implements OnInit, OnDestroy { abstractResult.meta.style.setZIndex(2000 + zIndexOffset); this.map.searchResultsOverlay.addFeature( abstractResult, - FeatureMotion.None + this.searchState.featureMotion.focus ); if (trigger === 'focused') { this.abstractFocusedResult = abstractResult; @@ -471,7 +471,7 @@ export class SearchResultsToolComponent implements OnInit, OnDestroy { } this.map.searchResultsOverlay.addFeature( result.data as Feature, - FeatureMotion.None + this.searchState.featureMotion.focus ); } } @@ -510,7 +510,7 @@ export class SearchResultsToolComponent implements OnInit, OnDestroy { */ onResultSelect(result: SearchResult) { this.map.searchResultsOverlay.dataSource.ol.clear(); - this.tryAddFeatureToMap(result); + this.tryAddFeatureToMap(result, this.searchState.featureMotion.selected); this.searchState.setSelectedResult(result); if (this.topPanelState === 'initial') { @@ -630,8 +630,12 @@ export class SearchResultsToolComponent implements OnInit, OnDestroy { /** * Try to add a feature to the map overlay * @param result A search result that could be a feature + * @param motion A FeatureMotion to trigger when adding the searchresult to the map search overlay */ - private tryAddFeatureToMap(result: SearchResult) { + private tryAddFeatureToMap( + result: SearchResult, + motion: FeatureMotion = FeatureMotion.Default + ) { if (result.meta.dataType !== FEATURE) { return undefined; } @@ -651,7 +655,7 @@ export class SearchResultsToolComponent implements OnInit, OnDestroy { ) ); - this.map.searchResultsOverlay.addFeature(feature); + this.map.searchResultsOverlay.addFeature(feature, motion); } isScrolledIntoView(elemSource, elem) { diff --git a/packages/integration/src/lib/search/search.state.ts b/packages/integration/src/lib/search/search.state.ts index e0b33ba2a0..aa44143611 100644 --- a/packages/integration/src/lib/search/search.state.ts +++ b/packages/integration/src/lib/search/search.state.ts @@ -10,6 +10,7 @@ import { ConfigService, StorageService } from '@igo2/core'; import { CommonVectorStyleOptions, Feature, + FeatureMotion, FeatureStore, FeatureWorkspace, OverlayStyleOptions, @@ -23,6 +24,14 @@ import { BehaviorSubject, Subscription } from 'rxjs'; import { MapState } from '../map'; import { WorkspaceState } from '../workspace/workspace.state'; +/** + * Define the FeatureMotion to apply when adding the SearchResult to the map as an overlay. + */ +export interface SearchFeatureMotion { + selected?: FeatureMotion; + focus?: FeatureMotion; +} + /** * Service that holds the state of the search module */ @@ -38,6 +47,16 @@ export class SearchState { public focusedOrResolution$$: Subscription; public selectedOrResolution$$: Subscription; + /** + * Default feature motion are: + * on selection = FeatureMotion.Default and + * on focus = FeatureMotion.None + */ + public featureMotion: SearchFeatureMotion = { + selected: FeatureMotion.Default, + focus: FeatureMotion.None + }; + readonly searchTermSplitter$: BehaviorSubject = new BehaviorSubject( '|' ); diff --git a/projects/demo/src/app/geo/search/search.component.html b/projects/demo/src/app/geo/search/search.component.html index 0c7ed27567..8d585c9578 100644 --- a/projects/demo/src/app/geo/search/search.component.html +++ b/projects/demo/src/app/geo/search/search.component.html @@ -50,7 +50,7 @@ placeholder="false" [settingsChange$]="settingsChange$" (resultFocus)="onResultFocus($event)" - (resultSelect)="onResultFocus($event)" + (resultSelect)="onResultSelect($event)" (moreResults)="onSearch($event)" > diff --git a/projects/demo/src/app/geo/search/search.component.ts b/projects/demo/src/app/geo/search/search.component.ts index a7b8c5d783..2dd1d8d60a 100644 --- a/projects/demo/src/app/geo/search/search.component.ts +++ b/projects/demo/src/app/geo/search/search.component.ts @@ -6,7 +6,7 @@ import { ViewChild } from '@angular/core'; -import { Action, ActionStore, EntityStore } from '@igo2/common'; +import { ActionStore, EntityStore } from '@igo2/common'; import { MediaService, StorageService } from '@igo2/core'; import { FEATURE, @@ -140,15 +140,27 @@ export class AppSearchComponent implements OnInit, OnDestroy { * @param result A search result that could be a feature */ onResultFocus(result: SearchResult): void { - this.tryAddFeatureToMap(result); - this.selectedFeature = (result satisfies SearchResult).data; + this.tryAddFeatureToMap(result, this.searchState.featureMotion.focus); + this.selectedFeature = result.data; + } + /** + * Try to add a feature to the map when it's being selected + * @internal + * @param result A search result that could be a feature + */ + onResultSelect(result: SearchResult): void { + this.tryAddFeatureToMap(result, this.searchState.featureMotion.selected); + this.selectedFeature = result.data; } /** * Try to add a feature to the map overlay * @param layer A search result that could be a feature */ - private tryAddFeatureToMap(layer: SearchResult): void | undefined { + private tryAddFeatureToMap( + layer: SearchResult, + motion: FeatureMotion = FeatureMotion.Default + ): void | undefined { if (layer.meta.dataType !== FEATURE) { return undefined; } @@ -158,10 +170,7 @@ export class AppSearchComponent implements OnInit, OnDestroy { return; } - this.map.searchResultsOverlay.setFeatures( - [layer.data] satisfies Feature[], - FeatureMotion.Default - ); + this.map.searchResultsOverlay.setFeatures([layer.data], motion); } ngOnInit(): void { @@ -181,7 +190,7 @@ export class AppSearchComponent implements OnInit, OnDestroy { title: 'googleStreetView', handler: () => this.openGoogleStreetView(this.lonlat) } - ] satisfies Action[]); + ]); } ngOnDestroy(): void {