Skip to content

Commit

Permalink
GO-180 added excludeTypes to query
Browse files Browse the repository at this point in the history
  • Loading branch information
zdila committed Dec 4, 2023
1 parent 5f79843 commit 2299ab1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 19 additions & 15 deletions src/services/geocoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export type GeocodingSearchResult = {

function addLanguageGeocodingOptions(
searchParams: URLSearchParams,
options: LanguageGeocodingOptions
options: LanguageGeocodingOptions,
) {
const { language } = options;

Expand All @@ -254,19 +254,19 @@ function addLanguageGeocodingOptions(
const languages = Array.from(
new Set(
(Array.isArray(language) ? language : [language]).map((lang) =>
lang === LanguageGeocoding.AUTO ? getAutoLanguageGeocoding() : lang
)
)
lang === LanguageGeocoding.AUTO ? getAutoLanguageGeocoding() : lang,
),
),
).join(",");

searchParams.set("language", languages);
}

function addCommonForwardAndReverseGeocodingOptions(
searchParams: URLSearchParams,
options: CommonForwardAndReverseGeocodingOptions
options: CommonForwardAndReverseGeocodingOptions,
) {
const { apiKey, limit, types } = options;
const { apiKey, limit, types, excludeTypes } = options;

searchParams.set("key", apiKey ?? config.apiKey);

Expand All @@ -278,12 +278,16 @@ function addCommonForwardAndReverseGeocodingOptions(
searchParams.set("types", types.join(","));
}

if (excludeTypes != undefined) {
searchParams.set("excludeTypes", String(excludeTypes));
}

addLanguageGeocodingOptions(searchParams, options);
}

function addForwardGeocodingOptions(
searchParams: URLSearchParams,
options: GeocodingOptions
options: GeocodingOptions,
) {
addCommonForwardAndReverseGeocodingOptions(searchParams, options);

Expand All @@ -296,7 +300,7 @@ function addForwardGeocodingOptions(
if (proximity != undefined) {
searchParams.set(
"proximity",
proximity === "ip" ? proximity : proximity.join(",")
proximity === "ip" ? proximity : proximity.join(","),
);
}

Expand Down Expand Up @@ -324,15 +328,15 @@ function addForwardGeocodingOptions(
*/
async function forward(
query: string,
options: GeocodingOptions = {}
options: GeocodingOptions = {},
): Promise<GeocodingSearchResult> {
if (typeof query !== "string" || query.trim().length === 0) {
throw new Error("The query must be a non-empty string");
}

const endpoint = new URL(
`geocoding/${encodeURIComponent(query)}.json`,
defaults.maptilerApiURL
defaults.maptilerApiURL,
);

const { searchParams } = endpoint;
Expand Down Expand Up @@ -362,15 +366,15 @@ async function forward(
*/
async function reverse(
position: Position,
options: ReverseGeocodingOptions = {}
options: ReverseGeocodingOptions = {},
): Promise<GeocodingSearchResult> {
if (!Array.isArray(position) || position.length < 2) {
throw new Error("The position must be an array of form [lng, lat].");
}

const endpoint = new URL(
`geocoding/${position[0]},${position[1]}.json`,
defaults.maptilerApiURL
defaults.maptilerApiURL,
);

addCommonForwardAndReverseGeocodingOptions(endpoint.searchParams, options);
Expand Down Expand Up @@ -399,7 +403,7 @@ async function reverse(
*/
async function byId(
id: string,
options: ByIdGeocodingOptions = {}
options: ByIdGeocodingOptions = {},
): Promise<GeocodingSearchResult> {
const endpoint = new URL(`geocoding/${id}.json`, defaults.maptilerApiURL);
endpoint.searchParams.set("key", options.apiKey ?? config.apiKey);
Expand Down Expand Up @@ -429,7 +433,7 @@ async function byId(
*/
async function batch(
queries: string[],
options: GeocodingOptions = {}
options: GeocodingOptions = {},
): Promise<GeocodingSearchResult[]> {
if (!queries.length) {
return [];
Expand All @@ -441,7 +445,7 @@ async function batch(

const endpoint = new URL(
`geocoding/${joinedQuery}.json`,
defaults.maptilerApiURL
defaults.maptilerApiURL,
);

const { searchParams } = endpoint;
Expand Down

0 comments on commit 2299ab1

Please sign in to comment.