Skip to content

Commit

Permalink
chore(search): rename osm provider to nominatim
Browse files Browse the repository at this point in the history
  • Loading branch information
tyrossel committed Nov 4, 2024
1 parent 9576c41 commit a7f39d6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/apps/custom/customConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const config: CustomConfig = {
},
},
{
type: 'osm',
type: 'nominatim',
options: {
limit: 10,
},
Expand Down
14 changes: 7 additions & 7 deletions src/interfaces/search/ingv-search-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ export function isGeoAdminSearchProvider(
return config.type === 'geoadmin';
}

export interface INGVOsmSearchProviderConfig {
type: 'osm';
export interface INGVNominatimSearchProviderConfig {
type: 'nominatim';

options?: {
/** URL to the OSM search API. The following placeholders are supported:
/** URL to the Nominatim search API. The following placeholders are supported:
* - `{input}`: the search query
* - `{lang}`: the language code
* - `{limit}`: see below
Expand All @@ -52,16 +52,16 @@ export interface INGVOsmSearchProviderConfig {
limit?: number;
};
}
export function isOsmSearchProvider(
export function isNominatimSearchProvider(
config: INGVSearchProviderConfigs,
): config is INGVOsmSearchProviderConfig {
return config.type === 'osm';
): config is INGVNominatimSearchProviderConfig {
return config.type === 'nominatim';
}

// Unions of all possible configs
export type INGVSearchProviderConfigs =
| INGVGeoAdminSearchProviderConfig
| INGVOsmSearchProviderConfig;
| INGVNominatimSearchProviderConfig;

export interface INGVSearchProvider {
search: (input: string, lang: string) => Promise<INGVSearchResult[]>;
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/search/ngv-search-providers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
isGeoAdminSearchProvider,
isOsmSearchProvider,
isNominatimSearchProvider,
type INGVSearchProvider,
type INGVSearchProviderConfigs,
} from '../../interfaces/search/ingv-search-provider.js';
Expand All @@ -13,11 +13,11 @@ export async function getProvider(
'./providers/ngv-geoadmin-provider.js'
);
return new NGVGeoAdminSearchProvider(config.options);
} else if (isOsmSearchProvider(config)) {
const {NGVOsmSearchProvider} = await import(
'./providers/ngv-osm-provider.js'
} else if (isNominatimSearchProvider(config)) {
const {NGVNominatimSearchProvider} = await import(
'./providers/ngv-nominatim-provider.js'
);
return new NGVOsmSearchProvider(config.options);
return new NGVNominatimSearchProvider(config.options);
}
throw new Error(`Unhandled search provider type`);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {Geometry} from 'geojson';
import type {
INGVOsmSearchProviderConfig,
INGVNominatimSearchProviderConfig,
INGVSearchProvider,
INGVSearchResult,
} from '../../../interfaces/search/ingv-search-provider.js';
Expand All @@ -14,12 +14,14 @@ interface OSMFeature {
lon: string;
}

export class NGVOsmSearchProvider implements INGVSearchProvider {
public name: 'osm';
export class NGVNominatimSearchProvider implements INGVSearchProvider {
public name: 'nominatim';
private searchUrl: string;
private limit: number;

constructor(config: INGVOsmSearchProviderConfig['options'] | undefined) {
constructor(
config: INGVNominatimSearchProviderConfig['options'] | undefined,
) {
this.searchUrl = config?.url ?? nominatimSearchUrl;
this.limit = config?.limit ?? 10;
}
Expand Down

0 comments on commit a7f39d6

Please sign in to comment.