@maptiler/sdk 2.4.1 → 2.4.2

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
@@ -128,6 +128,8 @@ export declare class Map extends maplibregl.Map {
128
128
  private terrainAnimationDuration;
129
129
  private monitoredStyleUrls;
130
130
  private styleInProcess;
131
+ private originalLabelStyle;
132
+ private isStyleLocalized;
131
133
  constructor(options: MapOptions);
132
134
  /**
133
135
  * Set the duration (millisec) of the terrain animation for growing or flattening.
@@ -1,4 +1,5 @@
1
- import { RequestParameters, ResourceType, RequestTransformFunction } from 'maplibre-gl';
1
+ import { default as maplibregl, RequestParameters, ResourceType, RequestTransformFunction } from 'maplibre-gl';
2
+ import { Map as MapSDK } from './Map';
2
3
 
3
4
  export declare function enableRTL(): void;
4
5
  export declare function bindAll(fns: Array<string>, context: any): void;
@@ -48,3 +49,41 @@ export declare function displayNoWebGlWarning(container: HTMLElement | string):
48
49
  * Display an error message in the Map div if WebGL2 is not supported
49
50
  */
50
51
  export declare function displayWebGLContextLostWarning(container: HTMLElement | string): void;
52
+ /**
53
+ * In a text-field style property (as an object, not a string) the languages that are specified as
54
+ * ["get", "name:XX"] are replaced by the proved replacer (also an object).
55
+ * This replacement happened regardless of how deep in the object the flag is.
56
+ * Note that it does not replace the occurences of ["get", "name"] (local names)
57
+ */
58
+ export declare function changeFirstLanguage(origExpr: maplibregl.ExpressionSpecification, replacer: maplibregl.ExpressionSpecification, localized: boolean): maplibregl.ExpressionSpecification;
59
+ /**
60
+ * If `localized` is `true`, it checks for the pattern "{name:xx}" (with "xx" being a language iso string).
61
+ * If `localized` is `false`, it check for {name}.
62
+ * In a exact way or is a loose way (such as "foo {name:xx}" or "foo {name} bar")
63
+ */
64
+ export declare function checkNamePattern(str: string, localized: boolean): {
65
+ contains: boolean;
66
+ exactMatch: boolean;
67
+ };
68
+ /**
69
+ * Replaces the occurences of {name:xx} in a string by a provided object-expression to return a concat object expression
70
+ */
71
+ export declare function replaceLanguage(origLang: string, newLang: maplibregl.ExpressionSpecification, localized: boolean): maplibregl.ExpressionSpecification;
72
+ /**
73
+ * Find languages used in string label definition.
74
+ * The returned array contains languages such as "en", "fr" but
75
+ * can also contain null that stand for the use of {name}
76
+ */
77
+ export declare function findLanguageStr(str: string): Array<string | null>;
78
+ /**
79
+ * Find languages used in object label definition.
80
+ * The returned array contains languages such as "en", "fr" but
81
+ * can also contain null that stand for the use of {name}
82
+ */
83
+ export declare function findLanguageObj(origExpr: maplibregl.ExpressionSpecification): Array<string | null>;
84
+ export declare function computeLabelsLocalizationMetrics(layers: maplibregl.LayerSpecification[], map: MapSDK): {
85
+ unlocalized: number;
86
+ localized: {
87
+ [k: string]: number;
88
+ };
89
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maptiler/sdk",
3
- "version": "2.4.1",
3
+ "version": "2.4.2",
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",
package/readme.md CHANGED
@@ -47,7 +47,7 @@ maptilersdk.config.apiKey = 'YOUR_API_KEY';
47
47
  // Let's say you have a DIV ready to receive a map
48
48
  const mapContainer = document.getElementById('my-container-div');
49
49
 
50
- // Instanciate the map
50
+ // Instantiate the map
51
51
  const map = new maptilersdk.Map({
52
52
  container: mapContainer,
53
53
  });
@@ -60,16 +60,16 @@ import * as maptilersdk from '@maptiler/sdk';
60
60
  // Let's say you have a DIV ready to receive a map
61
61
  const mapContainer = document.getElementById('my-container-div');
62
62
 
63
- // Instanciate the map
63
+ // Instantiate the map
64
64
  const map = new maptilersdk.Map({
65
65
  container: mapContainer,
66
- apiKey: 'YOUR_API_KEY';
66
+ apiKey: 'YOUR_API_KEY'
67
67
  });
68
68
  ```
69
69
 
70
70
  By default, the map will be initialized with the style [streets-v2](https://www.maptiler.com/maps/#style=streets-v2).
71
71
 
72
- Depending on the framework and environment you are using for your application, you will have to also include the CSS file.
72
+ Depending on the framework and environment you are using for your application, you will have to also include the CSS file.
73
73
 
74
74
  For example, with a [NextJS](https://nextjs.org/) app, this can take place at the top of the file `_app.ts/js`:
75
75
  ```ts
@@ -79,7 +79,7 @@ import "@maptiler/sdk/dist/maptiler-sdk.css";
79
79
  ### TypeScript
80
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
81
 
82
- There are mainly two ways to addess this issue and access to the complete type definition.
82
+ There are mainly two ways to address this issue and access to the complete type definition.
83
83
 
84
84
  1. **With `esModuleInterop`**
85
85
 
@@ -237,7 +237,7 @@ All reference styles (instances of `ReferenceMapStyle`) and style variants (inst
237
237
  ___
238
238
 
239
239
 
240
- Still, you can still use some classic styles with just a *string* if you know their MapTiler Cloud ID:
240
+ You can also use classic styles with just a *string* if you know their MapTiler Cloud ID:
241
241
 
242
242
  ```ts
243
243
  map.setStyle('outdoor-v2');
@@ -290,7 +290,7 @@ The `geolocation` options will not be taken into consideration in the following
290
290
 
291
291
  > 📣 *__Note:__* if none of the options `center` or `hash` is provided to the `Map` constructor, then the map will be centered using the `POINT` strategy, unless the `geolocate` has the value `false`.
292
292
 
293
- > 📣 *__Note 2:__* the term *IP geolocation* refers to finding the physical location of a computer using its *IP address*. The *IP address* is a numerical identifier of a computer within a network, just like the phone number for a telephone. The *IP geolocation* is **not** using the GPS of a device and usually provides a precision in the order of a few hundred meters. This precision may vary based on many local parameters such as the density of the network grid or the terrain, this is why it is generaly better not to use a zoom level higher than `14`.
293
+ > 📣 *__Note 2:__* the term *IP geolocation* refers to finding the physical location of a computer using its *IP address*. The *IP address* is a numerical identifier of a computer within a network, just like the phone number for a telephone. The *IP geolocation* is **not** using the GPS of a device and usually provides a precision in the order of a few hundred meters. This precision may vary based on many local parameters such as the density of the network grid or the terrain, this is why it is generally better not to use a zoom level higher than `14`.
294
294
 
295
295
  # Easy to add controls
296
296
  The term "control" is commonly used for all sorts of buttons and information displays that take place in one of the corners of the map area. The most well-known are probably the `[+]` and `[-]` zoom buttons as well as the attribution information. Plenty of others are possible and we have made a few easy to add and directly accessible from the `Map` constructor options:
@@ -367,7 +367,7 @@ Or simply disable it:
367
367
  map.disableTerrain()
368
368
  ```
369
369
 
370
- > 📣 *__Note:__* Keep in mind that setting an exaggeration factor at `0` will result in a the same result as disabling the elevation but that terrain RGB tiles will still be fetched in the background.
370
+ > 📣 *__Note:__* Keep in mind that setting an exaggeration factor at `0` will result in the same result as disabling the elevation but that terrain RGB tiles will still be fetched in the background.
371
371
 
372
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.
373
373
 
@@ -389,7 +389,7 @@ map.on("terrain", (e) => {
389
389
  })
390
390
  ```
391
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.
392
+ Since MapTiler SDK adds animation and the terrain data is necessary all along, the `"terrain"` event will be called at the very beginning of the terrain animation when enabling and at the very end when disabling.
393
393
 
394
394
  - `"terrainAnimationStart"` and `"terrainAnimationStop"` events
395
395
 
@@ -405,7 +405,7 @@ map.on("terrainAnimationStop", (event) => {
405
405
  });
406
406
  ```
407
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`.
408
+ The `event` argument is an object that contains (among 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
409
 
410
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
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
@@ -541,7 +541,7 @@ function init() {
541
541
  });
542
542
 
543
543
  // We wait for the event.
544
- // Once triggered, the callback is ranin it's own scope.
544
+ // Once triggered, the callback is ran in its own scope.
545
545
  map.on("load", (evt) => {
546
546
  // Adding a data source
547
547
  map.addSource('my-gps-track-source', {
@@ -633,7 +633,7 @@ function init() {
633
633
  });
634
634
 
635
635
  // We wait for the event.
636
- // Once triggered, the callback is ranin it's own scope.
636
+ // Once triggered, the callback is ran in its own scope.
637
637
  map.on("ready", (evt) => {
638
638
  // Adding a data source
639
639
  map.addSource('my-gps-track-source', {
@@ -671,9 +671,9 @@ We believe that the *promise* approach is better because it does not nest scopes
671
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.
672
672
 
673
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.
674
+ The map 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 resources are running low or when multiple browser tabs are competing to access graphics memory.
675
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.
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 dynamically 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
677
 
678
678
  Here is how to respond to a WebGL context loss with a simple page refresh:
679
679
  ```ts
@@ -764,13 +764,13 @@ maptilersdk.helpers
764
764
 
765
765
  **Example:** we have a *geoJSON* file that contains both *polygons* and *point* and we use it as the `data` property on the `helpers.addPoint(map, { options })`, this will only add the *points*.
766
766
 
767
- In addition to easy styling, the helper's datasource can be:
767
+ In addition to easy styling, the helpers' datasource can be:
768
768
  - a URL to a geoJSON file or its string content
769
769
  - a URL to a GPX or KML file (only for the polyline helper) or its string content
770
770
  - a UUID of a MapTiler Cloud dataset
771
771
 
772
772
  ### Multiple Layers
773
- The key design principle of these vector layer helpers is **it's easy to make what you want**, which is very different from **making MapLibre easier to use**.
773
+ The key design principle of these vector layer helpers is **it's easy to make what you want**, which is very different from **making MapLibre easier to use**.
774
774
 
775
775
  > For example, to create a road with an outline, one must draw two layers: a wider base layer and a narrower top layer, fueled by the same polyline data. This requires ordering the layers properly and computing not the width of the outline, but rather the width of the polyline underneath so that it outgrows the top road layer of the desired number of pixels.
776
776
 
@@ -859,13 +859,12 @@ helpers.addPolyline(map, {
859
859
 
860
860
  Endless possibilities, what about a glowing wire?
861
861
  ```ts
862
- helpers.addPolyline(map, {
862
+ helpers.addPolyline(map, {
863
863
  data: "74003ba7-215a-4b7e-8e26-5bbe3aa70b05",
864
864
  lineColor: "#fff",
865
865
  lineWidth: 1,
866
866
  outline: true,
867
867
  outlineColor: "#ca57ff",
868
- outlineWidth: 2,
869
868
  outlineWidth: 10,
870
869
  outlineBlur: 10,
871
870
  outlineOpacity: 0.5,
@@ -877,7 +876,7 @@ helpers.addPolyline(map, {
877
876
  All the other options are documented on [our reference page](https://docs.maptiler.com/sdk-js/api/helpers/#polyline) and more examples are available [here](https://docs.maptiler.com/sdk-js/examples/?q=polyline+helper).
878
877
 
879
878
  ## Polygon Layer Helper
880
- The polygon helper makes it easy to create vector layers that contain polygons, whether they are *multi*polylons, *holed*polygons or just simple polygons. Whenever it's possible and it makes sense, we use the same terminology across the different helpers.
879
+ The polygon helper makes it easy to create vector layers that contain polygons, whether they are *multi*polygons, *holed*polygons or just simple polygons. Whenever it's possible and it makes sense, we use the same terminology across the different helpers.
881
880
 
882
881
  Here is a minimalist example, with a half-transparent polygon of Switzerland, from a local file:
883
882
 
package/tsconfig.json CHANGED
@@ -2,10 +2,10 @@
2
2
  "compilerOptions": {
3
3
  "baseUrl": "src",
4
4
  "moduleResolution": "Node",
5
- "target": "ES2020",
5
+ "target": "es2021",
6
6
  "useDefineForClassFields": true,
7
7
  "module": "ESNext",
8
- "lib": ["ES2020", "DOM", "DOM.Iterable"],
8
+ "lib": ["es2021", "DOM", "DOM.Iterable"],
9
9
  "skipLibCheck": true,
10
10
 
11
11
  /* Bundler mode */