@maptiler/sdk 2.3.0 → 2.4.0

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/src/Map.d.ts CHANGED
@@ -124,7 +124,15 @@ export declare class Map extends maplibregl.Map {
124
124
  private forceLanguageUpdate;
125
125
  private languageAlwaysBeenStyle;
126
126
  private isReady;
127
+ private terrainAnimationDuration;
128
+ private monitoredStyleUrls;
129
+ private styleInProcess;
127
130
  constructor(options: MapOptions);
131
+ /**
132
+ * Set the duration (millisec) of the terrain animation for growing or flattening.
133
+ * Must be positive. (Built-in default: `1000` milliseconds)
134
+ */
135
+ setTerrainAnimationDuration(d: number): void;
128
136
  /**
129
137
  * Awaits for _this_ Map instance to be "loaded" and returns a Promise to the Map.
130
138
  * If _this_ Map instance is already loaded, the Promise is resolved directly,
@@ -149,6 +157,7 @@ export declare class Map extends maplibregl.Map {
149
157
  * @returns
150
158
  */
151
159
  onLoadWithTerrainAsync(): Promise<Map>;
160
+ private monitorStyleUrl;
152
161
  /**
153
162
  * Update the style of the map.
154
163
  * Can be:
@@ -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';
@@ -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): string | maplibregl.StyleSpecification;
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 {};
@@ -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.0",
3
+ "version": "2.4.0",
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": "^4.7.0",
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.
@@ -565,6 +645,27 @@ We believe that the *promise* approach is better because it does not nest scopes
565
645
 
566
646
  > 📣 *__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
647
 
648
+ ### The `webglContextLost` event
649
+ 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.
650
+
651
+ 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.
652
+
653
+ Here is how to respond to a WebGL context loss with a simple page refresh:
654
+ ```ts
655
+
656
+ // Init the map
657
+ const map = new maptilersdk.Map({
658
+ container: "map-container",
659
+ hash: true,
660
+ })
661
+
662
+ // Refresh the page if context is lost.
663
+ // Since `hash` is true, the location will be the same as before
664
+ map.on("webglContextLost", (e) => {
665
+ location.reload();
666
+ })
667
+ ```
668
+
568
669
  # Color Ramps
569
670
  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
671