diff --git a/packages/geo/src/lib/query/shared/query-search-source.ts b/packages/geo/src/lib/query/shared/query-search-source.ts index 0a51f01abb..f8548d8ce0 100644 --- a/packages/geo/src/lib/query/shared/query-search-source.ts +++ b/packages/geo/src/lib/query/shared/query-search-source.ts @@ -20,6 +20,10 @@ export class QuerySearchSource extends SearchSource { return QuerySearchSource.id; } + getType(): string { + return QuerySearchSource.type; + } + protected getDefaultOptions(): SearchSourceOptions { return { title: 'Carte' diff --git a/packages/geo/src/lib/routing/routing-form/routing-form.component.ts b/packages/geo/src/lib/routing/routing-form/routing-form.component.ts index 4b0ae48578..e76df32e4e 100644 --- a/packages/geo/src/lib/routing/routing-form/routing-form.component.ts +++ b/packages/geo/src/lib/routing/routing-form/routing-form.component.ts @@ -923,7 +923,7 @@ export class RoutingFormComponent implements OnInit, AfterViewInit, OnDestroy { private handleTermChanged(term: string) { if (term !== undefined || term.length !== 0) { const searchProposals = []; - const researches = this.searchService.search(term); + const researches = this.searchService.search(term, {searchType: 'Feature'}); researches.map(res => this.routesQueries$$.push( res.request.subscribe(results => { diff --git a/packages/geo/src/lib/search/shared/search.service.ts b/packages/geo/src/lib/search/shared/search.service.ts index 81059a7bab..e34afee6f6 100644 --- a/packages/geo/src/lib/search/shared/search.service.ts +++ b/packages/geo/src/lib/search/shared/search.service.ts @@ -45,10 +45,20 @@ export class SearchService { console.log(response.message); } - const sources = this.searchSourceService - .getEnabledSources() - .filter(sourceCanSearch); + let sources = this.searchSourceService + .getEnabledSources(); + if (options) { + if (options.getEnabledOnly || options.getEnabledOnly === undefined) { + sources = this.searchSourceService.getEnabledSources(); + } else { + sources = this.searchSourceService.getSources(); + } + if (options.searchType) { + sources = sources.filter(source => source.getType() === options.searchType); + } + } + sources = sources.filter(sourceCanSearch); return this.searchSources(sources, term, options || {}); } diff --git a/packages/geo/src/lib/search/shared/sources/coordinates.ts b/packages/geo/src/lib/search/shared/sources/coordinates.ts index 4023baba4f..8a0085b5e9 100644 --- a/packages/geo/src/lib/search/shared/sources/coordinates.ts +++ b/packages/geo/src/lib/search/shared/sources/coordinates.ts @@ -48,6 +48,10 @@ export class CoordinatesReverseSearchSource extends SearchSource return CoordinatesReverseSearchSource.id; } + getType(): string { + return CoordinatesReverseSearchSource.type; + } + protected getDefaultOptions(): SearchSourceOptions { return { title: 'igo.geo.search.coordinates.name', diff --git a/packages/geo/src/lib/search/shared/sources/icherche.ts b/packages/geo/src/lib/search/shared/sources/icherche.ts index 1c60d7a6fd..df0764d90c 100644 --- a/packages/geo/src/lib/search/shared/sources/icherche.ts +++ b/packages/geo/src/lib/search/shared/sources/icherche.ts @@ -66,6 +66,10 @@ export class IChercheSearchSource extends SearchSource implements TextSearch { return IChercheSearchSource.id; } + getType(): string { + return IChercheSearchSource.type; + } + protected getDefaultOptions(): SearchSourceOptions { return { title: 'iCherche', @@ -394,6 +398,10 @@ export class IChercheReverseSearchSource extends SearchSource return IChercheReverseSearchSource.id; } + getType(): string { + return IChercheReverseSearchSource.type; + } + protected getDefaultOptions(): SearchSourceOptions { return { title: 'Territoire (Géocodage inversé)', diff --git a/packages/geo/src/lib/search/shared/sources/ilayer.ts b/packages/geo/src/lib/search/shared/sources/ilayer.ts index 082180c785..5c7d80717f 100644 --- a/packages/geo/src/lib/search/shared/sources/ilayer.ts +++ b/packages/geo/src/lib/search/shared/sources/ilayer.ts @@ -82,6 +82,10 @@ export class ILayerSearchSource extends SearchSource implements TextSearch { return ILayerSearchSource.id; } + getType(): string { + return ILayerSearchSource.type; + } + protected getDefaultOptions(): ILayerSearchSourceOptions { return { title: 'igo.geo.search.ilayer.name', diff --git a/packages/geo/src/lib/search/shared/sources/nominatim.ts b/packages/geo/src/lib/search/shared/sources/nominatim.ts index 113686c5f5..e5c86f698b 100644 --- a/packages/geo/src/lib/search/shared/sources/nominatim.ts +++ b/packages/geo/src/lib/search/shared/sources/nominatim.ts @@ -30,6 +30,10 @@ export class NominatimSearchSource extends SearchSource implements TextSearch { return NominatimSearchSource.id; } + getType(): string { + return NominatimSearchSource.type; + } + /* * Source : https://wiki.openstreetmap.org/wiki/Key:amenity */ diff --git a/packages/geo/src/lib/search/shared/sources/source.interfaces.ts b/packages/geo/src/lib/search/shared/sources/source.interfaces.ts index 2a89d1c484..5e5e411d3d 100644 --- a/packages/geo/src/lib/search/shared/sources/source.interfaces.ts +++ b/packages/geo/src/lib/search/shared/sources/source.interfaces.ts @@ -28,6 +28,8 @@ export interface SettingOptions { export interface TextSearchOptions { params?: { [key: string]: string }; + searchType?: 'Feature' | 'Layer'; // refer to search.enum.ts SEARCH_TYPES = [FEATURE, LAYER]; + getEnabledOnly?: boolean; } export interface ReverseSearchOptions { diff --git a/packages/geo/src/lib/search/shared/sources/source.ts b/packages/geo/src/lib/search/shared/sources/source.ts index 25e11c09b7..f4e56d6be3 100644 --- a/packages/geo/src/lib/search/shared/sources/source.ts +++ b/packages/geo/src/lib/search/shared/sources/source.ts @@ -37,6 +37,13 @@ export class SearchSource { getId(): string { throw new Error('You have to implement the method "getId".'); } + /** + * Get search source's type + * @returns Search source's type + */ + getType(): string { + throw new Error('You have to implement the method "getType".'); + } /** * Get search source's default options diff --git a/packages/geo/src/lib/search/shared/sources/storedqueries.ts b/packages/geo/src/lib/search/shared/sources/storedqueries.ts index b495cf3855..8024fff5d3 100644 --- a/packages/geo/src/lib/search/shared/sources/storedqueries.ts +++ b/packages/geo/src/lib/search/shared/sources/storedqueries.ts @@ -88,6 +88,10 @@ export class StoredQueriesSearchSource extends SearchSource implements TextSearc return StoredQueriesSearchSource.id; } + getType(): string { + return StoredQueriesSearchSource.type; + } + protected getDefaultOptions(): SearchSourceOptions { return { title: 'Stored Queries', @@ -295,6 +299,10 @@ export class StoredQueriesReverseSearchSource extends SearchSource return StoredQueriesReverseSearchSource.id; } + getType(): string { + return StoredQueriesReverseSearchSource.type; + } + protected getDefaultOptions(): SearchSourceOptions { return { title: 'Stored Queries (reverse)',