You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Javascript & TypeScript API client library to enjoy <ahref="https://www.maptiler.com/cloud/">MapTiler Cloud</a>'s <br>services such as geocoding, geolocation and more!
The **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:
22
6
-[Geocoding forward and reverse](#-geocoding)
23
7
-[Geolocation from visitor's IP address](#%EF%B8%8F%EF%B8%8F-geolocation)
@@ -26,8 +10,6 @@ The **MapTiler Client JS** exposes a number of handy functions that wrap API cal
26
10
-[Static maps of all sorts](#%EF%B8%8F-static-maps)
27
11
-[Elevation lookup with batch features](#-elevation)
28
12
29
-
## Why?
30
-
31
13
The project is entirely written in TypeScript and all the function arguments are nicely documented and typed.
32
14
33
15
- Better developer experience of working with APIs in the code editor - with parameter info, quick info, and member lists.
@@ -38,15 +20,63 @@ The project is entirely written in TypeScript and all the function arguments are
In addition to the details and examples provided in this readme, check out the [complete API documentation](https://docs.maptiler.com/client-js/).
56
+
### From NodeJS
57
+
NodeJS 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 >= 18) then it is going to be resolved automatically, Yet, a custom `fetch()` function can be provided to the `config` object for Node < 18.
58
+
59
+
In [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*.
60
+
61
+
```js
62
+
import {
63
+
config,
64
+
// ...
65
+
} from'@maptiler/client';
66
+
67
+
// For this example to work, you must bring your own node-compatible fetch,
68
+
// unles you are using a version of Nodejs that already contains fetch (>=18)
69
+
importfetchfrom'node-fetch';
70
+
71
+
config.fetch= fetch;
72
+
73
+
// ...
74
+
```
75
+
76
+
<br>
77
+
78
+
## 🚀 Basic Usage
48
79
49
-
# Quick start
50
80
```ts
51
81
// Import the whole library
52
82
import*asmaptilerClientfrom'@maptiler/client';
@@ -64,15 +94,30 @@ import {
64
94
} from'@maptiler/client';
65
95
```
66
96
97
+
<br>
98
+
99
+
## 💡 Related Examples
100
+
67
101
The [examples](examples/) folder includes are featuring usages for **NodeJS**, **browser with UMD** and **browser with ES module**.
68
102
69
-
# Easy access to MapTiler Cloud API
103
+
<br>
104
+
105
+
## 📘 API Reference
106
+
107
+
For detailed guides, API reference, and advanced examples, visit our comprehensive documentation:
Here is the list of service wrapper functions that are built-in:
71
114
72
-
## 🔍 Geocoding
115
+
### 🔍 Geocoding
116
+
73
117
> ✅ 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) ⚖️
74
118
75
-
### Forward
119
+
#### Forward
120
+
76
121
You want to know the longitude and latitude of a specific place, use the forward geocoding:
77
122
```ts
78
123
// in an async function, or as a 'thenable':
@@ -85,7 +130,8 @@ You can provide some options such as:
85
130
86
131
Read 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).
87
132
88
-
### Reverse
133
+
#### Reverse
134
+
89
135
You wan to tknow the name of a place, given a longitude-latitude? Use the reverse geocoding:
90
136
```ts
91
137
// in an async function, or as a 'thenable':
@@ -95,7 +141,8 @@ The same option object as the forward geocoding can be provided.
95
141
96
142
Read more about reverse geocoding on our [official documentation](https://docs.maptiler.com/client-js/geocoding/#reverse).
97
143
98
-
### Language
144
+
#### Language
145
+
99
146
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:
100
147
101
148
```ts
@@ -106,7 +153,8 @@ The special language `AUTO` will detect the platform/browser preferred language.
106
153
107
154
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)).
108
155
109
-
## 🕵️♂️ Geolocation
156
+
### 🕵️♂️ Geolocation
157
+
110
158
The geolocation service provides location informations of a visitor using its IP address.
111
159
112
160
The 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.
@@ -119,10 +167,12 @@ const result = await maptilerClient.geolocation.info();
119
167
120
168
Read more about geolocation on our [official documentation](https://docs.maptiler.com/client-js/geolocation/).
121
169
122
-
## 🌐 Coordinates
170
+
### 🌐 Coordinates
171
+
123
172
If 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!
124
173
125
-
### Search
174
+
#### Search
175
+
126
176
The `search` lets you perform a query in a free form fashion. Here are some examples:
127
177
```ts
128
178
// in an async function, or as a 'thenable':
@@ -136,7 +186,8 @@ The `transformations` options retrieves a lot more details about the CRS that Ma
136
186
137
187
Read more about searching coordinate systems on our [official documentation](https://docs.maptiler.com/client-js/coordinates/#search).
138
188
139
-
### Transform
189
+
#### Transform
190
+
140
191
Transforming 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).
141
192
142
193
If 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:
Read more about transforming coordinates on our [official documentation](https://docs.maptiler.com/client-js/coordinates/#transform).
155
206
156
-
## 💽 Data
207
+
### 💽 Data
208
+
157
209
MapTiler 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:
158
210
159
211
```ts
@@ -165,7 +217,8 @@ Since the result is a GeoJSON, it can easily be added to a `map` with `.addSourc
165
217
166
218
Read more about fetching your own data on our [official documentation](https://docs.maptiler.com/client-js/data/).
167
219
168
-
## 🗺️ Static maps
220
+
### 🗺️ Static maps
221
+
169
222
> ✅ Please, use static maps URLs only from client side `<img>` 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) ⚖️
170
223
171
224
Maptiler Cloud provides many possibilities for creating static maps as PNG, JPEG or WebP images. They all offer the possibilities to:
@@ -178,8 +231,8 @@ Three modes are available: `centered`, `bounded` and `automatic`.
178
231
> 📣 *__important:__* <spanstyle="text-decoration: underline">only image **URLs** are returned.</span>
179
232
> 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 `<img>` elements.
180
233
234
+
#### Map Styles
181
235
182
-
### Map Styles
183
236
In 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:
184
237
185
238
-`MapStyle.STREETS`, reference style for navigation and city exploration
@@ -218,7 +271,8 @@ In the following static map functions, the `option` object features a `style` pr
218
271
-`MapStyle.OPENSTREETMAP` (reference style, this one does not have any variants)
219
272
-`MapStyle.OCEAN` (reference style, this one does not have any variants)
220
273
221
-
### Centered static maps
274
+
#### Centered static maps
275
+
222
276
This 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).
223
277
Note 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).
Read more about centered static maps on our official [API documentation](https://docs.maptiler.com/cloud/api/static-maps/#center-based-image).
248
302
303
+
#### Bounded static maps
249
304
250
-
### Bounded static maps
251
305
This 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.
252
306
253
307
```ts
@@ -289,7 +343,8 @@ As you may notice, the geo bounding box could have very different proportions th
289
343
290
344
Read more about bounded static maps on our official [API documentation](https://docs.maptiler.com/cloud/api/static-maps/#bounds-based-image).
291
345
292
-
### Automatic static maps
346
+
#### Automatic static maps
347
+
293
348
As 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.
294
349
295
350
In 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:
@@ -332,7 +387,8 @@ And voila!
332
387
333
388
Read more about bounded static maps on our official [API documentation](https://docs.maptiler.com/cloud/api/static-maps/#auto-fitted-image).
334
389
335
-
## 🏔️ Elevation
390
+
### 🏔️ Elevation
391
+
336
392
With 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!
337
393
338
394
> ℹ️ 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.
@@ -341,7 +397,8 @@ With the elevation API, it's possible to get the elevation in metter from any lo
341
397
342
398
Let's see how to use it:
343
399
344
-
### At a single location
400
+
#### At a single location
401
+
345
402
```ts
346
403
// Not mandatory, but it's to explain where the type comes from:
347
404
import { Position } from"geojson";
@@ -353,7 +410,8 @@ The returned value is also a *GeoJSON* `Position` array, but with three elements
353
410
354
411
Read more about elevation lookup for a single location in our [official documentation](https://docs.maptiler.com/client-js/elevation/#at).
355
412
356
-
### Batch mode
413
+
#### Batch mode
414
+
357
415
```ts
358
416
// Not mandatory, but it's to explain where the type comes from:
Read more about elevation lookup for a batch of locations in our [official documentation](https://docs.maptiler.com/client-js/elevation/#batch).
377
435
378
-
### From a GeoJSON LineString
436
+
#### From a GeoJSON LineString
437
+
379
438
In 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.
Read more about elevation lookup for a `LineString` in our [official documentation](https://docs.maptiler.com/client-js/elevation/#linestring).
396
455
397
-
### From a GeoJSON MultiLineString
456
+
#### From a GeoJSON MultiLineString
457
+
398
458
In 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.
Read more about elevation lookup for a `MultiLineString` in our [official documentation](https://docs.maptiler.com/client-js/elevation/#multilinestring).
419
479
420
-
### Caching
480
+
#### Caching
481
+
421
482
In 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.
422
483
423
-
## 🧮 Math
484
+
### 🧮 Math
485
+
424
486
Some 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!
425
487
426
488
The `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.
Please find out more about the math package in our [official documentation](https://docs.maptiler.com/client-js/math):
524
+
Please find out more about the math package in our [official documentation](https://docs.maptiler.com/client-js/math).
463
525
464
-
# From NodeJS
465
-
NodeJS 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 >= 18) then it is going to be resolved automatically, Yet, a custom `fetch()` function can be provided to the `config` object for Node < 18.
526
+
<br>
466
527
467
-
In [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*.
528
+
## 💬 Support
468
529
469
-
```js
470
-
import {
471
-
config,
472
-
// ...
473
-
} from'@maptiler/client';
530
+
- 📚 [Documentation](https://docs.maptiler.com/client-js/) - Comprehensive guides and API reference
531
+
- ✉️ [Contact us](https://maptiler.com/contact) - Get in touch or submit a request
532
+
- 🐦 [Twitter/X](https://twitter.com/maptiler) - Follow us for updates
474
533
475
-
// For this example to work, you must bring your own node-compatible fetch,
476
-
// unles you are using a version of Nodejs that already contains fetch (>=18)
477
-
importfetchfrom'node-fetch';
534
+
<br>
478
535
479
-
config.fetch= fetch;
536
+
---
480
537
481
-
// ...
482
-
```
538
+
<br>
539
+
540
+
## 🤝 Contributing
541
+
542
+
We love contributions from the community! Whether it's bug reports, feature requests, or pull requests, all contributions are welcome:
543
+
544
+
- Fork the repository and create your branch from `main`
545
+
- If you've added code, add tests that cover your changes
546
+
- Ensure your code follows our style guidelines
547
+
- Give your pull request a clear, descriptive summary
548
+
- Open a Pull Request with a comprehensive description
549
+
550
+
<br>
551
+
552
+
## 📄 License
553
+
554
+
This project is licensed under the BSD 3-Clause License – see the [LICENSE](./LICENSE) file for details.
555
+
556
+
### Terms and usage limitations
483
557
484
-
# Terms and usage limitations
485
558
The 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.
559
+
560
+
<br>
561
+
562
+
<palign="center"style="margin-top:20px;margin-bottom:20px;"> <ahref="https://cloud.maptiler.com/account/keys/"style="display:inline-block;padding:12px32px;background:#F2F6FF;color:#000;font-weight:bold;border-radius:6px;text-decoration:none;"> Get Your API Key <supstyle="background-color:#0000ff;color:#fff;padding:2px6px;font-size:12px;border-radius:3px;">FREE</sup><br /> <spanstyle="font-size:90%;font-weight:400;">Start building with 100,000 free map loads per month ・ No credit card required.</span> </a> </p>
563
+
564
+
<br>
565
+
566
+
<palign="center"> 💜 Made with love by the <ahref="https://www.maptiler.com/">MapTiler</a> team <br />
0 commit comments