@maptiler/sdk 2.3.0 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/maptiler-sdk.css +1 -1
- package/dist/maptiler-sdk.mjs +8331 -1215
- package/dist/maptiler-sdk.mjs.map +1 -1
- package/dist/src/Map.d.ts +12 -2
- package/dist/src/index.d.ts +1 -0
- package/dist/src/mapstyle.d.ts +16 -1
- package/dist/src/tools.d.ts +4 -0
- package/package.json +3 -2
- package/readme.md +127 -1
package/dist/src/Map.d.ts
CHANGED
|
@@ -28,11 +28,12 @@ export type MapOptions = Omit<MapOptionsML, "style" | "maplibreLogo"> & {
|
|
|
28
28
|
*/
|
|
29
29
|
style?: ReferenceMapStyle | MapStyleVariant | StyleSpecification | string;
|
|
30
30
|
/**
|
|
31
|
-
* Define the language of the map. This can be done directly with a language ISO code (eg. "en")
|
|
31
|
+
* Define the language of the map. This can be done directly with a language ISO code (eg. "en"),
|
|
32
|
+
* the ISO code prepended with the OSM flag (eg. "name:en" or even just "name"),
|
|
32
33
|
* or with a built-in shorthand (eg. Language.ENGLISH).
|
|
33
34
|
* Note that this is equivalent to setting the `config.primaryLanguage` and will overwrite it.
|
|
34
35
|
*/
|
|
35
|
-
language?: LanguageInfo;
|
|
36
|
+
language?: LanguageInfo | string;
|
|
36
37
|
/**
|
|
37
38
|
* Define the MapTiler Cloud API key to be used. This is strictly equivalent to setting
|
|
38
39
|
* `config.apiKey` and will overwrite it.
|
|
@@ -124,7 +125,15 @@ export declare class Map extends maplibregl.Map {
|
|
|
124
125
|
private forceLanguageUpdate;
|
|
125
126
|
private languageAlwaysBeenStyle;
|
|
126
127
|
private isReady;
|
|
128
|
+
private terrainAnimationDuration;
|
|
129
|
+
private monitoredStyleUrls;
|
|
130
|
+
private styleInProcess;
|
|
127
131
|
constructor(options: MapOptions);
|
|
132
|
+
/**
|
|
133
|
+
* Set the duration (millisec) of the terrain animation for growing or flattening.
|
|
134
|
+
* Must be positive. (Built-in default: `1000` milliseconds)
|
|
135
|
+
*/
|
|
136
|
+
setTerrainAnimationDuration(d: number): void;
|
|
128
137
|
/**
|
|
129
138
|
* Awaits for _this_ Map instance to be "loaded" and returns a Promise to the Map.
|
|
130
139
|
* If _this_ Map instance is already loaded, the Promise is resolved directly,
|
|
@@ -149,6 +158,7 @@ export declare class Map extends maplibregl.Map {
|
|
|
149
158
|
* @returns
|
|
150
159
|
*/
|
|
151
160
|
onLoadWithTerrainAsync(): Promise<Map>;
|
|
161
|
+
private monitorStyleUrl;
|
|
152
162
|
/**
|
|
153
163
|
* Update the style of the map.
|
|
154
164
|
* Can be:
|
package/dist/src/index.d.ts
CHANGED
|
@@ -80,6 +80,7 @@ export * from './MaptilerLogoControl';
|
|
|
80
80
|
export * from './MaptilerTerrainControl';
|
|
81
81
|
export * from './MaptilerNavigationControl';
|
|
82
82
|
export { type AutomaticStaticMapOptions, type BoundedStaticMapOptions, type BufferToPixelDataFunction, type ByIdGeocodingOptions, type CenteredStaticMapOptions, type CommonForwardAndReverseGeocodingOptions, type CoordinateExport, type CoordinateGrid, type CoordinateId, type CoordinateSearch, type CoordinateSearchResult, type CoordinateTransformResult, type CoordinateTransformation, type Coordinates, type CoordinatesSearchOptions, type CoordinatesTransformOptions, type DefaultTransformation, type ElevationAtOptions, type ElevationBatchOptions, type FeatureHierarchy, type FetchFunction, type GeocodingFeature, type GeocodingOptions, type GeocodingSearchResult, type GeolocationInfoOptions, type GeolocationResult, type GetDataOptions, type LanguageGeocodingOptions, MapStyle, type MapStylePreset, type MapStyleType, MapStyleVariant, type PixelData, ReferenceMapStyle, type ReverseGeocodingOptions, ServiceError, type StaticMapBaseOptions, type StaticMapMarker, type TileJSON, type XYZ, bufferToPixelDataBrowser, circumferenceAtLatitude, coordinates, data, elevation, expandMapStyle, geocoding, geolocation, getBufferToPixelDataParser, getTileCache, mapStylePresetList, math, misc, staticMaps, styleToStyle, type LanguageInfo, areSameLanguages, toLanguageInfo, isLanguageInfo, getAutoLanguage, getLanguageInfoFromFlag, getLanguageInfoFromCode, getLanguageInfoFromKey, } from '@maptiler/client';
|
|
83
|
+
export { getWebGLSupportError } from './tools';
|
|
83
84
|
export { config, SdkConfig } from './config';
|
|
84
85
|
export * from './language';
|
|
85
86
|
export { type Unit } from './unit';
|
package/dist/src/mapstyle.d.ts
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
1
|
import { ReferenceMapStyle, MapStyleVariant } from '@maptiler/client';
|
|
2
2
|
|
|
3
|
-
export declare function styleToStyle(style: string | ReferenceMapStyle | MapStyleVariant | maplibregl.StyleSpecification | null | undefined):
|
|
3
|
+
export declare function styleToStyle(style: string | ReferenceMapStyle | MapStyleVariant | maplibregl.StyleSpecification | null | undefined): {
|
|
4
|
+
style: string | maplibregl.StyleSpecification;
|
|
5
|
+
requiresUrlMonitoring: boolean;
|
|
6
|
+
isFallback: boolean;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* makes sure a URL is absolute
|
|
10
|
+
*/
|
|
11
|
+
export declare function urlToAbsoluteUrl(url: string): string;
|
|
12
|
+
type StyleValidationReport = {
|
|
13
|
+
isValidJSON: boolean;
|
|
14
|
+
isValidStyle: boolean;
|
|
15
|
+
styleObject: maplibregl.StyleSpecification | null;
|
|
16
|
+
};
|
|
17
|
+
export declare function convertToStyleSpecificationString(str: string): StyleValidationReport;
|
|
18
|
+
export {};
|
package/dist/src/tools.d.ts
CHANGED
|
@@ -44,3 +44,7 @@ export declare function getWebGLSupportError(): string | null;
|
|
|
44
44
|
* Display an error message in the Map div if WebGL2 is not supported
|
|
45
45
|
*/
|
|
46
46
|
export declare function displayNoWebGlWarning(container: HTMLElement | string): void;
|
|
47
|
+
/**
|
|
48
|
+
* Display an error message in the Map div if WebGL2 is not supported
|
|
49
|
+
*/
|
|
50
|
+
export declare function displayWebGLContextLostWarning(container: HTMLElement | string): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maptiler/sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"description": "The Javascript & TypeScript map SDK tailored for MapTiler Cloud",
|
|
5
5
|
"module": "dist/maptiler-sdk.mjs",
|
|
6
6
|
"types": "dist/maptiler-sdk.d.ts",
|
|
@@ -61,10 +61,11 @@
|
|
|
61
61
|
"vitest": "^0.34.2"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
+
"@maplibre/maplibre-gl-style-spec": "^20.3.1",
|
|
64
65
|
"@maptiler/client": "^2.0.0",
|
|
65
66
|
"events": "^3.3.0",
|
|
66
67
|
"js-base64": "^3.7.4",
|
|
67
|
-
"maplibre-gl": "
|
|
68
|
+
"maplibre-gl": "4.7.1",
|
|
68
69
|
"uuid": "^9.0.0"
|
|
69
70
|
}
|
|
70
71
|
}
|
package/readme.md
CHANGED
|
@@ -76,6 +76,37 @@ For example, with a [NextJS](https://nextjs.org/) app, this can take place at th
|
|
|
76
76
|
import "@maptiler/sdk/dist/maptiler-sdk.css";
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
+
### TypeScript
|
|
80
|
+
The SDK is fully typed, but it may happen that types defined in Maplibre GL JS are not visible in your project. This is a known issue that comes from Maplibre being a CommonJS bundle.
|
|
81
|
+
|
|
82
|
+
There are mainly two ways to addess this issue and access to the complete type definition.
|
|
83
|
+
|
|
84
|
+
1. **With `esModuleInterop`**
|
|
85
|
+
|
|
86
|
+
Set the following in your `tsconfig.json`:
|
|
87
|
+
```js
|
|
88
|
+
{
|
|
89
|
+
"compilerOptions": {
|
|
90
|
+
// ...
|
|
91
|
+
"esModuleInterop": true,
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
2. **With `moduleResolution`**
|
|
97
|
+
|
|
98
|
+
Set the following in your `tsconfig.json`:
|
|
99
|
+
```js
|
|
100
|
+
{
|
|
101
|
+
"compilerOptions": {
|
|
102
|
+
// ...
|
|
103
|
+
"moduleResolution": "Bundler",
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
Note that this second option is not always possible as some frameworks and other dependencies won't let you use the "Bundler" mode.
|
|
108
|
+
|
|
109
|
+
|
|
79
110
|
|
|
80
111
|
## With CDN
|
|
81
112
|
The SDK hosted on our CDN is bundled as *[Universal Module Definition](https://github.com/umdjs/umd)* (UMD) to make it standalone and contain all its dependencies. The CDN also serves the style sheet (CSS).
|
|
@@ -340,6 +371,55 @@ map.disableTerrain()
|
|
|
340
371
|
|
|
341
372
|
> 📣 *__Note 2:__* please be aware that due to the volume and elevation of the map floor in 3D space, the navigation with the terrain enabled is slightly different than without.
|
|
342
373
|
|
|
374
|
+
By default, enabling, disabling or even just updating the terrain exaggeration will result in a 1-second animation. This is possible to modify with the following `Map` method:
|
|
375
|
+
|
|
376
|
+
```ts
|
|
377
|
+
// Duration in milliseconds
|
|
378
|
+
map.setTerrainAnimationDuration(500);
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
## Terrain events
|
|
382
|
+
- `"terrain"` event
|
|
383
|
+
|
|
384
|
+
As an extension of Maplibre GL JS, MapTiler SDK is also exposing the terrain event `"terrain"`. This event is triggered when a terrain source is added or removed:
|
|
385
|
+
|
|
386
|
+
```ts
|
|
387
|
+
map.on("terrain", (e) => {
|
|
388
|
+
// your logic here
|
|
389
|
+
})
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
Since MapTiler SDK adds animation and the terrain data is necessary all along, the `"terrain"` event will be called at the very begining of the terrain animation when enabling and at the very end when disabling.
|
|
393
|
+
|
|
394
|
+
- `"terrainAnimationStart"` and `"terrainAnimationStop"` events
|
|
395
|
+
|
|
396
|
+
With the animation of the terrain, it can sometimes be convenient to know when the animation starts and ends. These two events are made just for that, here are how they work:
|
|
397
|
+
|
|
398
|
+
```ts
|
|
399
|
+
map.on("terrainAnimationStart", (event) => {
|
|
400
|
+
console.log("Terrain animation is starting...");
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
map.on("terrainAnimationStop", (event) => {
|
|
404
|
+
console.log("Terrain animation is finished");
|
|
405
|
+
});
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
The `event` argument is an object that contains (amond other things) a `terrain` attribute. In the case of `"terrainAnimationStop"`, this terrain attribute is `null` if the animation was about disabling the terrain, otherwise, this is just a propagation of `map.terrain`.
|
|
409
|
+
|
|
410
|
+
In the following example, we decide to associate the terrain animation with a change of camera, e.g. from clicking on the terrain control:
|
|
411
|
+
- when the terrain is enabled, it pops up with an animation and only **then** the camera is animated to take a lower point of view
|
|
412
|
+
- when the terrain is disabled, it is flattened with an animation and only **then** the camera is animated to a top view
|
|
413
|
+
|
|
414
|
+
```ts
|
|
415
|
+
map.on("terrainAnimationStop", (e) => {
|
|
416
|
+
map.easeTo({
|
|
417
|
+
pitch: e.terrain ? 60 : 0,
|
|
418
|
+
duration: 500,
|
|
419
|
+
});
|
|
420
|
+
});
|
|
421
|
+
```
|
|
422
|
+
|
|
343
423
|
|
|
344
424
|
# Easy language switching
|
|
345
425
|
The language generally depends on the style but we made it possible to easily set and update from a built-in list of languages.
|
|
@@ -388,7 +468,7 @@ Whenever a label is not supported in the defined language, it falls back to `Lan
|
|
|
388
468
|
Here is a sample of some compatible languages:
|
|
389
469
|

|
|
390
470
|
|
|
391
|
-
|
|
471
|
+
## Built-in support for right-to-left languages
|
|
392
472
|
Languages that are written right-to-left such as Arabic and Hebrew are fully supported by default. No need to install any plugins!
|
|
393
473
|
|
|
394
474
|
<p align="center">
|
|
@@ -396,6 +476,31 @@ Languages that are written right-to-left such as Arabic and Hebrew are fully sup
|
|
|
396
476
|
<img src="images/screenshots/lang-hebrew.jpeg" width="48%"></img>
|
|
397
477
|
</p>
|
|
398
478
|
|
|
479
|
+
## Visitor language modes
|
|
480
|
+
The *visitor* language modes are special built-in modes made to display labels in two different languages, concatenated when available:
|
|
481
|
+
- `Language.VISITOR` concatenates labels in the language of your system and the *local* language
|
|
482
|
+
- `Language.VISITOR_ENGLISH` concatenates labels in English and the *local* language
|
|
483
|
+
|
|
484
|
+
```ts
|
|
485
|
+
const map = new Map({
|
|
486
|
+
// some options...
|
|
487
|
+
language: Language.VISITOR,
|
|
488
|
+
})
|
|
489
|
+
|
|
490
|
+
// or
|
|
491
|
+
|
|
492
|
+
const map = new Map({
|
|
493
|
+
// some options...
|
|
494
|
+
language: Language.VISITOR_ENGLISH,
|
|
495
|
+
})
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
We believe these two modes can be very handy to help the end users identify places, especially when the local labels are not using a latin charset. Here is how it looks like:
|
|
499
|
+
|
|
500
|
+

|
|
501
|
+

|
|
502
|
+
|
|
503
|
+
|
|
399
504
|
# Custom Events and Map Lifecycle
|
|
400
505
|
## Events
|
|
401
506
|
### The `ready` event
|
|
@@ -565,6 +670,27 @@ We believe that the *promise* approach is better because it does not nest scopes
|
|
|
565
670
|
|
|
566
671
|
> 📣 *__Note:__* Generally speaking, *promises* are not a go to replacement for all event+callback and are suitable only for events that are called only once in the lifecycle of a Map instance. This is the reason why we have decided to provide a *promise* equivalent only for the `load`, `ready` and `loadWithTerrain` events but not for events that may be called multiple time such as interaction events.
|
|
567
672
|
|
|
673
|
+
### The `webglContextLost` event
|
|
674
|
+
The maps is rendered with WebGL, that leverages the GPU to provide high-performance graphics. In some cases, the host machine, operating system or the graphics driver, can decide that continuing to run such high performance graphics is unsustainable, and will abort the process. This is called a "WebGL context loss". Such situation happens when the ressources are running low or when multiple browser tabs are competing to access graphics memory.
|
|
675
|
+
|
|
676
|
+
The best course of action in such situation varies from an app to another. Sometimes a page refresh is the best thing to do, in other cases, instantiating a new Map dynmicaly at application level is more appropriate because it hides a technical failure to the end user. The event `webglContextLost` is exposed so that the most appropriate scenario can be implemented at application level.
|
|
677
|
+
|
|
678
|
+
Here is how to respond to a WebGL context loss with a simple page refresh:
|
|
679
|
+
```ts
|
|
680
|
+
|
|
681
|
+
// Init the map
|
|
682
|
+
const map = new maptilersdk.Map({
|
|
683
|
+
container: "map-container",
|
|
684
|
+
hash: true,
|
|
685
|
+
})
|
|
686
|
+
|
|
687
|
+
// Refresh the page if context is lost.
|
|
688
|
+
// Since `hash` is true, the location will be the same as before
|
|
689
|
+
map.on("webglContextLost", (e) => {
|
|
690
|
+
location.reload();
|
|
691
|
+
})
|
|
692
|
+
```
|
|
693
|
+
|
|
568
694
|
# Color Ramps
|
|
569
695
|
A color ramp is a color gradient defined in a specific interval, for instance in [0, 1], and for any value within this interval will retrieve a color. They are defined by at least a color at each bound and usually additional colors within the range.
|
|
570
696
|
|