@maptiler/sdk 1.0.7 → 1.0.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maptiler/sdk",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
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
@@ -165,10 +165,13 @@ Here is the full list:
165
165
  - `MapStyle.STREETS.DARK` (variant)
166
166
  - `MapStyle.STREETS.LIGHT` (variant)
167
167
  - `MapStyle.STREETS.PASTEL` (variant)
168
- - `MapStyle.OUTDOOR` reference style for adventure
169
- - `MapStyle.WINTER` reference style for winter adventure
170
168
  - `MapStyle.SATELLITE` reference style satellite and airborne imagery (no variants)
171
169
  - `MapStyle.HYBRID` reference style satellite and airborne imagery with labels (no variants)
170
+ - `MapStyle.OUTDOOR` reference style for adventure
171
+ - `MapStyle.WINTER` reference style for winter adventure
172
+ - `MapStyle.DATAVIZ`, the perfect style for data visualization, with very little noise
173
+ - `MapStyle.DATAVIZ.DARK` (variant)
174
+ - `MapStyle.DATAVIZ.LIGHT` (variant)
172
175
  - `MapStyle.BASIC` reference style for minimalist design and general purpose
173
176
  - `MapStyle.BASIC.DARK` (variant)
174
177
  - `MapStyle.BASIC.LIGHT` (variant)
@@ -189,9 +192,7 @@ Here is the full list:
189
192
  - `MapStyle.TONER.LITE` (variant)
190
193
  - `MapStyle.TONER.LINES` (variant)
191
194
  - `MapStyle.OPENSTREETMAP` (reference style, this one does not have any variants)
192
- - `MapStyle.DATAVIZ`, the perfect style for data visualization, with very little noise
193
- - `MapStyle.DATAVIZ.DARK` (variant)
194
- - `MapStyle.DATAVIZ.LIGHT` (variant)
195
+
195
196
 
196
197
  All reference styles (instances of `ReferenceMapStyle`) and style variants (instances of `MapStyleVariant`) have methods to know the alternative styles and variant that belong to the same reference style (`.getVariants()`). This is handy to provide a default/dark/light alternative color scheme, yet preserving the same level of details as in the reference style. Read more about about [ReferenceMapStyle](docsmd/classes/ReferenceMapStyle.md) and [MapStyleVariant](docsmd/classes/MapStyleVariant.md).
197
198
  </details>
package/src/Map.ts CHANGED
@@ -140,6 +140,8 @@ export class Map extends maplibregl.Map {
140
140
  private isStyleInitialized = false;
141
141
  private isTerrainEnabled = false;
142
142
  private terrainExaggeration = 1;
143
+ private primaryLanguage: LanguageString | null = null;
144
+ private secondaryLanguage: LanguageString | null = null;
143
145
 
144
146
  constructor(options: MapOptions) {
145
147
  // if (options.language) {
@@ -197,6 +199,9 @@ export class Map extends maplibregl.Map {
197
199
  },
198
200
  });
199
201
 
202
+ this.primaryLanguage = options.language ?? config.primaryLanguage;
203
+ this.secondaryLanguage = config.secondaryLanguage;
204
+
200
205
  // Map centering and geolocation
201
206
  this.once("styledata", async () => {
202
207
  // Not using geolocation centering if...
@@ -271,40 +276,10 @@ export class Map extends maplibregl.Map {
271
276
  }
272
277
  });
273
278
 
274
- // Check if language has been modified and. If so, it will be updated during the next lifecycle step
275
- this.on("styledataloading", () => {
276
- this.languageShouldUpdate =
277
- !!config.primaryLanguage || !!config.secondaryLanguage;
278
- });
279
-
280
- // To flag if the language was already initialized at build time
281
- // so that the language optionnaly passed in constructor is
282
- // considered only once and at instanciation time.
283
- let initLanguageFromConstructor = true;
284
-
285
279
  // If the config includes language changing, we must update the map language
286
280
  this.on("styledata", () => {
287
- // If the language is set as a constructor options,
288
- // This prevails on the language from the config.
289
- if (options.language && initLanguageFromConstructor) {
290
- this.setPrimaryLanguage(options.language);
291
- } else if (
292
- config.primaryLanguage &&
293
- (this.languageShouldUpdate || !this.isStyleInitialized)
294
- ) {
295
- this.setPrimaryLanguage(config.primaryLanguage);
296
- }
297
-
298
- if (
299
- config.secondaryLanguage &&
300
- (this.languageShouldUpdate || !this.isStyleInitialized)
301
- ) {
302
- this.setSecondaryLanguage(config.secondaryLanguage);
303
- }
304
-
305
- this.languageShouldUpdate = false;
306
- this.isStyleInitialized = true;
307
- initLanguageFromConstructor = false;
281
+ this.setPrimaryLanguage(this.primaryLanguage);
282
+ this.setSecondaryLanguage(this.secondaryLanguage);
308
283
  });
309
284
 
310
285
  // this even is in charge of reaplying the terrain elevation after the
@@ -495,6 +470,8 @@ export class Map extends maplibregl.Map {
495
470
  return;
496
471
  }
497
472
 
473
+ this.primaryLanguage = language;
474
+
498
475
  this.onStyleReady(() => {
499
476
  if (language === Language.AUTO) {
500
477
  return this.setPrimaryLanguage(getBrowserLanguage());
@@ -649,7 +626,7 @@ export class Map extends maplibregl.Map {
649
626
  }
650
627
 
651
628
  /**
652
- * Define the secondary language of the map.
629
+ * Define the secondary language of the map. Note that this is not supported by all the map styles
653
630
  * Note that most styles do not allow a secondary language and this function only works if the style allows (no force adding)
654
631
  * @param language
655
632
  */
@@ -658,6 +635,8 @@ export class Map extends maplibregl.Map {
658
635
  return;
659
636
  }
660
637
 
638
+ this.secondaryLanguage = language;
639
+
661
640
  this.onStyleReady(() => {
662
641
  if (language === Language.AUTO) {
663
642
  return this.setSecondaryLanguage(getBrowserLanguage());
@@ -780,6 +759,22 @@ export class Map extends maplibregl.Map {
780
759
  });
781
760
  }
782
761
 
762
+ /**
763
+ * Get the primary language
764
+ * @returns
765
+ */
766
+ getPrimaryLanguage(): LanguageString {
767
+ return this.primaryLanguage;
768
+ }
769
+
770
+ /**
771
+ * Get the secondary language
772
+ * @returns
773
+ */
774
+ getSecondaryLanguage(): LanguageString {
775
+ return this.secondaryLanguage;
776
+ }
777
+
783
778
  /**
784
779
  * Get the exaggeration factor applied to the terrain
785
780
  * @returns