diff --git a/src/lib/search/module.ts b/src/lib/search/module.ts index 5a07e88bb7..b555616d5c 100644 --- a/src/lib/search/module.ts +++ b/src/lib/search/module.ts @@ -5,18 +5,11 @@ import { IgoSharedModule } from '../shared'; import { SearchService, provideSearchSourceService } from './shared'; -import { provideSearchSourceOptions, SearchSourceOptions, - provideNominatimSearchSource } from './search-sources'; +import { provideSearchSourceOptions } from './search-sources'; import { SearchBarComponent, SearchUrlParamDirective } from './search-bar'; -export function provideDefaultSearchSources(options?: SearchSourceOptions) { - return [ - provideNominatimSearchSource() - ]; -} - @NgModule({ imports: [ JsonpModule, diff --git a/src/lib/search/search-sources/datasource-search-source.ts b/src/lib/search/search-sources/datasource-search-source.ts index 5fa182ce0c..d8c905ca20 100644 --- a/src/lib/search/search-sources/datasource-search-source.ts +++ b/src/lib/search/search-sources/datasource-search-source.ts @@ -1,28 +1,16 @@ -import { Inject } from '@angular/core'; +import { Inject, Injectable } from '@angular/core'; import { Jsonp, Response, URLSearchParams } from '@angular/http'; import { Observable } from 'rxjs/Observable'; import { Message } from '../../core/message'; import { Feature, FeatureType } from '../../feature'; -import { SEARCH_SOURCE_OPTIONS, SearchSource } from './search-source'; +import { SearchSource } from './search-source'; +import { SEARCH_SOURCE_OPTIONS } from './search-source.provider'; import { SearchSourceOptions } from './search-source.interface'; -export function dataSourceSearchSourcesFactory(jsonp: Jsonp, options: any) { - return new DataSourceSearchSource(jsonp, options); -} - -export function provideDataSourceSearchSource() { - return { - provide: SearchSource, - useFactory: dataSourceSearchSourcesFactory, - multi: true, - deps: [Jsonp, SEARCH_SOURCE_OPTIONS] - }; -} - - +@Injectable() export class DataSourceSearchSource extends SearchSource { static _name: string = 'Data Sources'; diff --git a/src/lib/search/search-sources/icherche-search-source.ts b/src/lib/search/search-sources/icherche-search-source.ts index 376c699d0f..17e064d968 100644 --- a/src/lib/search/search-sources/icherche-search-source.ts +++ b/src/lib/search/search-sources/icherche-search-source.ts @@ -1,27 +1,16 @@ -import { Inject } from '@angular/core'; +import { Inject, Injectable } from '@angular/core'; import { Jsonp, Response, URLSearchParams } from '@angular/http'; import { Observable } from 'rxjs/Observable'; import { Message } from '../../core/message'; import { Feature, FeatureType, FeatureFormat} from '../../feature'; -import { SEARCH_SOURCE_OPTIONS, SearchSource } from './search-source'; +import { SearchSource } from './search-source'; +import { SEARCH_SOURCE_OPTIONS } from './search-source.provider'; import { SearchSourceOptions } from './search-source.interface'; -export function ichercheSearchSourcesFactory(jsonp: Jsonp, options: any) { - return new IChercheSearchSource(jsonp, options); -} - -export function provideIChercheSearchSource() { - return { - provide: SearchSource, - useFactory: ichercheSearchSourcesFactory, - multi: true, - deps: [Jsonp, SEARCH_SOURCE_OPTIONS] - }; -} - +@Injectable() export class IChercheSearchSource extends SearchSource { static _name: string = 'ICherche Québec'; diff --git a/src/lib/search/search-sources/index.ts b/src/lib/search/search-sources/index.ts index 445c7fe9cc..27d1f3cbae 100644 --- a/src/lib/search/search-sources/index.ts +++ b/src/lib/search/search-sources/index.ts @@ -1,4 +1,5 @@ export * from './search-source'; +export * from './search-source.provider'; export * from './search-source.interface'; export * from './nominatim-search-source'; export * from './icherche-search-source'; diff --git a/src/lib/search/search-sources/nominatim-search-source.ts b/src/lib/search/search-sources/nominatim-search-source.ts index db39d91763..13ac3ee190 100644 --- a/src/lib/search/search-sources/nominatim-search-source.ts +++ b/src/lib/search/search-sources/nominatim-search-source.ts @@ -1,27 +1,16 @@ -import { Inject } from '@angular/core'; +import { Inject, Injectable } from '@angular/core'; import { Http, Response, URLSearchParams } from '@angular/http'; import { Observable } from 'rxjs/Observable'; import { Message } from '../../core/message'; import { Feature, FeatureType, FeatureFormat} from '../../feature'; -import { SEARCH_SOURCE_OPTIONS, SearchSource } from './search-source'; +import { SearchSource } from './search-source'; +import { SEARCH_SOURCE_OPTIONS } from './search-source.provider'; import { SearchSourceOptions } from './search-source.interface'; -export function nominatimSearchSourcesFactory(http: Http, options: any) { - return new NominatimSearchSource(http, options); -} - -export function provideNominatimSearchSource() { - return { - provide: SearchSource, - useFactory: nominatimSearchSourcesFactory, - multi: true, - deps: [Http, SEARCH_SOURCE_OPTIONS] - }; -} - +@Injectable() export class NominatimSearchSource extends SearchSource { static _name: string = 'Nominatim (OSM)'; diff --git a/src/lib/search/search-sources/search-source.provider.ts b/src/lib/search/search-sources/search-source.provider.ts new file mode 100644 index 0000000000..f0f35c10d8 --- /dev/null +++ b/src/lib/search/search-sources/search-source.provider.ts @@ -0,0 +1,61 @@ +import { InjectionToken } from '@angular/core'; +import { Http, Jsonp } from '@angular/http'; + +import { SearchSource } from './search-source'; +import { SearchSourceOptions } from './search-source.interface'; +import { NominatimSearchSource } from './nominatim-search-source'; +import { IChercheSearchSource } from './icherche-search-source'; +import { DataSourceSearchSource } from './datasource-search-source'; + + +export let SEARCH_SOURCE_OPTIONS = + new InjectionToken('searchSourceOptions'); + +export function provideSearchSourceOptions(options: SearchSourceOptions) { + return { + provide: SEARCH_SOURCE_OPTIONS, + useValue: options + }; +} + + +export function nominatimSearchSourcesFactory(http: Http, options: any) { + return new NominatimSearchSource(http, options); +} + +export function provideNominatimSearchSource() { + return { + provide: SearchSource, + useFactory: (nominatimSearchSourcesFactory), + multi: true, + deps: [Http, SEARCH_SOURCE_OPTIONS] + }; +} + + +export function ichercheSearchSourcesFactory(jsonp: Jsonp, options: any) { + return new IChercheSearchSource(jsonp, options); +} + +export function provideIChercheSearchSource() { + return { + provide: SearchSource, + useFactory: (ichercheSearchSourcesFactory), + multi: true, + deps: [Jsonp, SEARCH_SOURCE_OPTIONS] + }; +} + + +export function dataSourceSearchSourcesFactory(jsonp: Jsonp, options: any) { + return new DataSourceSearchSource(jsonp, options); +} + +export function provideDataSourceSearchSource() { + return { + provide: SearchSource, + useFactory: (dataSourceSearchSourcesFactory), + multi: true, + deps: [Jsonp, SEARCH_SOURCE_OPTIONS] + }; +} diff --git a/src/lib/search/search-sources/search-source.ts b/src/lib/search/search-sources/search-source.ts index 4c7d922304..cb91dbbcf3 100644 --- a/src/lib/search/search-sources/search-source.ts +++ b/src/lib/search/search-sources/search-source.ts @@ -1,20 +1,9 @@ -import { InjectionToken } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import { Message } from '../../core/message'; import { Feature } from '../../feature'; -import { SearchSourceOptions } from './search-source.interface'; -export let SEARCH_SOURCE_OPTIONS = - new InjectionToken('searchSourceOptions'); - -export function provideSearchSourceOptions(options: SearchSourceOptions) { - return { - provide: SEARCH_SOURCE_OPTIONS, - useValue: options - }; -} export abstract class SearchSource {