Skip to content

Commit

Permalink
RD-294: Move the list of map languages to maptiler-client (#42)
Browse files Browse the repository at this point in the history
* wip languages

* listing all the languages

* list of language on par with geocoding

* linting

* removed languageGeocoding

* cleaning

* adding language equality functions

* fixing language labels

* changelog, version and readme

* some fixes after review

* simplified condition

* some typing

* linting
  • Loading branch information
jonathanlurie authored Sep 6, 2024
1 parent a9a799d commit 4d5269a
Show file tree
Hide file tree
Showing 11 changed files with 1,225 additions and 130 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
root: true,
rules: {
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-explicit-any": "warn",
}
};
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# MapTiler Client Changelog

## DEVEL
## 2.0.0
### New Features
- Added `matching_text` and `matching_place_name` properties to geocoding feature response
- Added `road` to geocoding `types`

### Bug Fixes
### Others
- Languages are now listed in the Client library

## 1.8.1
### Bug Fixes
Expand Down
5 changes: 1 addition & 4 deletions examples/test-browser-es.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,13 @@
coordinates,
data,
staticMaps,
LanguageGeocoding,
} from '../dist/maptiler-client.mjs';

console.log(LanguageGeocoding);

// The API key must be in the URL param as `?key=ABCD1234`
config.apiKey = (new URLSearchParams(location.search)).get("key");

async function testGeocoding() {
console.log(await geocoding.forward('bordeaux', {language: [geocoding.language.SPANISH, geocoding.language.ENGLISH]}));
console.log(await geocoding.forward('bordeaux', {language: [geocoding.Language.SPANISH, geocoding.Language.ENGLISH]}));
console.log(await geocoding.forward('bordeaux', {
bbox: [-7.638157121837139, 33.595474163650685, -7.624914050102235, 33.600446760011856]
}));
Expand Down
10 changes: 5 additions & 5 deletions examples/test-browser-umd.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
maptilerClient.config.apiKey = (new URLSearchParams(location.search)).get("key");

async function testGeocoding() {
console.log(await maptilerClient.geocoding.forward('bordeaux', {language: [maptilerClient.LanguageGeocoding.SPANISH, maptilerClient.LanguageGeocoding.ENGLISH]}));
console.log(await maptilerClient.geocoding.forward('bordeaux'));
console.log(await maptilerClient.geocoding.reverse([6.249638, 46.402056], {language: ['es', 'en']}));
console.log(await maptilerClient.geocoding.forward('bordeaux', {language: [maptilerClient.Language.SPANISH, maptilerClient.Language.ENGLISH]}));
// console.log(await maptilerClient.geocoding.forward('bordeaux'));
// console.log(await maptilerClient.geocoding.reverse([6.249638, 46.402056], {language: ['es', 'en']}));
}

async function testGeolocation() {
Expand Down Expand Up @@ -79,11 +79,11 @@


(async () => {
// await testGeocoding();
await testGeocoding();
// await testGeolocation();
// await testCoordinates();
// await testData();
staticMapTest();
// staticMapTest();
})()
</script>
</body>
Expand Down
12 changes: 6 additions & 6 deletions examples/test-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import {
geolocation,
coordinates,
data,
LanguageGeocoding,
Language,
} from '../dist/maptiler-client.mjs';

// For this examople to work, you must bring your own node-compatible fetch,
// unles you are using a version of Nodejs that already contains fetch (>=18)
// import fetch from 'node-fetch';

// config.fetch = fetch;
config.apiKey = 'YOUR_MAPTILER_CLOUD_API_KEY';
config.apiKey = 'YOUR_API_KEY';

async function testGeocoding() {
// const result1 = await geocoding.forward('bordeaux', {language: [LanguageGeocoding.AUTO, LanguageGeocoding.ENGLISH]});
// console.log(result1);
const result1 = await geocoding.forward('bordeaux', {language: [Language.AUTO, Language.ENGLISH]});
console.log(result1);

const result2 = await geocoding.reverse([6.249638, 46.402056], {language: ['es', 'en']});
console.log(result2);
// const result2 = await geocoding.reverse([6.249638, 46.402056], {language: ['es', 'en']});
// console.log(result2);
}

async function testGeolocation() {
Expand Down
36 changes: 23 additions & 13 deletions package-lock.json

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

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@maptiler/client",
"version": "1.8.1",
"version": "2.0.0",
"description": "Javascript & Typescript wrapper to MapTiler Cloud API",
"module": "dist/maptiler-client.mjs",
"types": "dist/maptiler-client.d.ts",
Expand Down Expand Up @@ -56,6 +56,8 @@
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/pluginutils": "^5.0.5",
"@types/geojson": "^7946.0.10",
"@typescript-eslint/eslint-plugin": "^6.9.0",
"@typescript-eslint/parser": "^6.9.0",
"eslint": "^8.52.0",
Expand All @@ -71,9 +73,7 @@
"typedoc": "^0.25.2",
"typedoc-plugin-markdown": "^3.16.0",
"typescript": "^5.2.2",
"vitest": "^0.34.6",
"@rollup/pluginutils": "^5.0.5",
"@types/geojson": "^7946.0.10"
"vitest": "^0.34.6"
},
"dependencies": {
"quick-lru": "^7.0.0"
Expand Down
6 changes: 4 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,16 @@ The same option object as the forward geocoding can be provided.
Read more about reverse geocoding on our [official documentation](https://docs.maptiler.com/client-js/geocoding/#reverse).

### Language
For both *forward* and *reverse* geocoding, this library provides a list of supported languages as shorthands to [ISO language codes](https://en.wikipedia.org/wiki/ISO_639-1). The result will be provided in multiple languages if the `language` options is an array:
For both *forward* and *reverse* geocoding, this library provides a list of supported languages as shorthands that include [ISO language codes](https://en.wikipedia.org/wiki/ISO_639-1). The result will be provided in multiple languages if the `language` options is an array:

```ts
const result = await maptilerClient.geocoding.forward('paris', {language: [maptilerClient.geocoding.languages.SPANISH, maptilerClient.geocoding.languages.KOREAN]})
const result = await maptilerClient.geocoding.forward('paris', {language: [maptilerClient.Language.SPANISH, maptilerClient.geocoding.Language.KOREAN]})
```

The special language `AUTO` will detect the platform/browser preferred language.

If the language is not specified as options, MapTiler Cloud will use the `Accept-language` from the HTTP header of the request. The language seleted this way is generaly similar to the `Language.AUTO` mode, but can still differ in some cases ([read more](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language)).

## 🕵️‍♂️ Geolocation
The geolocation service provides location informations of a visitor using its IP address.

Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BBox, Position, LineString, MultiLineString } from "geojson";
import type { BBox, Position, LineString, MultiLineString } from "geojson";
export type { BBox, Position, LineString, MultiLineString };
export * from "./config";
export * from "./language";
Expand All @@ -13,3 +13,4 @@ export * from "./services/math";
export * from "./services/elevation";
export * from "./tiledecoding";
export * from "./misc";
export * from "./language";
Loading

0 comments on commit 4d5269a

Please sign in to comment.