{"id":28576946,"url":"https://github.com/maptiler/maptiler-client-js","last_synced_at":"2025-06-11T00:08:23.157Z","repository":{"id":65344345,"uuid":"567362399","full_name":"maptiler/maptiler-client-js","owner":"maptiler","description":"MapTiler APIs wrapper in JavaScript \u0026 TypeScript","archived":false,"fork":false,"pushed_at":"2025-04-23T09:36:09.000Z","size":41534,"stargazers_count":16,"open_issues_count":4,"forks_count":9,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-04-23T10:28:15.506Z","etag":null,"topics":["api-client","geocoding","geolocation","javascript","map","maptiler","services","static-maps","typescript"],"latest_commit_sha":null,"homepage":"https://docs.maptiler.com/client-js/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maptiler.png","metadata":{"files":{"readme":"readme.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-11-17T16:19:54.000Z","updated_at":"2025-04-23T09:30:07.000Z","dependencies_parsed_at":"2023-02-16T09:15:38.998Z","dependency_job_id":"c64e0a73-5221-4a05-b3c9-962820c96561","html_url":"https://github.com/maptiler/maptiler-client-js","commit_stats":{"total_commits":63,"total_committers":9,"mean_commits":7.0,"dds":"0.33333333333333337","last_synced_commit":"8e2efa9c78774e3734b3db5c674afc94d96753fe"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maptiler%2Fmaptiler-client-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maptiler%2Fmaptiler-client-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maptiler%2Fmaptiler-client-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maptiler%2Fmaptiler-client-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maptiler","download_url":"https://codeload.github.com/maptiler/maptiler-client-js/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maptiler%2Fmaptiler-client-js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259172986,"owners_count":22816560,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-client","geocoding","geolocation","javascript","map","maptiler","services","static-maps","typescript"],"created_at":"2025-06-11T00:08:22.558Z","updated_at":"2025-06-11T00:08:23.142Z","avatar_url":"https://github.com/maptiler.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003ca href=\"https://docs.maptiler.com/client-js/\"\u003eofficial page →\u003c/a\u003e\u003cbr\u003e\n  \u003cimg src=\"images/maptiler-client-logo.svg\" width=\"400px\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\" style=\"color: #AAA\"\u003e\n  The Javascript \u0026 TypeScript API client library to enjoy \u003ca href=\"https://www.maptiler.com/cloud/\"\u003eMapTiler Cloud\u003c/a\u003e's \u003cbr\u003eservices such as geocoding, geolocation and more!\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"images/JS-logo.svg\" width=\"20px\"\u003e\n  \u003cimg src=\"images/TS-logo.svg\" width=\"20px\"\u003e\n  \u003cimg src=\"https://img.shields.io/npm/v/@maptiler/client\"\u003e\u003c/img\u003e\n  \u003cimg src=\"https://img.shields.io/twitter/follow/maptiler?style=social\"\u003e\u003c/img\u003e\n\u003c/p\u003e\n\n# API Client Library for JavaScript / TypeScript\n\n## What?\n\nThe **MapTiler Client JS** exposes a number of handy functions that wrap API call to [MapTiler Cloud API services](https://docs.maptiler.com/cloud/api), such as:\n- [Geocoding forward and reverse](#-geocoding)\n- [Geolocation from visitor's IP address](#%EF%B8%8F%EF%B8%8F-geolocation)\n- [Coordinate systems search and tranform](#-coordinates)\n- [User data fetching as GeoJSON](#-data)\n- [Static maps of all sorts](#%EF%B8%8F-static-maps)\n- [Elevation lookup with batch features](#-elevation)\n\n## Why?\n\nThe project is entirely written in TypeScript and all the function arguments are nicely documented and typed.\n\n- Better developer experience of working with APIs in the code editor - with parameter info, quick info, and member lists.\n  - Code completion: reducing typos and other common mistakes\n  - Content assist and code hinting providing contextual help\n- Type safety - for higher quality code and testing\n- Backward compatibility: guaranteed on changes to API endpoints\n- Runs: in Node.js or in browser\n- Open source license\n\n# Install\n```shell\nnpm install --save @maptiler/client\n```\n\n# API documentation\nIn addition to the details and examples provided in this readme, check out the [complete API documentation](https://labs.maptiler.com/maptiler-client-js).\n\n# Quick start\n```ts\n// Import the whole library\nimport * as maptilerClient from '@maptiler/client';\n\n// Or import only the bits you need\nimport {\n  config,\n  geocoding,\n  geolocation,\n  coordinates,\n  data,\n  staticMaps,\n  elevation,\n  math,\n} from '@maptiler/client';\n```\n\nThe [examples](examples/) folder includes are featuring usages for **NodeJS**, **browser with UMD** and **browser with ES module**.\n\n# Easy access to MapTiler Cloud API\nHere is the list of service wrapper functions that are built-in:\n\n## 🔍 Geocoding\n\u003e ✅ Please, use geocoding functions only from client-side (browser) and do not 🚫 **store** or **redistribute** MapTiler Cloud API data. In case of doubt, consult the [terms](https://www.maptiler.com/cloud/terms/#explicitly-prohibited-use) ⚖️\n\n### Forward\nYou want to know the longitude and latitude of a specific place, use the forward geocoding:\n```ts\n// in an async function, or as a 'thenable':\nconst result = await maptilerClient.geocoding.forward('paris');\n```\nYou can provide some options such as:\n- the proximity, given a lon-lat position, to sort the results\n- one of more languages to get the results into\n- a bounding geo box, to restrict the search to a given window\n\nRead more about forward geocoding as well as feature ID query and batch forward geocoding on our [official documentation](https://docs.maptiler.com/client-js/geocoding/#forward).\n\n### Reverse\nYou wan to tknow the name of a place, given a longitude-latitude? Use the reverse geocoding:\n```ts\n// in an async function, or as a 'thenable':\nconst result = await maptilerClient.geocoding.reverse([6.249638, 46.402056]);\n```\nThe same option object as the forward geocoding can be provided.\n\nRead more about reverse geocoding on our [official documentation](https://docs.maptiler.com/client-js/geocoding/#reverse).\n\n### Language\nFor 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:\n\n```ts\nconst result = await maptilerClient.geocoding.forward('paris', {language: [maptilerClient.Language.SPANISH, maptilerClient.geocoding.Language.KOREAN]})\n```\n\nThe special language `AUTO` will detect the platform/browser preferred language.\n\nIf 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)).\n\n## 🕵️‍♂️ Geolocation\nThe geolocation service provides location informations of a visitor using its IP address.\n\nThe geolocation uses the IP address of a visitors to provide informations about their location, such as city, region, country, timezone, etc. The precision is lower than GPS but does not require visitors to explicitely enable the location service from their web browser.\n\nThere is only a single function:\n```ts\n// in an async function, or as a 'thenable':\nconst result = await maptilerClient.geolocation.info();\n```\n\nRead more about geolocation on our [official documentation](https://docs.maptiler.com/client-js/geolocation/).\n\n## 🌐 Coordinates\nIf you are already familiar with [epsg.io](https://epsg.io/) (created by MapTiler), then you may find convenient to access the details of more than 10 thousands of coordinate reference systems (CRS) programmatically, as well as transforming coordinates from one system to another!\n\n### Search\nThe `search` lets you perform a query in a free form fashion. Here are some examples:\n```ts\n// in an async function, or as a 'thenable':\nconst resultA = await maptilerClient.coordinates.search('mercator');\nconst resultB = await maptilerClient.coordinates.search('plate carree');\nconst resultC = await maptilerClient.coordinates.search('france');\nconst resultD = await maptilerClient.coordinates.search('code:4326', {transformations: true}));\n```\n\nThe `transformations` options retrieves a lot more details about the CRS that MapTiler API is able to transform to/from than just their IDs.\n\nRead more about searching coordinate systems on our [official documentation](https://docs.maptiler.com/client-js/coordinates/#search).\n\n### Transform\nTransforming a couple of coordinates from one system to another can be challenging, for example, most countries have their own official system, yet web mapping tools are more often than not exclusive to [WGS84](https://epsg.io/4326).\n\nIf not provided, both the source (`sourceCrs`) and the destination (`targetCrs`) are default to **EPSG:4326** (in other words, [WGS84](https://epsg.io/4326)). Here is how to use this feature:\n\n```ts\n// in an async function, or as a 'thenable':\n\n// Providing one coordinate to transform, with a target CRS being EPSG:9793 (RGF93 v2 / Lambert-93, France official CRS)\nconst resultA = await maptilerClient.coordinates.transform([1, 45], {targetCrs: 9793})\n\n// Using the same logic, we can pass up to 50 coordinates to be transformed\nconst resultB = await maptilerClient.coordinates.transform([[10, 48], [1, 45]], {targetCrs: 9793})\n```\n\nRead more about transforming coordinates on our [official documentation](https://docs.maptiler.com/client-js/coordinates/#transform).\n\n## 💽 Data\nMapTiler Cloud give its users the possibility to [upload and create data](https://cloud.maptiler.com/data/), manually with a user interface or by uploading a GPX, GeoJSON, KML or shp file. A unique ID is associated to each dataset so that we can later on access it programmatically to retrieve a GeoJSON equivalent of it:\n\n```ts\n// in an async function, or as a 'thenable':\nconst result = await maptilerClient.data.get('my-dataset-unique-id')\n```\n\nSince the result is a GeoJSON, it can easily be added to a `map` with `.addSource()` and `.addLayer()`.\n\nRead more about fetching your own data on our [official documentation](https://docs.maptiler.com/client-js/data/).\n\n## 🗺️ Static maps\n\u003e ✅ Please, use static maps URLs only from client side `\u003cimg\u003e` elements, and do not 🚫 store or redistribute the static map files. In case of doubt, consult the [terms](https://www.maptiler.com/cloud/terms/#explicitly-prohibited-use) ⚖️\n\nMaptiler Cloud provides many possibilities for creating static maps as PNG, JPEG or WebP images. They all offer the possibilities to:\n- Choose from one of the MapTiler style or your own\n- Add markers with a custom icon (or default icon with custom color)\n- Add path or polygon, with a parametric line width and color and a parametric filling color\n\nThree modes are available: `centered`, `bounded` and `automatic`.\n\n\u003e 📣 *__important:__* \u003cspan style=\"text-decoration: underline\"\u003eonly image **URLs** are returned.\u003c/span\u003e   \n\u003e Contrary to the other functions of this library, the static map functions **do not** perform any query to MapTiler Cloud API, instead they build the image URL for you to use in `\u003cimg\u003e` elements.\n\n\n### Map Styles\nIn the following static map functions, the `option` object features a `style` property that can be a string or one of the built-in style shorthand. Here is the full list:\n\n- `MapStyle.STREETS`, reference style for navigation and city exploration\n  - `MapStyle.STREETS.DARK` (variant)\n  - `MapStyle.STREETS.LIGHT` (variant)\n  - `MapStyle.STREETS.PASTEL` (variant)\n- `MapStyle.OUTDOOR` reference style for adventure\n- `MapStyle.DATAVIZ`, the perfect style for data visualization, with very little noise\n  - `MapStyle.DATAVIZ.DARK` (variant)\n  - `MapStyle.DATAVIZ.LIGHT` (variant)\n- `MapStyle.BACKDROP`, the perfect style for data visualization, with very little noise\n  - `MapStyle.BACKDROP.DARK` (variant)\n  - `MapStyle.BACKDROP.LIGHT` (variant)\n- `MapStyle.WINTER` reference style for winter adventure\n- `MapStyle.SATELLITE` reference style satellite and airborne imagery (no variants)\n- `MapStyle.HYBRID` reference style satellite and airborne imagery with labels (no variants)\n- `MapStyle.BASIC` reference style for minimalist design and general purpose\n  - `MapStyle.BASIC.DARK` (variant)\n  - `MapStyle.BASIC.LIGHT` (variant)\n- `MapStyle.BRIGHT` reference style for high contrast navigation\n  - `MapStyle.BRIGHT.DARK` (variant)\n  - `MapStyle.BRIGHT.LIGHT` (variant)\n  - `MapStyle.BRIGHT.PASTEL` (variant)\n- `MapStyle.TOPO` reference style for topographic study\n  - `MapStyle.TOPO.SHINY` (variant)\n  - `MapStyle.TOPO.PASTEL` (variant)\n  - `MapStyle.TOPO.TOPOGRAPHIQUE` (variant)\n- `MapStyle.VOYAGER` reference style for stylish yet minimalist maps\n  - `MapStyle.VOYAGER.DARK` (variant)\n  - `MapStyle.VOYAGER.LIGHT` (variant)\n  - `MapStyle.VOYAGER.VINTAGE` (variant)\n- `MapStyle.TONER` reference style for very high contrast stylish maps \n  - `MapStyle.TONER.BACKGROUND` (variant)\n  - `MapStyle.TONER.LITE` (variant)\n  - `MapStyle.TONER.LINES` (variant)\n- `MapStyle.OPENSTREETMAP` (reference style, this one does not have any variants)\n- `MapStyle.OCEAN` (reference style, this one does not have any variants)\n\n### Centered static maps\nThis type of map is centered on a longitude-latitude coordinate and the zoom level must also be provided (from `0`: very zoomed out, to `22`: very zoomed in).  \nNote that if a path or markers are provided, the framing of the map will not automatically adapt to include those (use the `automatic` mode for that).\n\n```ts\nconst imageLink = maptilerClient.staticMaps.centered(\n  // center position (Boston)\n  [-71.06080, 42.362114], \n\n  // zoom level\n  12.5, \n  \n  // Options\n  {\n    // Request a hiDPI/Retina image\n    hiDPI: true,\n\n    // Output image size\n    width: 1000,\n    height: 1000,\n\n    // Map style\n    style: maptilerClient.MapStyle.OUTDOOR,\n  });\n```\n\nRead more about centered static maps on our official [API documentation](https://docs.maptiler.com/cloud/api/static-maps/#center-based-image).\n\n\n### Bounded static maps\nThis type of map requires a bounding box made of two points: the south-west bound and the north-east bound. The zoom level cannot be provided and is automatically deduced from the size of the bounding box.\n\n```ts\nconst imageLink = maptilerClient.staticMaps.bounded(\n  // The bounding box on Europe\n  [\n    -24,  // west bound (min x)\n    34.5, // south bound (min y)\n    32,   // east bound (max x)\n    71,   // north bound (max y)\n  ],\n\n  // Options\n  {\n    hiDPI: true,\n    width: 2048,\n    height: 2048,\n    style: maptilerClient.MapStyle.STREETS.DARK,\n\n    // Extra space that will add around the bounding box, in percentage\n    // (0.1 = 10% is actually the dafault)\n    padding: 0.1\n  });\n```\n\nSince the zoom level cannot be provided, the level of details is dictated by the size of the output image. here is an example:\n\n| `2048 x 2048`      | `1024 x 1024` |\n| :-----------: | :-----------: |\n| ![](images/screenshots/static-bounded-europe-2048.png)      | ![](images/screenshots/static-bounded-europe-1024.png)       |\n\nAs you may notice, the geo bounding box could have very different proportions than the output image size. In the following example, we place the very same bounding box around Portugal, which has a this particular strip looking shape. We also add a `path` that repeats exactly the same bounding box to show the difference between the provided bounding box and the final image. We kept the default padding of 10%:\n\n\n| `2048 x 2048`      | `1024 x 2048` |\n| :-----------: | :-----------: |\n| ![](images/screenshots/static-bounded-portugal-2048x2048.png)      | ![](images/screenshots/static-bounded-portugal-1024x2048.png)       |\n\n\nRead more about bounded static maps on our official [API documentation](https://docs.maptiler.com/cloud/api/static-maps/#bounds-based-image).\n\n### Automatic static maps\nAs we have seen with centered and bounded maps, providing all the parameters is nice but can be cumbersome for the simplest use cases. This is why MapTiler Cloud also provides static maps that fits automatically whatever you need to place inside: path or markers.\n\nIn the following example, we are going to load a cycling track recorded by one of our team members in Montreal, Canada. The track, originally a GPX file, was pushed to MapTiler Data and is now made available as a GeoJSON:\n\n```ts\n// Fetching the GeoJSON\nconst bikeTrack = await maptilerClient.data.get('the-id-of-a-bike-track-in-montreal');\n\n// Extracting the track points with the shape [[lng, lat], [lng, lat], ...]\nconst trackPoints = bikeTrack.features[0].geometry.coordinates[0]\n  .map(p =\u003e p.slice(0, 2));\n\nconst imageLink = maptilerClient.staticMaps.automatic({\n  // hiDPI/Retina precision\n  hiDPI: true,\n\n  // A fairly large output image\n  width: 2048,\n  height: 1024 ,\n\n  // A grey style on which the track will pop!\n  style: maptilerClient.MapStyle.STREETS.LIGHT,\n\n  // Draw a path with the trackpoints\n  path: trackPoints,\n\n  // Adding a marker for the starting point, with a custom color (array of shape [lng, lat, color])\n  marker: [trackPoints[0][0], trackPoints[0][1], '#0a0'],\n\n  // Showing the track in red\n  pathStrokeColor: 'red',\n});\n```\n\nAnd voila!\n\n![static map with bike path](images/screenshots/static-with-path.png)\n\n\u003e 📣 *__Note:__* The GeoJSON for this track contains 9380 couples of coordinates, which is a lot! In order to send the track to MapTiler Cloud static maps API, the client simplifies the long paths while keeping a high degree of precision using a very fast [Ramer-Douglas-Peucker algorithm](https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm).\n\nRead more about bounded static maps on our official [API documentation](https://docs.maptiler.com/cloud/api/static-maps/#auto-fitted-image).\n\n## 🏔️ Elevation\nWith the elevation API, it's possible to get the elevation in metter from any location. It's possible lookup and compute elevation for a single location, to provide a batch of points, from a GeoJSON LineString or from a GeoJSON MultiLineString!\n\n\u003e ℹ️ Under the hood, the elevation API is fueled by MapTiler Cloud's **RGB Terrain** raster tileset, which is a composite of many high-resolution DEMs from all over the world, currated and processed by our geodata team! The same dataset is also fueling our SDK's elevation (3D terrain) and the hillshading we use in many of our styles.\n\n\u003e 📣 Note for **TypeScript** users: internaly, the elevation feature relies on some *GeoJSON* types definitions that can be found in this NPM package: `@types/geojson`. Namely `LineString`, `MultiLineString` and `Position`. It may improve your developer experience to also use these types. \n\nLet's see how to use it:\n\n### At a single location\n```ts\n// Not mandatory, but it's to explain where the type comes from:\nimport { Position } from \"geojson\";\n\nconst montBlancPeak: Position = [6.864884, 45.832743];\nconst elevatedPosition = await maptilerClient.elevation.at(montBlancPeak);\n```\nThe returned value is also a *GeoJSON* `Position` array, but with three elements: `[lng, lat, elevation]`.\n\nRead more about elevation lookup for a single location in our [official documentation](https://docs.maptiler.com/client-js/elevation/#at).\n\n### Batch mode\n```ts\n// Not mandatory, but it's to explain where the type comes from:\nimport { Position } from \"geojson\";\n\nconst peaks: Position[] = [\n  [6.864884, 45.832743],   // Mont Blanc, Alps\n  [86.9250, 27.9881],      // Mount Everest, Himalayas\n  [-70.0109, -32.6532],    // Aconcagua, Andes\n  [-151.0064, 63.0695],    // Denali, Alaska\n  [37.3556, -3.0674],      // Mount Kilimanjaro\n  [42.4453, 43.3499],      // Mount Elbrus, Caucasus\n  [137.1595, -4.0784],     // Puncak Jaya, Sudirman Range\n  [-140.4055, 60.5672],    // Mount Logan, Saint Elias Mountains\n  [138.73111, 35.358055],  // Mount Fuji\n];\n\nconst elevatedPeaks = await maptilerClient.elevation.batch(peaks);\n```\n\nRead more about elevation lookup for a batch of locations in our [official documentation](https://docs.maptiler.com/client-js/elevation/#batch).\n\n### From a GeoJSON LineString\nIn the *GeoJSON* LineString case, it clones the entire structure and the positions arrays of the clone will contain three element: `[lng, lat, elevation]`. The original LineString is not mutated nor pointed at.\n\n```ts\n// Not mandatory, but it's to explain where the type comes from:\nimport { LineString } from \"geojson\";\n\n\nconst someLineString: LineString = {\n  type: \"LineString\",\n  coordinates: [[6.864884, 45.832743], [86.9250, 27.9881], [-70.0109, -32.6532]]\n};\n\nconst someElevatedLineString = await maptilerClient.elevation.fromLineString(someLineString);\n// someElevatedLineString is also of type LineString\n```\n\nRead more about elevation lookup for a `LineString` in our [official documentation](https://docs.maptiler.com/client-js/elevation/#linestring).\n\n### From a GeoJSON MultiLineString\nIn the *GeoJSON* MultiLineString case, it clones the entire structure and the positions arrays of the clone will contain three element: `[lng, lat, elevation]`. The original MultiLineString is not mutated nor pointed at.\n\n```ts\n// Not mandatory, but it's to explain where the type comes from:\nimport { MultiLineString } from \"geojson\";\n\n\nconst someMultiLineString: MultiLineString = {\n  type: \"LineString\",\n  coordinates: [\n    [[6.864884, 45.832743], [86.9250, 27.9881], [-70.0109, -32.6532]],\n    [[-151.0064, 63.0695], [37.3556, -3.0674], [42.4453, 43.3499]],\n    [[137.1595, -4.0784], [-140.4055, 60.5672], [138.73111, 35.358055]],\n  ]\n};\n\nconst someElevatedMultiLineString = await maptilerClient.elevation.fromMultiLineString(someMultiLineString);\n// someElevatedMultiLineString is also of type MultiLineString\n```\n\nRead more about elevation lookup for a `MultiLineString` in our [official documentation](https://docs.maptiler.com/client-js/elevation/#multilinestring).\n\n### Caching\nIn order to increase performance while reducing unnecessary elevation data fetching, the elevation tiles are cached. This is particularly important for the LineString and MultiLineString lookups because GeoJSON data are likely to come from a recorded or planned route, where position points are very close to one another.\n\n## 🧮 Math\nSome operations can be fairly repetitive: WGS84 to Mercator, WGS84 to *zxy* tile index, distance between two points with Haversine formula, etc. As a result, we have decided to expose a `math` package providing the most recurent feature, so that, just like us at MapTiler, you no longer need to copy-paste the same function from your previous project!\n\nThe `math` package differs from the others in the sense that it does not call the MapTiler Cloud API, instead it operates fully on the machine it's running on.\n\nHere are some examples:\n\n```ts\n// Not mandatory, but it's to explain where the type comes from:\nimport { Position } from \"geojson\";\n\n// Some constants\nconst earthRadius = maptilerClient.math.EARTH_RADIUS;\nconst earthCircumference = maptilerClient.math.EARTH_CIRCUMFERENCE;\n\nconst montBlancPeakWgs84: Position = [6.864884, 45.832743];\n\n// From WGS84 to Mercator\nconst montBlancPeakMerc = maptilerClient.math.wgs84ToMercator(montBlancPeakWgs84); // also of type Position\n\n// From Mercator to WGS84\nconst montBlancPeakWgs84Again = maptilerClient.math.mercatorToWgs84(montBlancPeakMerc);\n\n// A great-circle distance in meter:\nconst from: Position = /* ... */;\nconst to: Position = /* ... */;\nconst distance = maptilerClient.math.haversineDistanceWgs84(from, to);\n\n// Full distance of a route made of many positions\nconst route: Position[] = /* ... */;\nconst totalDistance = maptilerClient.math.haversineCumulatedDistanceWgs84(route);\n\n// Lon lat to tile index, given a zoom level. An [x, y] array is returned\nconst tileXY = maptilerClient.math.wgs84ToTileIndex(montBlancPeakWgs84, 14);\n// Possible to have floating point tile indices with a third argument to `false`\n\n// and many more!\n```\n\nPlease find out more about the math package in our [official documentation](https://docs.maptiler.com/client-js/math):\n\n# From NodeJS\nNodeJS includes a stable `fetch()` function only from its version *18*, and this client does not contain a polyfill. If the `fetch()` function exists (browser or Node \u003e= 18) then it is going to be resolved automatically, Yet, a custom `fetch()` function can be provided to the `config` object for Node \u003c 18.\n\nIn [this NodeJS example](examples/test-node.js), you can see that the package [Node Fetch](https://www.npmjs.com/package/node-fetch) has been `npm install`ed and is passed to the config object of the *MapTiler Client*.\n\n```js\nimport {\n  config,\n  // ...\n} from '@maptiler/client';\n\n// For this example to work, you must bring your own node-compatible fetch,\n// unles you are using a version of Nodejs that already contains fetch (\u003e=18)\nimport fetch from 'node-fetch';\n\nconfig.fetch = fetch;\n\n// ...\n```\n\n# Terms and usage limitations\nThe data fetched from MapTiler Cloud API, with or without this library, cannot be stored or redistributed in any ways. If you have any doubt about your specific usecase, please consult our [legal terms](https://www.maptiler.com/cloud/terms/#explicitly-prohibited-use) or contact us.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaptiler%2Fmaptiler-client-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaptiler%2Fmaptiler-client-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaptiler%2Fmaptiler-client-js/lists"}