@maptiler/sdk 1.1.2 → 1.2.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.
Files changed (41) hide show
  1. package/.eslintrc.cjs +15 -5
  2. package/.github/pull_request_template.md +11 -0
  3. package/.github/workflows/format-lint.yml +24 -0
  4. package/CHANGELOG.md +94 -51
  5. package/colorramp.md +93 -0
  6. package/dist/maptiler-sdk.d.ts +1207 -123
  7. package/dist/maptiler-sdk.min.mjs +3 -1
  8. package/dist/maptiler-sdk.mjs +3561 -485
  9. package/dist/maptiler-sdk.mjs.map +1 -1
  10. package/dist/maptiler-sdk.umd.js +3825 -869
  11. package/dist/maptiler-sdk.umd.js.map +1 -1
  12. package/dist/maptiler-sdk.umd.min.js +51 -49
  13. package/package.json +27 -13
  14. package/readme.md +298 -0
  15. package/rollup.config.js +2 -16
  16. package/src/Map.ts +489 -357
  17. package/src/MaptilerGeolocateControl.ts +23 -20
  18. package/src/MaptilerLogoControl.ts +3 -3
  19. package/src/MaptilerNavigationControl.ts +9 -6
  20. package/src/MaptilerTerrainControl.ts +15 -14
  21. package/src/Minimap.ts +373 -0
  22. package/src/Point.ts +3 -5
  23. package/src/colorramp.ts +1216 -0
  24. package/src/config.ts +4 -3
  25. package/src/converters/index.ts +1 -0
  26. package/src/converters/xml.ts +681 -0
  27. package/src/defaults.ts +1 -1
  28. package/src/helpers/index.ts +27 -0
  29. package/src/helpers/stylehelper.ts +395 -0
  30. package/src/helpers/vectorlayerhelpers.ts +1511 -0
  31. package/src/index.ts +10 -0
  32. package/src/language.ts +116 -79
  33. package/src/mapstyle.ts +4 -2
  34. package/src/tools.ts +68 -16
  35. package/tsconfig.json +8 -5
  36. package/vite.config.ts +10 -0
  37. package/demos/maptiler-sdk.css +0 -147
  38. package/demos/maptiler-sdk.umd.js +0 -4041
  39. package/demos/mountain.html +0 -67
  40. package/demos/simple.html +0 -67
  41. package/demos/transform-request.html +0 -81
@@ -7,6 +7,27 @@ export { LanguageGeocoding, MapStyle, MapStyleVariant, ReferenceMapStyle, Servic
7
7
  import { v4 } from 'uuid';
8
8
 
9
9
  const Language = {
10
+ /**
11
+ * The visitor language mode concatenates the prefered language from the user settings and the "default name".
12
+ * Note: The "default name" is equivalent to OSM's `{name}`, which can be the most recognized names a global
13
+ * scale or the local name.
14
+ * This mode is helpful in the context where a user needs to access both the local names and the names in their
15
+ * own language, for instance when traveling abroad, where signs likely to be only available in the local language.
16
+ */
17
+ VISITOR: "visitor",
18
+ /**
19
+ * The visitor language mode concatenates English and the "default name".
20
+ * Note: The "default name" is equivalent to OSM's `{name}`, which can be the most recognized names a global
21
+ * scale or the local name.
22
+ * This mode is helpful in the context where a user needs to access both the local names and the names in their
23
+ * own language, for instance when traveling abroad, where signs likely to be only available in the local language.
24
+ */
25
+ VISITOR_ENGLISH: "visitor_en",
26
+ /**
27
+ * Language as the style is designed. Not that this is the default state and one
28
+ * the language has been changed to another than `STYLE`, then it cannot be set back to `STYLE`.
29
+ */
30
+ STYLE: "style",
10
31
  /**
11
32
  * AUTO mode uses the language of the browser
12
33
  */
@@ -20,85 +41,97 @@ const Language = {
20
41
  /**
21
42
  * Default fallback languages that uses latin charaters
22
43
  */
23
- LATIN: "latin",
44
+ LATIN: "name:latin",
24
45
  /**
25
46
  * Default fallback languages that uses non-latin charaters
26
47
  */
27
- NON_LATIN: "nonlatin",
48
+ NON_LATIN: "name:nonlatin",
28
49
  /**
29
50
  * Labels are in their local language, when available
30
51
  */
31
- LOCAL: "",
32
- ALBANIAN: "sq",
33
- AMHARIC: "am",
34
- ARABIC: "ar",
35
- ARMENIAN: "hy",
36
- AZERBAIJANI: "az",
37
- BASQUE: "eu",
38
- BELORUSSIAN: "be",
39
- BOSNIAN: "bs",
40
- BRETON: "br",
41
- BULGARIAN: "bg",
42
- CATALAN: "ca",
43
- CHINESE: "zh",
44
- CORSICAN: "co",
45
- CROATIAN: "hr",
46
- CZECH: "cs",
47
- DANISH: "da",
48
- DUTCH: "nl",
49
- ENGLISH: "en",
50
- ESPERANTO: "eo",
51
- ESTONIAN: "et",
52
- FINNISH: "fi",
53
- FRENCH: "fr",
54
- FRISIAN: "fy",
55
- GEORGIAN: "ka",
56
- GERMAN: "de",
57
- GREEK: "el",
58
- HEBREW: "he",
59
- HINDI: "hi",
60
- HUNGARIAN: "hu",
61
- ICELANDIC: "is",
62
- INDONESIAN: "id",
63
- IRISH: "ga",
64
- ITALIAN: "it",
65
- JAPANESE: "ja",
66
- JAPANESE_HIRAGANA: "ja-Hira",
67
- JAPANESE_KANA: "ja_kana",
68
- JAPANESE_LATIN: "ja_rm",
69
- JAPANESE_2018: "ja-Latn",
70
- KANNADA: "kn",
71
- KAZAKH: "kk",
72
- KOREAN: "ko",
73
- KOREAN_LATIN: "ko-Latn",
74
- KURDISH: "ku",
75
- ROMAN_LATIN: "la",
76
- LATVIAN: "lv",
77
- LITHUANIAN: "lt",
78
- LUXEMBOURGISH: "lb",
79
- MACEDONIAN: "mk",
80
- MALAYALAM: "ml",
81
- MALTESE: "mt",
82
- NORWEGIAN: "no",
83
- OCCITAN: "oc",
84
- POLISH: "pl",
85
- PORTUGUESE: "pt",
86
- ROMANIAN: "ro",
87
- ROMANSH: "rm",
88
- RUSSIAN: "ru",
89
- SCOTTISH_GAELIC: "gd",
90
- SERBIAN_CYRILLIC: "sr",
91
- SERBIAN_LATIN: "sr-Latn",
92
- SLOVAK: "sk",
93
- SLOVENE: "sl",
94
- SPANISH: "es",
95
- SWEDISH: "sv",
96
- TAMIL: "ta",
97
- TELUGU: "te",
98
- THAI: "th",
99
- TURKISH: "tr",
100
- UKRAINIAN: "uk",
101
- WELSH: "cy"
52
+ LOCAL: "name",
53
+ /**
54
+ * International name
55
+ */
56
+ INTERNATIONAL: "name_int",
57
+ ALBANIAN: "name:sq",
58
+ AMHARIC: "name:am",
59
+ ARABIC: "name:ar",
60
+ ARMENIAN: "name:hy",
61
+ AZERBAIJANI: "name:az",
62
+ BASQUE: "name:eu",
63
+ BELORUSSIAN: "name:be",
64
+ BENGALI: "name:bn",
65
+ BOSNIAN: "name:bs",
66
+ BRETON: "name:br",
67
+ BULGARIAN: "name:bg",
68
+ CATALAN: "name:ca",
69
+ CHINESE: "name:zh",
70
+ TRADITIONAL_CHINESE: "name:zh-Hant",
71
+ SIMPLIFIED_CHINESE: "name:zh-Hans",
72
+ CORSICAN: "name:co",
73
+ CROATIAN: "name:hr",
74
+ CZECH: "name:cs",
75
+ DANISH: "name:da",
76
+ DUTCH: "name:nl",
77
+ ENGLISH: "name:en",
78
+ ESPERANTO: "name:eo",
79
+ ESTONIAN: "name:et",
80
+ FINNISH: "name:fi",
81
+ FRENCH: "name:fr",
82
+ FRISIAN: "name:fy",
83
+ GEORGIAN: "name:ka",
84
+ GERMAN: "name:de",
85
+ GREEK: "name:el",
86
+ HEBREW: "name:he",
87
+ HINDI: "name:hi",
88
+ HUNGARIAN: "name:hu",
89
+ ICELANDIC: "name:is",
90
+ INDONESIAN: "name:id",
91
+ IRISH: "name:ga",
92
+ ITALIAN: "name:it",
93
+ JAPANESE: "name:ja",
94
+ JAPANESE_HIRAGANA: "name:ja-Hira",
95
+ JAPANESE_KANA: "name:ja_kana",
96
+ JAPANESE_LATIN: "name:ja_rm",
97
+ JAPANESE_2018: "name:ja-Latn",
98
+ KANNADA: "name:kn",
99
+ KAZAKH: "name:kk",
100
+ KOREAN: "name:ko",
101
+ KOREAN_LATIN: "name:ko-Latn",
102
+ KURDISH: "name:ku",
103
+ ROMAN_LATIN: "name:la",
104
+ LATVIAN: "name:lv",
105
+ LITHUANIAN: "name:lt",
106
+ LUXEMBOURGISH: "name:lb",
107
+ MACEDONIAN: "name:mk",
108
+ MALAYALAM: "name:ml",
109
+ MALTESE: "name:mt",
110
+ NORWEGIAN: "name:no",
111
+ OCCITAN: "name:oc",
112
+ PERSIAN: "name:fa",
113
+ POLISH: "name:pl",
114
+ PORTUGUESE: "name:pt",
115
+ PUNJABI: "name:pa",
116
+ WESTERN_PUNJABI: "name:pnb",
117
+ ROMANIAN: "name:ro",
118
+ ROMANSH: "name:rm",
119
+ RUSSIAN: "name:ru",
120
+ SCOTTISH_GAELIC: "name:gd",
121
+ SERBIAN_CYRILLIC: "name:sr",
122
+ SERBIAN_LATIN: "name:sr-Latn",
123
+ SLOVAK: "name:sk",
124
+ SLOVENE: "name:sl",
125
+ SPANISH: "name:es",
126
+ SWEDISH: "name:sv",
127
+ TAMIL: "name:ta",
128
+ TELUGU: "name:te",
129
+ THAI: "name:th",
130
+ TURKISH: "name:tr",
131
+ UKRAINIAN: "name:uk",
132
+ URDU: "name:ur",
133
+ VIETNAMIAN_LATIN: "name:vi",
134
+ WELSH: "name:cy"
102
135
  };
103
136
  const languagesIsoSet = new Set(Object.values(Language));
104
137
  function isLanguageSupported(lang) {
@@ -107,14 +140,32 @@ function isLanguageSupported(lang) {
107
140
  const languageCodeSet = new Set(Object.values(Language));
108
141
  function getBrowserLanguage() {
109
142
  if (typeof navigator === "undefined") {
110
- return Intl.DateTimeFormat().resolvedOptions().locale.split("-")[0];
143
+ return `name:${Intl.DateTimeFormat().resolvedOptions().locale.split("-")[0]}`;
111
144
  }
112
145
  const canditatelangs = Array.from(
113
- new Set(navigator.languages.map((l) => l.split("-")[0]))
146
+ new Set(navigator.languages.map((l) => `name:${l.split("-")[0]}`))
114
147
  ).filter((l) => languageCodeSet.has(l));
115
- return canditatelangs.length ? canditatelangs[0] : Language.LATIN;
148
+ return canditatelangs.length ? canditatelangs[0] : Language.LOCAL;
116
149
  }
117
150
 
151
+ const defaults = {
152
+ maptilerLogoURL: "https://api.maptiler.com/resources/logo.svg",
153
+ maptilerURL: "https://www.maptiler.com/",
154
+ maptilerApiHost: "api.maptiler.com",
155
+ rtlPluginURL: "https://cdn.maptiler.com/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.min.js",
156
+ primaryLanguage: Language.STYLE,
157
+ secondaryLanguage: Language.LOCAL,
158
+ terrainSourceURL: "https://api.maptiler.com/tiles/terrain-rgb-v2/tiles.json",
159
+ terrainSourceId: "maptiler-terrain"
160
+ };
161
+ Object.freeze(defaults);
162
+
163
+ var __defProp$b = Object.defineProperty;
164
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
165
+ var __publicField$8 = (obj, key, value) => {
166
+ __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
167
+ return value;
168
+ };
118
169
  const MAPTILER_SESSION_ID = v4();
119
170
  class SdkConfig extends EventEmitter {
120
171
  constructor() {
@@ -122,12 +173,12 @@ class SdkConfig extends EventEmitter {
122
173
  /**
123
174
  * The primary language. By default, the language of the web browser is used.
124
175
  */
125
- this.primaryLanguage = Language.AUTO;
176
+ __publicField$8(this, "primaryLanguage", defaults.primaryLanguage);
126
177
  /**
127
178
  * The secondary language, to overwrite the default language defined in the map style.
128
179
  * This settings is highly dependant on the style compatibility and may not work in most cases.
129
180
  */
130
- this.secondaryLanguage = null;
181
+ __publicField$8(this, "secondaryLanguage");
131
182
  /**
132
183
  * Setting on whether of not the SDK runs with a session logic.
133
184
  * A "session" is started at the initialization of the SDK and finished when the browser
@@ -135,15 +186,15 @@ class SdkConfig extends EventEmitter {
135
186
  * When `session` is enabled (default: true), the extra URL param `mtsid` is added to queries
136
187
  * on the MapTiler Cloud API. This allows MapTiler to enable "session based billing".
137
188
  */
138
- this.session = true;
189
+ __publicField$8(this, "session", true);
139
190
  /**
140
191
  * Unit to be used
141
192
  */
142
- this._unit = "metric";
193
+ __publicField$8(this, "_unit", "metric");
143
194
  /**
144
195
  * MapTiler Cloud API key
145
196
  */
146
- this._apiKey = "";
197
+ __publicField$8(this, "_apiKey", "");
147
198
  }
148
199
  /**
149
200
  * Set the unit system
@@ -187,36 +238,31 @@ class SdkConfig extends EventEmitter {
187
238
  }
188
239
  const config = new SdkConfig();
189
240
 
190
- const defaults = {
191
- maptilerLogoURL: "https://api.maptiler.com/resources/logo.svg",
192
- maptilerURL: "https://www.maptiler.com/",
193
- maptilerApiHost: "api.maptiler.com",
194
- rtlPluginURL: "https://cdn.maptiler.com/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.min.js",
195
- primaryLanguage: Language.AUTO,
196
- secondaryLanguage: Language.LOCAL,
197
- terrainSourceURL: "https://api.maptiler.com/tiles/terrain-rgb-v2/tiles.json",
198
- terrainSourceId: "maptiler-terrain"
199
- };
200
- Object.freeze(defaults);
201
-
202
241
  class LogoControl extends maplibregl__default.LogoControl {
203
242
  onAdd(map) {
204
243
  return super.onAdd(map);
205
244
  }
206
245
  }
207
246
 
247
+ var __defProp$a = Object.defineProperty;
248
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
249
+ var __publicField$7 = (obj, key, value) => {
250
+ __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
251
+ return value;
252
+ };
208
253
  class MaptilerLogoControl extends LogoControl {
209
254
  constructor(options = {}) {
210
255
  var _a, _b;
211
256
  super(options);
212
- this.logoURL = "";
213
- this.linkURL = "";
257
+ __publicField$7(this, "logoURL", "");
258
+ __publicField$7(this, "linkURL", "");
214
259
  this.logoURL = (_a = options.logoURL) != null ? _a : defaults.maptilerLogoURL;
215
260
  this.linkURL = (_b = options.linkURL) != null ? _b : defaults.maptilerURL;
216
261
  }
217
262
  onAdd(map) {
263
+ var _a;
218
264
  this._map = map;
219
- this._compact = this.options && this.options.compact;
265
+ this._compact = (_a = this.options.compact) != null ? _a : false;
220
266
  this._container = window.document.createElement("div");
221
267
  this._container.className = "maplibregl-ctrl";
222
268
  const anchor = window.document.createElement("a");
@@ -244,19 +290,19 @@ class MaptilerLogoControl extends LogoControl {
244
290
  }
245
291
  }
246
292
 
247
- var __defProp$2 = Object.defineProperty;
248
- var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
249
- var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
250
- var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
251
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
252
- var __spreadValues$2 = (a, b) => {
293
+ var __defProp$9 = Object.defineProperty;
294
+ var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
295
+ var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
296
+ var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
297
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
298
+ var __spreadValues$5 = (a, b) => {
253
299
  for (var prop in b || (b = {}))
254
- if (__hasOwnProp$2.call(b, prop))
255
- __defNormalProp$2(a, prop, b[prop]);
256
- if (__getOwnPropSymbols$2)
257
- for (var prop of __getOwnPropSymbols$2(b)) {
258
- if (__propIsEnum$2.call(b, prop))
259
- __defNormalProp$2(a, prop, b[prop]);
300
+ if (__hasOwnProp$5.call(b, prop))
301
+ __defNormalProp$9(a, prop, b[prop]);
302
+ if (__getOwnPropSymbols$5)
303
+ for (var prop of __getOwnPropSymbols$5(b)) {
304
+ if (__propIsEnum$5.call(b, prop))
305
+ __defNormalProp$9(a, prop, b[prop]);
260
306
  }
261
307
  return a;
262
308
  };
@@ -264,7 +310,10 @@ function enableRTL() {
264
310
  if (maplibregl__default.getRTLTextPluginStatus() === "unavailable") {
265
311
  maplibregl__default.setRTLTextPlugin(
266
312
  defaults.rtlPluginURL,
267
- null,
313
+ (err) => {
314
+ if (err)
315
+ console.error(err);
316
+ },
268
317
  true
269
318
  // Lazy load the plugin
270
319
  );
@@ -272,9 +321,8 @@ function enableRTL() {
272
321
  }
273
322
  function bindAll(fns, context) {
274
323
  fns.forEach((fn) => {
275
- if (!context[fn]) {
324
+ if (typeof context[fn] !== "function")
276
325
  return;
277
- }
278
326
  context[fn] = context[fn].bind(context);
279
327
  });
280
328
  }
@@ -291,7 +339,7 @@ function DOMremove(node) {
291
339
  node.parentNode.removeChild(node);
292
340
  }
293
341
  }
294
- function maptilerCloudTransformRequest(url, resourceType) {
342
+ function maptilerCloudTransformRequest(url, _resourceType) {
295
343
  let reqUrl = null;
296
344
  try {
297
345
  reqUrl = new URL(url);
@@ -312,17 +360,32 @@ function maptilerCloudTransformRequest(url, resourceType) {
312
360
  url: reqUrl.href
313
361
  };
314
362
  }
315
- function combineTransformRequest(userDefinedRTF = null) {
363
+ function combineTransformRequest(userDefinedRTF) {
316
364
  return function(url, resourceType) {
317
- if (userDefinedRTF) {
365
+ var _a;
366
+ if (userDefinedRTF !== void 0) {
318
367
  const rp = userDefinedRTF(url, resourceType);
319
- const rp2 = maptilerCloudTransformRequest(rp.url);
320
- return __spreadValues$2(__spreadValues$2({}, rp), rp2);
368
+ const rp2 = maptilerCloudTransformRequest((_a = rp == null ? void 0 : rp.url) != null ? _a : "");
369
+ return __spreadValues$5(__spreadValues$5({}, rp), rp2);
321
370
  } else {
322
371
  return maptilerCloudTransformRequest(url);
323
372
  }
324
373
  };
325
374
  }
375
+ function generateRandomString() {
376
+ return Math.random().toString(36).substring(2);
377
+ }
378
+ function isUUID(s) {
379
+ const regexExp = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gi;
380
+ return regexExp.test(s);
381
+ }
382
+ function jsonParseNoThrow(doc) {
383
+ try {
384
+ return JSON.parse(doc);
385
+ } catch (e) {
386
+ }
387
+ return null;
388
+ }
326
389
 
327
390
  function styleToStyle(style) {
328
391
  if (!style) {
@@ -344,8 +407,17 @@ function styleToStyle(style) {
344
407
  return style;
345
408
  }
346
409
 
410
+ var __defProp$8 = Object.defineProperty;
411
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
412
+ var __publicField$6 = (obj, key, value) => {
413
+ __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
414
+ return value;
415
+ };
347
416
  class MaptilerTerrainControl {
348
417
  constructor() {
418
+ __publicField$6(this, "_map");
419
+ __publicField$6(this, "_container");
420
+ __publicField$6(this, "_terrainButton");
349
421
  bindAll(["_toggleTerrain", "_updateTerrainIcon"], this);
350
422
  }
351
423
  onAdd(map) {
@@ -402,6 +474,12 @@ class NavigationControl extends maplibregl__default.NavigationControl {
402
474
  }
403
475
  }
404
476
 
477
+ var __defProp$7 = Object.defineProperty;
478
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
479
+ var __publicField$5 = (obj, key, value) => {
480
+ __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
481
+ return value;
482
+ };
405
483
  class MaptilerNavigationControl extends NavigationControl {
406
484
  constructor() {
407
485
  super({
@@ -409,6 +487,19 @@ class MaptilerNavigationControl extends NavigationControl {
409
487
  showZoom: true,
410
488
  visualizePitch: true
411
489
  });
490
+ /**
491
+ * Overloading: Limit how flat the compass icon can get
492
+ */
493
+ __publicField$5(this, "_rotateCompassArrow", () => {
494
+ const rotate = this.options.visualizePitch ? `scale(${Math.min(
495
+ 1.5,
496
+ 1 / Math.pow(
497
+ Math.cos(this._map.transform.pitch * (Math.PI / 180)),
498
+ 0.5
499
+ )
500
+ )}) rotateX(${Math.min(70, this._map.transform.pitch)}deg) rotateZ(${this._map.transform.angle * (180 / Math.PI)}deg)` : `rotate(${this._map.transform.angle * (180 / Math.PI)}deg)`;
501
+ this._compassIcon.style.transform = rotate;
502
+ });
412
503
  this._compass.removeEventListener(
413
504
  "click",
414
505
  this._compass.clickFunction
@@ -436,16 +527,6 @@ class MaptilerNavigationControl extends NavigationControl {
436
527
  button.clickFunction = fn;
437
528
  return button;
438
529
  }
439
- /**
440
- * Overloading: Limit how flat the compass icon can get
441
- */
442
- _rotateCompassArrow() {
443
- const rotate = this.options.visualizePitch ? `scale(${Math.min(
444
- 1.5,
445
- 1 / Math.pow(Math.cos(this._map.transform.pitch * (Math.PI / 180)), 0.5)
446
- )}) rotateX(${Math.min(70, this._map.transform.pitch)}deg) rotateZ(${this._map.transform.angle * (180 / Math.PI)}deg)` : `rotate(${this._map.transform.angle * (180 / Math.PI)}deg)`;
447
- this._compassIcon.style.transform = rotate;
448
- }
449
530
  }
450
531
 
451
532
  class GeolocateControl extends maplibregl__default.GeolocateControl {
@@ -454,150 +535,160 @@ class GeolocateControl extends maplibregl__default.GeolocateControl {
454
535
  }
455
536
  }
456
537
 
457
- var __defProp$1 = Object.defineProperty;
458
- var __defProps$1 = Object.defineProperties;
459
- var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
460
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
461
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
462
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
463
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
464
- var __spreadValues$1 = (a, b) => {
538
+ var __defProp$6 = Object.defineProperty;
539
+ var __defProps$3 = Object.defineProperties;
540
+ var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
541
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
542
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
543
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
544
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
545
+ var __spreadValues$4 = (a, b) => {
465
546
  for (var prop in b || (b = {}))
466
- if (__hasOwnProp$1.call(b, prop))
467
- __defNormalProp$1(a, prop, b[prop]);
468
- if (__getOwnPropSymbols$1)
469
- for (var prop of __getOwnPropSymbols$1(b)) {
470
- if (__propIsEnum$1.call(b, prop))
471
- __defNormalProp$1(a, prop, b[prop]);
547
+ if (__hasOwnProp$4.call(b, prop))
548
+ __defNormalProp$6(a, prop, b[prop]);
549
+ if (__getOwnPropSymbols$4)
550
+ for (var prop of __getOwnPropSymbols$4(b)) {
551
+ if (__propIsEnum$4.call(b, prop))
552
+ __defNormalProp$6(a, prop, b[prop]);
472
553
  }
473
554
  return a;
474
555
  };
475
- var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
556
+ var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
557
+ var __publicField$4 = (obj, key, value) => {
558
+ __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
559
+ return value;
560
+ };
476
561
  const Marker$1 = maplibregl__default.Marker;
477
562
  const LngLat$1 = maplibregl__default.LngLat;
478
563
  const LngLatBounds$1 = maplibregl__default.LngLatBounds;
479
564
  class MaptilerGeolocateControl extends GeolocateControl {
480
565
  constructor() {
481
566
  super(...arguments);
482
- this.lastUpdatedCenter = new LngLat$1(0, 0);
483
- }
484
- /**
485
- * Update the camera location to center on the current position
486
- *
487
- * @param {Position} position the Geolocation API Position
488
- * @private
489
- */
490
- _updateCamera(position) {
491
- const center = new LngLat$1(
492
- position.coords.longitude,
493
- position.coords.latitude
494
- );
495
- const radius = position.coords.accuracy;
496
- const bearing = this._map.getBearing();
497
- const options = __spreadProps$1(__spreadValues$1({
498
- bearing
499
- }, this.options.fitBoundsOptions), {
500
- linear: true
501
- });
502
- const currentMapZoom = this._map.getZoom();
503
- if (currentMapZoom > this.options.fitBoundsOptions.maxZoom) {
504
- options.zoom = currentMapZoom;
505
- }
506
- this._map.fitBounds(LngLatBounds$1.fromLngLat(center, radius), options, {
507
- geolocateSource: true
508
- // tag this camera change so it won't cause the control to change to background state
509
- });
510
- let hasFittingBeenDisrupted = false;
511
- const flagFittingDisruption = () => {
512
- hasFittingBeenDisrupted = true;
513
- };
514
- this._map.once("click", flagFittingDisruption);
515
- this._map.once("dblclick", flagFittingDisruption);
516
- this._map.once("dragstart", flagFittingDisruption);
517
- this._map.once("mousedown", flagFittingDisruption);
518
- this._map.once("touchstart", flagFittingDisruption);
519
- this._map.once("wheel", flagFittingDisruption);
520
- this._map.once("moveend", () => {
521
- this._map.off("click", flagFittingDisruption);
522
- this._map.off("dblclick", flagFittingDisruption);
523
- this._map.off("dragstart", flagFittingDisruption);
524
- this._map.off("mousedown", flagFittingDisruption);
525
- this._map.off("touchstart", flagFittingDisruption);
526
- this._map.off("wheel", flagFittingDisruption);
527
- if (hasFittingBeenDisrupted) {
528
- return;
567
+ __publicField$4(this, "lastUpdatedCenter", new LngLat$1(0, 0));
568
+ /**
569
+ * Update the camera location to center on the current position
570
+ *
571
+ * @param {Position} position the Geolocation API Position
572
+ * @private
573
+ */
574
+ __publicField$4(this, "_updateCamera", (position) => {
575
+ var _a, _b, _c;
576
+ const center = new LngLat$1(
577
+ position.coords.longitude,
578
+ position.coords.latitude
579
+ );
580
+ const radius = position.coords.accuracy;
581
+ const bearing = this._map.getBearing();
582
+ const options = __spreadProps$3(__spreadValues$4({
583
+ bearing
584
+ }, this.options.fitBoundsOptions), {
585
+ linear: true
586
+ });
587
+ const currentMapZoom = this._map.getZoom();
588
+ if (currentMapZoom > ((_c = (_b = (_a = this.options) == null ? void 0 : _a.fitBoundsOptions) == null ? void 0 : _b.maxZoom) != null ? _c : 30)) {
589
+ options.zoom = currentMapZoom;
529
590
  }
530
- this.lastUpdatedCenter = this._map.getCenter();
591
+ this._map.fitBounds(LngLatBounds$1.fromLngLat(center, radius), options, {
592
+ geolocateSource: true
593
+ // tag this camera change so it won't cause the control to change to background state
594
+ });
595
+ let hasFittingBeenDisrupted = false;
596
+ const flagFittingDisruption = () => {
597
+ hasFittingBeenDisrupted = true;
598
+ };
599
+ this._map.once("click", flagFittingDisruption);
600
+ this._map.once("dblclick", flagFittingDisruption);
601
+ this._map.once("dragstart", flagFittingDisruption);
602
+ this._map.once("mousedown", flagFittingDisruption);
603
+ this._map.once("touchstart", flagFittingDisruption);
604
+ this._map.once("wheel", flagFittingDisruption);
605
+ this._map.once("moveend", () => {
606
+ this._map.off("click", flagFittingDisruption);
607
+ this._map.off("dblclick", flagFittingDisruption);
608
+ this._map.off("dragstart", flagFittingDisruption);
609
+ this._map.off("mousedown", flagFittingDisruption);
610
+ this._map.off("touchstart", flagFittingDisruption);
611
+ this._map.off("wheel", flagFittingDisruption);
612
+ if (hasFittingBeenDisrupted) {
613
+ return;
614
+ }
615
+ this.lastUpdatedCenter = this._map.getCenter();
616
+ });
531
617
  });
532
- }
533
- _setupUI(supported) {
534
- this.lastUpdatedCenter = this._map.getCenter();
535
- this._container.addEventListener(
536
- "contextmenu",
537
- (e) => e.preventDefault()
538
- );
539
- this._geolocateButton = DOMcreate(
540
- "button",
541
- "maplibregl-ctrl-geolocate",
542
- this._container
543
- );
544
- DOMcreate(
545
- "span",
546
- "maplibregl-ctrl-icon",
547
- this._geolocateButton
548
- ).setAttribute("aria-hidden", "true");
549
- this._geolocateButton.type = "button";
550
- if (supported === false) {
551
- const title = this._map._getUIString(
552
- "GeolocateControl.LocationNotAvailable"
618
+ __publicField$4(this, "_setupUI", (supported) => {
619
+ this.lastUpdatedCenter = this._map.getCenter();
620
+ this._container.addEventListener(
621
+ "contextmenu",
622
+ (e) => e.preventDefault()
553
623
  );
554
- this._geolocateButton.disabled = true;
555
- this._geolocateButton.title = title;
556
- this._geolocateButton.setAttribute("aria-label", title);
557
- } else {
558
- const title = this._map._getUIString("GeolocateControl.FindMyLocation");
559
- this._geolocateButton.title = title;
560
- this._geolocateButton.setAttribute("aria-label", title);
561
- }
562
- if (this.options.trackUserLocation) {
563
- this._geolocateButton.setAttribute("aria-pressed", "false");
564
- this._watchState = "OFF";
565
- }
566
- if (this.options.showUserLocation) {
567
- this._dotElement = DOMcreate("div", "maplibregl-user-location-dot");
568
- this._userLocationDotMarker = new Marker$1(this._dotElement);
569
- this._circleElement = DOMcreate(
570
- "div",
571
- "maplibregl-user-location-accuracy-circle"
624
+ this._geolocateButton = DOMcreate(
625
+ "button",
626
+ "maplibregl-ctrl-geolocate",
627
+ this._container
572
628
  );
573
- this._accuracyCircleMarker = new Marker$1({
574
- element: this._circleElement,
575
- pitchAlignment: "map"
576
- });
577
- if (this.options.trackUserLocation)
629
+ DOMcreate(
630
+ "span",
631
+ "maplibregl-ctrl-icon",
632
+ this._geolocateButton
633
+ ).setAttribute("aria-hidden", "true");
634
+ this._geolocateButton.type = "button";
635
+ if (supported === false) {
636
+ const title = this._map._getUIString(
637
+ "GeolocateControl.LocationNotAvailable"
638
+ );
639
+ this._geolocateButton.disabled = true;
640
+ this._geolocateButton.title = title;
641
+ this._geolocateButton.setAttribute("aria-label", title);
642
+ } else {
643
+ const title = this._map._getUIString("GeolocateControl.FindMyLocation");
644
+ this._geolocateButton.title = title;
645
+ this._geolocateButton.setAttribute("aria-label", title);
646
+ }
647
+ if (this.options.trackUserLocation) {
648
+ this._geolocateButton.setAttribute("aria-pressed", "false");
578
649
  this._watchState = "OFF";
579
- this._map.on("move", this._onZoom);
580
- }
581
- this._geolocateButton.addEventListener("click", this.trigger.bind(this));
582
- this._setup = true;
583
- if (this.options.trackUserLocation) {
584
- this._map.on("moveend", (event) => {
585
- const fromResize = event.originalEvent && event.originalEvent.type === "resize";
586
- const movingDistance = this.lastUpdatedCenter.distanceTo(
587
- this._map.getCenter()
650
+ }
651
+ if (this.options.showUserLocation) {
652
+ this._dotElement = DOMcreate("div", "maplibregl-user-location-dot");
653
+ this._userLocationDotMarker = new Marker$1({ element: this._dotElement });
654
+ this._circleElement = DOMcreate(
655
+ "div",
656
+ "maplibregl-user-location-accuracy-circle"
588
657
  );
589
- if (!event.geolocateSource && this._watchState === "ACTIVE_LOCK" && !fromResize && movingDistance > 1) {
590
- this._watchState = "BACKGROUND";
591
- this._geolocateButton.classList.add(
592
- "maplibregl-ctrl-geolocate-background"
593
- );
594
- this._geolocateButton.classList.remove(
595
- "maplibregl-ctrl-geolocate-active"
658
+ this._accuracyCircleMarker = new Marker$1({
659
+ element: this._circleElement,
660
+ pitchAlignment: "map"
661
+ });
662
+ if (this.options.trackUserLocation)
663
+ this._watchState = "OFF";
664
+ this._map.on("move", this._onZoom);
665
+ }
666
+ this._geolocateButton.addEventListener("click", this.trigger.bind(this));
667
+ this._setup = true;
668
+ if (this.options.trackUserLocation) {
669
+ this._map.on("moveend", (event) => {
670
+ const fromResize = event.originalEvent && event.originalEvent.type === "resize";
671
+ const movingDistance = this.lastUpdatedCenter.distanceTo(
672
+ this._map.getCenter()
596
673
  );
597
- this.fire(new Event("trackuserlocationend"));
598
- }
599
- });
600
- }
674
+ if (!event.geolocateSource && this._watchState === "ACTIVE_LOCK" && !fromResize && movingDistance > 1) {
675
+ this._watchState = "BACKGROUND";
676
+ this._geolocateButton.classList.add(
677
+ "maplibregl-ctrl-geolocate-background"
678
+ );
679
+ this._geolocateButton.classList.remove(
680
+ "maplibregl-ctrl-geolocate-active"
681
+ );
682
+ this.fire(new Event("trackuserlocationend"));
683
+ }
684
+ });
685
+ }
686
+ });
687
+ __publicField$4(this, "_onZoom", () => {
688
+ if (this.options.showUserLocation && this.options.showAccuracyCircle) {
689
+ this._updateCircleRadius();
690
+ }
691
+ });
601
692
  }
602
693
  _updateCircleRadius() {
603
694
  if (this._watchState !== "BACKGROUND" && this._watchState !== "ACTIVE_LOCK") {
@@ -618,11 +709,6 @@ class MaptilerGeolocateControl extends GeolocateControl {
618
709
  this._circleElement.style.width = `${circleDiameter}px`;
619
710
  this._circleElement.style.height = `${circleDiameter}px`;
620
711
  }
621
- _onZoom() {
622
- if (this.options.showUserLocation && this.options.showAccuracyCircle) {
623
- this._updateCircleRadius();
624
- }
625
- }
626
712
  }
627
713
 
628
714
  class AttributionControl extends maplibregl__default.AttributionControl {
@@ -643,26 +729,314 @@ class FullscreenControl extends maplibregl__default.FullscreenControl {
643
729
  }
644
730
  }
645
731
 
646
- var __defProp = Object.defineProperty;
647
- var __defProps = Object.defineProperties;
648
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
649
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
650
- var __hasOwnProp = Object.prototype.hasOwnProperty;
651
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
652
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
653
- var __spreadValues = (a, b) => {
732
+ var __defProp$5 = Object.defineProperty;
733
+ var __defProps$2 = Object.defineProperties;
734
+ var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
735
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
736
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
737
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
738
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
739
+ var __spreadValues$3 = (a, b) => {
654
740
  for (var prop in b || (b = {}))
655
- if (__hasOwnProp.call(b, prop))
656
- __defNormalProp(a, prop, b[prop]);
657
- if (__getOwnPropSymbols)
658
- for (var prop of __getOwnPropSymbols(b)) {
659
- if (__propIsEnum.call(b, prop))
660
- __defNormalProp(a, prop, b[prop]);
741
+ if (__hasOwnProp$3.call(b, prop))
742
+ __defNormalProp$5(a, prop, b[prop]);
743
+ if (__getOwnPropSymbols$3)
744
+ for (var prop of __getOwnPropSymbols$3(b)) {
745
+ if (__propIsEnum$3.call(b, prop))
746
+ __defNormalProp$5(a, prop, b[prop]);
661
747
  }
662
748
  return a;
663
749
  };
664
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
665
- var __async = (__this, __arguments, generator) => {
750
+ var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
751
+ var __publicField$3 = (obj, key, value) => {
752
+ __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
753
+ return value;
754
+ };
755
+ var __accessCheck = (obj, member, msg) => {
756
+ if (!member.has(obj))
757
+ throw TypeError("Cannot " + msg);
758
+ };
759
+ var __privateGet = (obj, member, getter) => {
760
+ __accessCheck(obj, member, "read from private field");
761
+ return getter ? getter.call(obj) : member.get(obj);
762
+ };
763
+ var __privateAdd = (obj, member, value) => {
764
+ if (member.has(obj))
765
+ throw TypeError("Cannot add the same private member more than once");
766
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
767
+ };
768
+ var __privateSet = (obj, member, value, setter) => {
769
+ __accessCheck(obj, member, "write to private field");
770
+ setter ? setter.call(obj, value) : member.set(obj, value);
771
+ return value;
772
+ };
773
+ var __privateMethod = (obj, member, method) => {
774
+ __accessCheck(obj, member, "access private method");
775
+ return method;
776
+ };
777
+ var _options, _parentMap, _container, _canvasContainer, _parentRect, _differentStyle, _desync, _addParentRect, addParentRect_fn, _setParentBounds, setParentBounds_fn, _syncMaps, syncMaps_fn;
778
+ class Minimap {
779
+ constructor(options, mapOptions) {
780
+ __privateAdd(this, _addParentRect);
781
+ __privateAdd(this, _setParentBounds);
782
+ __privateAdd(this, _syncMaps);
783
+ __privateAdd(this, _options, void 0);
784
+ __publicField$3(this, "map");
785
+ __privateAdd(this, _parentMap, void 0);
786
+ __privateAdd(this, _container, void 0);
787
+ __privateAdd(this, _canvasContainer, void 0);
788
+ __privateAdd(this, _parentRect, void 0);
789
+ __privateAdd(this, _differentStyle, false);
790
+ __privateAdd(this, _desync, void 0);
791
+ var _a;
792
+ if (options.style !== void 0)
793
+ __privateSet(this, _differentStyle, true);
794
+ __privateSet(this, _options, __spreadProps$2(__spreadValues$3(__spreadProps$2(__spreadValues$3({
795
+ // set defaults
796
+ zoomAdjust: -4,
797
+ position: "top-right"
798
+ }, mapOptions), {
799
+ // override any lingering control options
800
+ forceNoAttributionControl: true,
801
+ attributionControl: false,
802
+ navigationControl: false,
803
+ geolocateControl: false,
804
+ maptilerLogo: false,
805
+ minimap: false,
806
+ hash: false,
807
+ pitchAdjust: false
808
+ }), options), {
809
+ containerStyle: __spreadValues$3({
810
+ border: "1px solid #000",
811
+ width: "400px",
812
+ height: "300px"
813
+ }, (_a = options.containerStyle) != null ? _a : {})
814
+ }));
815
+ if (options.lockZoom !== void 0) {
816
+ __privateGet(this, _options).minZoom = options.lockZoom;
817
+ __privateGet(this, _options).maxZoom = options.lockZoom;
818
+ }
819
+ }
820
+ setStyle(style, options) {
821
+ if (!__privateGet(this, _differentStyle))
822
+ this.map.setStyle(style, options);
823
+ __privateMethod(this, _setParentBounds, setParentBounds_fn).call(this);
824
+ }
825
+ addLayer(layer, beforeId) {
826
+ if (!__privateGet(this, _differentStyle))
827
+ this.map.addLayer(layer, beforeId);
828
+ __privateMethod(this, _setParentBounds, setParentBounds_fn).call(this);
829
+ return this.map;
830
+ }
831
+ moveLayer(id, beforeId) {
832
+ if (!__privateGet(this, _differentStyle))
833
+ this.map.moveLayer(id, beforeId);
834
+ __privateMethod(this, _setParentBounds, setParentBounds_fn).call(this);
835
+ return this.map;
836
+ }
837
+ removeLayer(id) {
838
+ if (!__privateGet(this, _differentStyle))
839
+ this.map.removeLayer(id);
840
+ __privateMethod(this, _setParentBounds, setParentBounds_fn).call(this);
841
+ return this;
842
+ }
843
+ setLayerZoomRange(layerId, minzoom, maxzoom) {
844
+ if (!__privateGet(this, _differentStyle))
845
+ this.map.setLayerZoomRange(layerId, minzoom, maxzoom);
846
+ __privateMethod(this, _setParentBounds, setParentBounds_fn).call(this);
847
+ return this;
848
+ }
849
+ setFilter(layerId, filter, options) {
850
+ if (!__privateGet(this, _differentStyle))
851
+ this.map.setFilter(layerId, filter, options);
852
+ __privateMethod(this, _setParentBounds, setParentBounds_fn).call(this);
853
+ return this;
854
+ }
855
+ setPaintProperty(layerId, name, value, options) {
856
+ if (!__privateGet(this, _differentStyle))
857
+ this.map.setPaintProperty(layerId, name, value, options);
858
+ __privateMethod(this, _setParentBounds, setParentBounds_fn).call(this);
859
+ return this;
860
+ }
861
+ setLayoutProperty(layerId, name, value, options) {
862
+ if (!__privateGet(this, _differentStyle))
863
+ this.map.setLayoutProperty(layerId, name, value, options);
864
+ __privateMethod(this, _setParentBounds, setParentBounds_fn).call(this);
865
+ return this;
866
+ }
867
+ setGlyphs(glyphsUrl, options) {
868
+ if (!__privateGet(this, _differentStyle))
869
+ this.map.setGlyphs(glyphsUrl, options);
870
+ __privateMethod(this, _setParentBounds, setParentBounds_fn).call(this);
871
+ return this;
872
+ }
873
+ onAdd(parentMap) {
874
+ __privateSet(this, _parentMap, parentMap);
875
+ __privateSet(this, _container, DOMcreate("div", "maplibregl-ctrl maplibregl-ctrl-group"));
876
+ for (const [key, value] of Object.entries(__privateGet(this, _options).containerStyle)) {
877
+ __privateGet(this, _container).style.setProperty(key, value);
878
+ }
879
+ __privateGet(this, _options).container = __privateGet(this, _container);
880
+ __privateGet(this, _options).zoom = parentMap.getZoom() + __privateGet(this, _options).zoomAdjust;
881
+ this.map = new Map(__privateGet(this, _options));
882
+ this.map.once("style.load", () => {
883
+ this.map.resize();
884
+ });
885
+ this.map.once("load", () => {
886
+ __privateMethod(this, _addParentRect, addParentRect_fn).call(this, __privateGet(this, _options).parentRect);
887
+ __privateSet(this, _desync, __privateMethod(this, _syncMaps, syncMaps_fn).call(this));
888
+ });
889
+ return __privateGet(this, _container);
890
+ }
891
+ onRemove() {
892
+ var _a;
893
+ (_a = __privateGet(this, _desync)) == null ? void 0 : _a.call(this);
894
+ DOMremove(__privateGet(this, _container));
895
+ }
896
+ }
897
+ _options = new WeakMap();
898
+ _parentMap = new WeakMap();
899
+ _container = new WeakMap();
900
+ _canvasContainer = new WeakMap();
901
+ _parentRect = new WeakMap();
902
+ _differentStyle = new WeakMap();
903
+ _desync = new WeakMap();
904
+ _addParentRect = new WeakSet();
905
+ addParentRect_fn = function(rect) {
906
+ if (rect === void 0 || rect.linePaint === void 0 && rect.fillPaint === void 0) {
907
+ return;
908
+ }
909
+ __privateSet(this, _parentRect, {
910
+ type: "Feature",
911
+ properties: {
912
+ name: "parentRect"
913
+ },
914
+ geometry: {
915
+ type: "Polygon",
916
+ coordinates: [[[], [], [], [], []]]
917
+ }
918
+ });
919
+ this.map.addSource("parentRect", {
920
+ type: "geojson",
921
+ data: __privateGet(this, _parentRect)
922
+ });
923
+ if (rect.lineLayout !== void 0 || rect.linePaint !== void 0) {
924
+ this.map.addLayer({
925
+ id: "parentRectOutline",
926
+ type: "line",
927
+ source: "parentRect",
928
+ layout: __spreadValues$3({}, rect.lineLayout),
929
+ paint: __spreadValues$3({
930
+ "line-color": "#FFF",
931
+ "line-width": 1,
932
+ "line-opacity": 0.85
933
+ }, rect.linePaint)
934
+ });
935
+ }
936
+ if (rect.fillPaint !== void 0) {
937
+ this.map.addLayer({
938
+ id: "parentRectFill",
939
+ type: "fill",
940
+ source: "parentRect",
941
+ layout: {},
942
+ paint: __spreadValues$3({
943
+ "fill-color": "#08F",
944
+ "fill-opacity": 0.135
945
+ }, rect.fillPaint)
946
+ });
947
+ }
948
+ __privateMethod(this, _setParentBounds, setParentBounds_fn).call(this);
949
+ };
950
+ _setParentBounds = new WeakSet();
951
+ setParentBounds_fn = function() {
952
+ if (__privateGet(this, _parentRect) === void 0)
953
+ return;
954
+ const { devicePixelRatio } = window;
955
+ const canvas = __privateGet(this, _parentMap).getCanvas();
956
+ const width = canvas.width / devicePixelRatio;
957
+ const height = canvas.height / devicePixelRatio;
958
+ const unproject = __privateGet(this, _parentMap).unproject.bind(__privateGet(this, _parentMap));
959
+ const northWest = unproject([0, 0]);
960
+ const northEast = unproject([width, 0]);
961
+ const southWest = unproject([0, height]);
962
+ const southEast = unproject([width, height]);
963
+ __privateGet(this, _parentRect).geometry.coordinates = [
964
+ [
965
+ southWest.toArray(),
966
+ southEast.toArray(),
967
+ northEast.toArray(),
968
+ northWest.toArray(),
969
+ southWest.toArray()
970
+ ]
971
+ ];
972
+ const source = this.map.getSource("parentRect");
973
+ source.setData(__privateGet(this, _parentRect));
974
+ };
975
+ _syncMaps = new WeakSet();
976
+ syncMaps_fn = function() {
977
+ const { pitchAdjust } = __privateGet(this, _options);
978
+ const parentCallback = () => {
979
+ sync("parent");
980
+ };
981
+ const minimapCallback = () => {
982
+ sync("minimap");
983
+ };
984
+ const on = () => {
985
+ __privateGet(this, _parentMap).on("move", parentCallback);
986
+ this.map.on("move", minimapCallback);
987
+ };
988
+ const off = () => {
989
+ __privateGet(this, _parentMap).off("move", parentCallback);
990
+ this.map.off("move", minimapCallback);
991
+ };
992
+ const sync = (which) => {
993
+ var _a;
994
+ off();
995
+ const from = which === "parent" ? __privateGet(this, _parentMap) : this.map;
996
+ const to = which === "parent" ? this.map : __privateGet(this, _parentMap);
997
+ const center = from.getCenter();
998
+ const zoom = from.getZoom() + ((_a = __privateGet(this, _options).zoomAdjust) != null ? _a : -4) * (which === "parent" ? 1 : -1);
999
+ const bearing = from.getBearing();
1000
+ const pitch = from.getPitch();
1001
+ to.jumpTo({
1002
+ center,
1003
+ zoom,
1004
+ bearing,
1005
+ pitch: pitchAdjust ? pitch : 0
1006
+ });
1007
+ __privateMethod(this, _setParentBounds, setParentBounds_fn).call(this);
1008
+ on();
1009
+ };
1010
+ on();
1011
+ return () => {
1012
+ off();
1013
+ };
1014
+ };
1015
+
1016
+ var __defProp$4 = Object.defineProperty;
1017
+ var __defProps$1 = Object.defineProperties;
1018
+ var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
1019
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
1020
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
1021
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
1022
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1023
+ var __spreadValues$2 = (a, b) => {
1024
+ for (var prop in b || (b = {}))
1025
+ if (__hasOwnProp$2.call(b, prop))
1026
+ __defNormalProp$4(a, prop, b[prop]);
1027
+ if (__getOwnPropSymbols$2)
1028
+ for (var prop of __getOwnPropSymbols$2(b)) {
1029
+ if (__propIsEnum$2.call(b, prop))
1030
+ __defNormalProp$4(a, prop, b[prop]);
1031
+ }
1032
+ return a;
1033
+ };
1034
+ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
1035
+ var __publicField$2 = (obj, key, value) => {
1036
+ __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
1037
+ return value;
1038
+ };
1039
+ var __async$1 = (__this, __arguments, generator) => {
666
1040
  return new Promise((resolve, reject) => {
667
1041
  var fulfilled = (value) => {
668
1042
  try {
@@ -699,21 +1073,24 @@ class Map extends maplibregl__default.Map {
699
1073
  "MapTiler Cloud API key is not set. Visit https://maptiler.com and try Cloud for free!"
700
1074
  );
701
1075
  }
702
- super(__spreadProps(__spreadValues({}, options), {
1076
+ super(__spreadProps$1(__spreadValues$2({}, options), {
703
1077
  style,
704
1078
  maplibreLogo: false,
705
1079
  transformRequest: combineTransformRequest(options.transformRequest)
706
1080
  }));
707
- this.isTerrainEnabled = false;
708
- this.terrainExaggeration = 1;
709
- this.primaryLanguage = null;
710
- this.secondaryLanguage = null;
711
- this.terrainGrowing = false;
712
- this.terrainFlattening = false;
1081
+ __publicField$2(this, "isTerrainEnabled", false);
1082
+ __publicField$2(this, "terrainExaggeration", 1);
1083
+ __publicField$2(this, "primaryLanguage");
1084
+ __publicField$2(this, "terrainGrowing", false);
1085
+ __publicField$2(this, "terrainFlattening", false);
1086
+ __publicField$2(this, "minimap");
1087
+ __publicField$2(this, "forceLanguageUpdate");
1088
+ __publicField$2(this, "languageAlwaysBeenStyle");
713
1089
  this.primaryLanguage = (_a = options.language) != null ? _a : config.primaryLanguage;
714
- this.secondaryLanguage = config.secondaryLanguage;
1090
+ this.forceLanguageUpdate = this.primaryLanguage === Language.STYLE || this.primaryLanguage === Language.STYLE_LOCK ? false : true;
1091
+ this.languageAlwaysBeenStyle = this.primaryLanguage === Language.STYLE;
715
1092
  this.terrainExaggeration = (_b = options.terrainExaggeration) != null ? _b : this.terrainExaggeration;
716
- this.once("styledata", () => __async(this, null, function* () {
1093
+ this.once("styledata", () => __async$1(this, null, function* () {
717
1094
  if (!options.geolocate) {
718
1095
  return;
719
1096
  }
@@ -731,7 +1108,7 @@ class Map extends maplibregl__default.Map {
731
1108
  } catch (e) {
732
1109
  console.warn(e.message);
733
1110
  }
734
- let ipLocatedCameraHash = null;
1111
+ let ipLocatedCameraHash;
735
1112
  try {
736
1113
  yield this.centerOnIpPoint(options.zoom);
737
1114
  ipLocatedCameraHash = this.getCameraHash();
@@ -779,21 +1156,20 @@ class Map extends maplibregl__default.Map {
779
1156
  }));
780
1157
  this.on("styledata", () => {
781
1158
  this.setPrimaryLanguage(this.primaryLanguage);
782
- this.setSecondaryLanguage(this.secondaryLanguage);
783
1159
  });
784
1160
  this.on("styledata", () => {
785
1161
  if (this.getTerrain() === null && this.isTerrainEnabled) {
786
1162
  this.enableTerrain(this.terrainExaggeration);
787
1163
  }
788
1164
  });
789
- this.once("load", () => __async(this, null, function* () {
1165
+ this.once("load", () => __async$1(this, null, function* () {
790
1166
  enableRTL();
791
1167
  }));
792
- this.once("load", () => __async(this, null, function* () {
1168
+ this.once("load", () => __async$1(this, null, function* () {
793
1169
  let tileJsonContent = { logo: null };
794
1170
  try {
795
1171
  const possibleSources = Object.keys(this.style.sourceCaches).map((sourceName) => this.getSource(sourceName)).filter(
796
- (s) => typeof s.url === "string" && s.url.includes("tiles.json")
1172
+ (s) => s && "url" in s && typeof s.url === "string" && (s == null ? void 0 : s.url.includes("tiles.json"))
797
1173
  );
798
1174
  const styleUrl = new URL(
799
1175
  possibleSources[0].url
@@ -805,21 +1181,23 @@ class Map extends maplibregl__default.Map {
805
1181
  tileJsonContent = yield tileJsonRes.json();
806
1182
  } catch (e) {
807
1183
  }
808
- if ("logo" in tileJsonContent && tileJsonContent.logo) {
809
- const logoURL = tileJsonContent.logo;
810
- this.addControl(
811
- new MaptilerLogoControl({ logoURL }),
812
- options.logoPosition
813
- );
814
- if (options.attributionControl === false) {
1184
+ if (options.forceNoAttributionControl !== true) {
1185
+ if ("logo" in tileJsonContent && tileJsonContent.logo) {
1186
+ const logoURL = tileJsonContent.logo;
815
1187
  this.addControl(
816
- new AttributionControl({
817
- customAttribution: options.customAttribution
818
- })
1188
+ new MaptilerLogoControl({ logoURL }),
1189
+ options.logoPosition
819
1190
  );
1191
+ if (options.attributionControl === false) {
1192
+ this.addControl(
1193
+ new AttributionControl({
1194
+ customAttribution: options.customAttribution
1195
+ })
1196
+ );
1197
+ }
1198
+ } else if (options.maptilerLogo) {
1199
+ this.addControl(new MaptilerLogoControl(), options.logoPosition);
820
1200
  }
821
- } else if (options.maptilerLogo) {
822
- this.addControl(new MaptilerLogoControl(), options.logoPosition);
823
1201
  }
824
1202
  if (options.scaleControl) {
825
1203
  const position = options.scaleControl === true || options.scaleControl === void 0 ? "bottom-right" : options.scaleControl;
@@ -864,13 +1242,73 @@ class Map extends maplibregl__default.Map {
864
1242
  }));
865
1243
  let loadEventTriggered = false;
866
1244
  let terrainEventTriggered = false;
867
- let terrainEventData = null;
868
- this.once("load", (_) => {
1245
+ let terrainEventData;
1246
+ this.once("load", () => {
869
1247
  loadEventTriggered = true;
870
1248
  if (terrainEventTriggered) {
871
1249
  this.fire("loadWithTerrain", terrainEventData);
872
1250
  }
873
1251
  });
1252
+ this.once("style.load", () => {
1253
+ var _a2;
1254
+ const { minimap } = options;
1255
+ if (typeof minimap === "object") {
1256
+ const {
1257
+ zoom,
1258
+ center,
1259
+ style: style2,
1260
+ language,
1261
+ apiKey,
1262
+ maptilerLogo,
1263
+ antialias,
1264
+ refreshExpiredTiles,
1265
+ maxBounds,
1266
+ scrollZoom,
1267
+ minZoom,
1268
+ maxZoom,
1269
+ boxZoom,
1270
+ locale,
1271
+ fadeDuration,
1272
+ crossSourceCollisions,
1273
+ clickTolerance,
1274
+ bounds,
1275
+ fitBoundsOptions,
1276
+ pixelRatio,
1277
+ validateStyle
1278
+ } = options;
1279
+ this.minimap = new Minimap(minimap, {
1280
+ zoom,
1281
+ center,
1282
+ style: style2,
1283
+ language,
1284
+ apiKey,
1285
+ container: "null",
1286
+ maptilerLogo,
1287
+ antialias,
1288
+ refreshExpiredTiles,
1289
+ maxBounds,
1290
+ scrollZoom,
1291
+ minZoom,
1292
+ maxZoom,
1293
+ boxZoom,
1294
+ locale,
1295
+ fadeDuration,
1296
+ crossSourceCollisions,
1297
+ clickTolerance,
1298
+ bounds,
1299
+ fitBoundsOptions,
1300
+ pixelRatio,
1301
+ validateStyle
1302
+ });
1303
+ this.addControl(this.minimap, (_a2 = minimap.position) != null ? _a2 : "bottom-left");
1304
+ } else if (minimap === true) {
1305
+ this.minimap = new Minimap({}, options);
1306
+ this.addControl(this.minimap, "bottom-left");
1307
+ } else if (minimap !== void 0 && minimap !== false) {
1308
+ this.minimap = new Minimap({}, options);
1309
+ this.addControl(this.minimap, minimap);
1310
+ }
1311
+ });
874
1312
  const terrainCallback = (evt) => {
875
1313
  if (!evt.terrain)
876
1314
  return;
@@ -899,12 +1337,12 @@ class Map extends maplibregl__default.Map {
899
1337
  * @returns
900
1338
  */
901
1339
  onLoadAsync() {
902
- return __async(this, null, function* () {
903
- return new Promise((resolve, reject) => {
1340
+ return __async$1(this, null, function* () {
1341
+ return new Promise((resolve) => {
904
1342
  if (this.loaded()) {
905
1343
  return resolve(this);
906
1344
  }
907
- this.once("load", (_) => {
1345
+ this.once("load", () => {
908
1346
  resolve(this);
909
1347
  });
910
1348
  });
@@ -918,12 +1356,12 @@ class Map extends maplibregl__default.Map {
918
1356
  * @returns
919
1357
  */
920
1358
  onLoadWithTerrainAsync() {
921
- return __async(this, null, function* () {
922
- return new Promise((resolve, reject) => {
1359
+ return __async$1(this, null, function* () {
1360
+ return new Promise((resolve) => {
923
1361
  if (this.loaded() && this.terrain) {
924
1362
  return resolve(this);
925
1363
  }
926
- this.once("loadWithTerrain", (_) => {
1364
+ this.once("loadWithTerrain", () => {
927
1365
  resolve(this);
928
1366
  });
929
1367
  });
@@ -935,182 +1373,298 @@ class Map extends maplibregl__default.Map {
935
1373
  * - a full style URL (possibly with API key)
936
1374
  * - a shorthand with only the MapTIler style name (eg. `"streets-v2"`)
937
1375
  * - a longer form with the prefix `"maptiler://"` (eg. `"maptiler://streets-v2"`)
938
- * @param style
939
- * @param options
940
- * @returns
941
1376
  */
942
1377
  setStyle(style, options) {
1378
+ var _a;
1379
+ (_a = this.minimap) == null ? void 0 : _a.setStyle(style);
1380
+ this.forceLanguageUpdate = true;
1381
+ this.once("idle", () => {
1382
+ this.forceLanguageUpdate = false;
1383
+ });
943
1384
  return super.setStyle(styleToStyle(style), options);
944
1385
  }
945
1386
  /**
946
- * Define the primary language of the map. Note that not all the languages shorthands provided are available.
947
- * This function is a short for `.setPrimaryLanguage()`
948
- * @param language
1387
+ * Adds a [MapLibre style layer](https://maplibre.org/maplibre-style-spec/layers)
1388
+ * to the map's style.
1389
+ *
1390
+ * A layer defines how data from a specified source will be styled. Read more about layer types
1391
+ * and available paint and layout properties in the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/layers).
1392
+ *
1393
+ * @param layer - The layer to add,
1394
+ * conforming to either the MapLibre Style Specification's [layer definition](https://maplibre.org/maplibre-style-spec/layers) or,
1395
+ * less commonly, the {@link CustomLayerInterface} specification.
1396
+ * The MapLibre Style Specification's layer definition is appropriate for most layers.
1397
+ *
1398
+ * @param beforeId - The ID of an existing layer to insert the new layer before,
1399
+ * resulting in the new layer appearing visually beneath the existing layer.
1400
+ * If this argument is not specified, the layer will be appended to the end of the layers array
1401
+ * and appear visually above all other layers.
1402
+ *
1403
+ * @returns `this`
949
1404
  */
950
- setLanguage(language = defaults.primaryLanguage) {
951
- if (language === Language.AUTO) {
952
- return this.setLanguage(getBrowserLanguage());
953
- }
954
- this.setPrimaryLanguage(language);
1405
+ addLayer(layer, beforeId) {
1406
+ var _a;
1407
+ (_a = this.minimap) == null ? void 0 : _a.addLayer(layer, beforeId);
1408
+ return super.addLayer(layer, beforeId);
955
1409
  }
956
1410
  /**
957
- * Define the primary language of the map. Note that not all the languages shorthands provided are available.
958
- * @param language
1411
+ * Moves a layer to a different z-position.
1412
+ *
1413
+ * @param id - The ID of the layer to move.
1414
+ * @param beforeId - The ID of an existing layer to insert the new layer before. When viewing the map, the `id` layer will appear beneath the `beforeId` layer. If `beforeId` is omitted, the layer will be appended to the end of the layers array and appear above all other layers on the map.
1415
+ * @returns `this`
1416
+ *
1417
+ * @example
1418
+ * Move a layer with ID 'polygon' before the layer with ID 'country-label'. The `polygon` layer will appear beneath the `country-label` layer on the map.
1419
+ * ```ts
1420
+ * map.moveLayer('polygon', 'country-label');
1421
+ * ```
959
1422
  */
960
- setPrimaryLanguage(language = defaults.primaryLanguage) {
961
- if (this.primaryLanguage === Language.STYLE_LOCK) {
962
- console.warn(
963
- "The language cannot be changed because this map has been instantiated with the STYLE_LOCK language flag."
964
- );
965
- return;
966
- }
967
- if (!isLanguageSupported(language)) {
968
- return;
969
- }
970
- this.primaryLanguage = language;
971
- this.onStyleReady(() => {
972
- if (language === Language.AUTO) {
973
- return this.setPrimaryLanguage(getBrowserLanguage());
974
- }
975
- const layers = this.getStyle().layers;
976
- const strLanguageRegex = /^\s*{\s*name\s*(:\s*(\S*))?\s*}$/;
977
- const strLanguageInArrayRegex = /^\s*name\s*(:\s*(\S*))?\s*$/;
978
- const strBilingualRegex = /^\s*{\s*name\s*(:\s*(\S*))?\s*}(\s*){\s*name\s*(:\s*(\S*))?\s*}$/;
979
- const strMoreInfoRegex = /^(.*)({\s*name\s*(:\s*(\S*))?\s*})(.*)$/;
980
- const langStr = language ? `name:${language}` : "name";
981
- const replacer = [
982
- "case",
983
- ["has", langStr],
984
- ["get", langStr],
985
- ["get", "name"]
986
- ];
987
- for (let i = 0; i < layers.length; i += 1) {
988
- const layer = layers[i];
989
- const layout = layer.layout;
990
- if (!layout) {
991
- continue;
992
- }
993
- if (!layout["text-field"]) {
994
- continue;
995
- }
996
- const textFieldLayoutProp = this.getLayoutProperty(
997
- layer.id,
998
- "text-field"
999
- );
1000
- let regexMatch;
1001
- if (Array.isArray(textFieldLayoutProp) && textFieldLayoutProp.length >= 2 && textFieldLayoutProp[0].trim().toLowerCase() === "concat") {
1002
- const newProp = textFieldLayoutProp.slice();
1003
- for (let j = 0; j < textFieldLayoutProp.length; j += 1) {
1004
- const elem = textFieldLayoutProp[j];
1005
- if ((typeof elem === "string" || elem instanceof String) && strLanguageRegex.exec(elem.toString())) {
1006
- newProp[j] = replacer;
1007
- break;
1008
- } else if (Array.isArray(elem) && elem.length >= 2 && elem[0].trim().toLowerCase() === "get" && strLanguageInArrayRegex.exec(elem[1].toString())) {
1009
- newProp[j] = replacer;
1010
- break;
1011
- } else if (Array.isArray(elem) && elem.length === 4 && elem[0].trim().toLowerCase() === "case") {
1012
- newProp[j] = replacer;
1013
- break;
1014
- }
1015
- }
1016
- this.setLayoutProperty(layer.id, "text-field", newProp);
1017
- } else if (Array.isArray(textFieldLayoutProp) && textFieldLayoutProp.length >= 2 && textFieldLayoutProp[0].trim().toLowerCase() === "get" && strLanguageInArrayRegex.exec(textFieldLayoutProp[1].toString())) {
1018
- const newProp = replacer;
1019
- this.setLayoutProperty(layer.id, "text-field", newProp);
1020
- } else if ((typeof textFieldLayoutProp === "string" || textFieldLayoutProp instanceof String) && strLanguageRegex.exec(textFieldLayoutProp.toString())) {
1021
- const newProp = replacer;
1022
- this.setLayoutProperty(layer.id, "text-field", newProp);
1023
- } else if (Array.isArray(textFieldLayoutProp) && textFieldLayoutProp.length === 4 && textFieldLayoutProp[0].trim().toLowerCase() === "case") {
1024
- const newProp = replacer;
1025
- this.setLayoutProperty(layer.id, "text-field", newProp);
1026
- } else if ((typeof textFieldLayoutProp === "string" || textFieldLayoutProp instanceof String) && (regexMatch = strBilingualRegex.exec(
1027
- textFieldLayoutProp.toString()
1028
- )) !== null) {
1029
- const newProp = `{${langStr}}${regexMatch[3]}{name${regexMatch[4] || ""}}`;
1030
- this.setLayoutProperty(layer.id, "text-field", newProp);
1031
- } else if ((typeof textFieldLayoutProp === "string" || textFieldLayoutProp instanceof String) && (regexMatch = strMoreInfoRegex.exec(
1032
- textFieldLayoutProp.toString()
1033
- )) !== null) {
1034
- const newProp = `${regexMatch[1]}{${langStr}}${regexMatch[5]}`;
1035
- this.setLayoutProperty(layer.id, "text-field", newProp);
1036
- }
1037
- }
1038
- });
1423
+ moveLayer(id, beforeId) {
1424
+ var _a;
1425
+ (_a = this.minimap) == null ? void 0 : _a.moveLayer(id, beforeId);
1426
+ return super.moveLayer(id, beforeId);
1039
1427
  }
1040
1428
  /**
1041
- * Define the secondary language of the map. Note that this is not supported by all the map styles
1042
- * Note that most styles do not allow a secondary language and this function only works if the style allows (no force adding)
1043
- * @param language
1429
+ * Removes the layer with the given ID from the map's style.
1430
+ *
1431
+ * An {@link ErrorEvent} will be fired if the image parameter is invald.
1432
+ *
1433
+ * @param id - The ID of the layer to remove
1434
+ * @returns `this`
1435
+ *
1436
+ * @example
1437
+ * If a layer with ID 'state-data' exists, remove it.
1438
+ * ```ts
1439
+ * if (map.getLayer('state-data')) map.removeLayer('state-data');
1440
+ * ```
1044
1441
  */
1045
- setSecondaryLanguage(language = defaults.secondaryLanguage) {
1046
- if (this.primaryLanguage === Language.STYLE_LOCK) {
1047
- console.warn(
1048
- "The language cannot be changed because this map has been instantiated with the STYLE_LOCK language flag."
1049
- );
1050
- return;
1442
+ removeLayer(id) {
1443
+ var _a;
1444
+ (_a = this.minimap) == null ? void 0 : _a.removeLayer(id);
1445
+ return super.removeLayer(id);
1446
+ }
1447
+ /**
1448
+ * Sets the zoom extent for the specified style layer. The zoom extent includes the
1449
+ * [minimum zoom level](https://maplibre.org/maplibre-style-spec/layers/#minzoom)
1450
+ * and [maximum zoom level](https://maplibre.org/maplibre-style-spec/layers/#maxzoom))
1451
+ * at which the layer will be rendered.
1452
+ *
1453
+ * Note: For style layers using vector sources, style layers cannot be rendered at zoom levels lower than the
1454
+ * minimum zoom level of the _source layer_ because the data does not exist at those zoom levels. If the minimum
1455
+ * zoom level of the source layer is higher than the minimum zoom level defined in the style layer, the style
1456
+ * layer will not be rendered at all zoom levels in the zoom range.
1457
+ */
1458
+ setLayerZoomRange(layerId, minzoom, maxzoom) {
1459
+ var _a;
1460
+ (_a = this.minimap) == null ? void 0 : _a.setLayerZoomRange(layerId, minzoom, maxzoom);
1461
+ return super.setLayerZoomRange(layerId, minzoom, maxzoom);
1462
+ }
1463
+ /**
1464
+ * Sets the filter for the specified style layer.
1465
+ *
1466
+ * Filters control which features a style layer renders from its source.
1467
+ * Any feature for which the filter expression evaluates to `true` will be
1468
+ * rendered on the map. Those that are false will be hidden.
1469
+ *
1470
+ * Use `setFilter` to show a subset of your source data.
1471
+ *
1472
+ * To clear the filter, pass `null` or `undefined` as the second parameter.
1473
+ */
1474
+ setFilter(layerId, filter, options) {
1475
+ var _a;
1476
+ (_a = this.minimap) == null ? void 0 : _a.setFilter(layerId, filter, options);
1477
+ return super.setFilter(layerId, filter, options);
1478
+ }
1479
+ /**
1480
+ * Sets the value of a paint property in the specified style layer.
1481
+ *
1482
+ * @param layerId - The ID of the layer to set the paint property in.
1483
+ * @param name - The name of the paint property to set.
1484
+ * @param value - The value of the paint property to set.
1485
+ * Must be of a type appropriate for the property, as defined in the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/).
1486
+ * @param options - Options object.
1487
+ * @returns `this`
1488
+ * @example
1489
+ * ```ts
1490
+ * map.setPaintProperty('my-layer', 'fill-color', '#faafee');
1491
+ * ```
1492
+ */
1493
+ setPaintProperty(layerId, name, value, options) {
1494
+ var _a;
1495
+ (_a = this.minimap) == null ? void 0 : _a.setPaintProperty(layerId, name, value, options);
1496
+ return super.setPaintProperty(layerId, name, value, options);
1497
+ }
1498
+ /**
1499
+ * Sets the value of a layout property in the specified style layer.
1500
+ * Layout properties define how the layer is styled.
1501
+ * Layout properties for layers of the same type are documented together.
1502
+ * Layers of different types have different layout properties.
1503
+ * See the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/) for the complete list of layout properties.
1504
+ * @param layerId - The ID of the layer to set the layout property in.
1505
+ * @param name - The name of the layout property to set.
1506
+ * @param value - The value of the layout property to set.
1507
+ * Must be of a type appropriate for the property, as defined in the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/).
1508
+ * @param options - Options object.
1509
+ * @returns `this`
1510
+ */
1511
+ setLayoutProperty(layerId, name, value, options) {
1512
+ var _a;
1513
+ (_a = this.minimap) == null ? void 0 : _a.setLayoutProperty(layerId, name, value, options);
1514
+ return super.setLayoutProperty(layerId, name, value, options);
1515
+ }
1516
+ /**
1517
+ * Sets the value of the style's glyphs property.
1518
+ *
1519
+ * @param glyphsUrl - Glyph URL to set. Must conform to the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/glyphs/).
1520
+ * @param options - Options object.
1521
+ * @returns `this`
1522
+ * @example
1523
+ * ```ts
1524
+ * map.setGlyphs('https://demotiles.maplibre.org/font/{fontstack}/{range}.pbf');
1525
+ * ```
1526
+ */
1527
+ setGlyphs(glyphsUrl, options) {
1528
+ var _a;
1529
+ (_a = this.minimap) == null ? void 0 : _a.setGlyphs(glyphsUrl, options);
1530
+ return super.setGlyphs(glyphsUrl, options);
1531
+ }
1532
+ getStyleLanguage() {
1533
+ if (!this.style.stylesheet.metadata)
1534
+ return null;
1535
+ if (typeof this.style.stylesheet.metadata !== "object")
1536
+ return null;
1537
+ if ("maptiler:language" in this.style.stylesheet.metadata && typeof this.style.stylesheet.metadata["maptiler:language"] === "string") {
1538
+ return this.style.stylesheet.metadata["maptiler:language"];
1539
+ } else {
1540
+ return null;
1541
+ }
1542
+ }
1543
+ /**
1544
+ * Define the primary language of the map. Note that not all the languages shorthands provided are available.
1545
+ */
1546
+ setLanguage(language) {
1547
+ var _a, _b;
1548
+ (_b = (_a = this.minimap) == null ? void 0 : _a.map) == null ? void 0 : _b.setLanguage(language);
1549
+ this.onStyleReady(() => {
1550
+ this.setPrimaryLanguage(language);
1551
+ });
1552
+ }
1553
+ /**
1554
+ * Define the primary language of the map. Note that not all the languages shorthands provided are available.
1555
+ */
1556
+ setPrimaryLanguage(language) {
1557
+ const styleLanguage = this.getStyleLanguage();
1558
+ if (!(language === Language.STYLE && (styleLanguage === Language.AUTO || styleLanguage === Language.VISITOR))) {
1559
+ if (language !== Language.STYLE) {
1560
+ this.languageAlwaysBeenStyle = false;
1561
+ }
1562
+ if (this.languageAlwaysBeenStyle) {
1563
+ return;
1564
+ }
1565
+ if (this.primaryLanguage === language && !this.forceLanguageUpdate) {
1566
+ return;
1567
+ }
1051
1568
  }
1052
1569
  if (!isLanguageSupported(language)) {
1570
+ console.warn(`The language "${language}" is not supported.`);
1053
1571
  return;
1054
1572
  }
1055
- this.secondaryLanguage = language;
1056
- this.onStyleReady(() => {
1057
- if (language === Language.AUTO) {
1058
- return this.setSecondaryLanguage(getBrowserLanguage());
1573
+ if (this.primaryLanguage === Language.STYLE_LOCK) {
1574
+ console.warn(
1575
+ "The language cannot be changed because this map has been instantiated with the STYLE_LOCK language flag."
1576
+ );
1577
+ return;
1578
+ }
1579
+ this.primaryLanguage = language;
1580
+ let languageNonStyle = language;
1581
+ if (language === Language.STYLE) {
1582
+ if (!styleLanguage) {
1583
+ console.warn("The style has no default languages.");
1584
+ return;
1059
1585
  }
1060
- const layers = this.getStyle().layers;
1061
- const strLanguageRegex = /^\s*{\s*name\s*(:\s*(\S*))?\s*}$/;
1062
- const strLanguageInArrayRegex = /^\s*name\s*(:\s*(\S*))?\s*$/;
1063
- const strBilingualRegex = /^\s*{\s*name\s*(:\s*(\S*))?\s*}(\s*){\s*name\s*(:\s*(\S*))?\s*}$/;
1064
- let regexMatch;
1065
- for (let i = 0; i < layers.length; i += 1) {
1066
- const layer = layers[i];
1067
- const layout = layer.layout;
1068
- if (!layout) {
1069
- continue;
1070
- }
1071
- if (!layout["text-field"]) {
1072
- continue;
1073
- }
1074
- const textFieldLayoutProp = this.getLayoutProperty(
1075
- layer.id,
1076
- "text-field"
1077
- );
1078
- let newProp;
1079
- if (Array.isArray(textFieldLayoutProp) && textFieldLayoutProp.length >= 2 && textFieldLayoutProp[0].trim().toLowerCase() === "concat") {
1080
- newProp = textFieldLayoutProp.slice();
1081
- let languagesAlreadyFound = 0;
1082
- for (let j = 0; j < textFieldLayoutProp.length; j += 1) {
1083
- const elem = textFieldLayoutProp[j];
1084
- if ((typeof elem === "string" || elem instanceof String) && strLanguageRegex.exec(elem.toString())) {
1085
- if (languagesAlreadyFound === 1) {
1086
- newProp[j] = `{name:${language}}`;
1087
- break;
1088
- }
1089
- languagesAlreadyFound += 1;
1090
- } else if (Array.isArray(elem) && elem.length >= 2 && elem[0].trim().toLowerCase() === "get" && strLanguageInArrayRegex.exec(elem[1].toString())) {
1091
- if (languagesAlreadyFound === 1) {
1092
- newProp[j][1] = `name:${language}`;
1093
- break;
1094
- }
1095
- languagesAlreadyFound += 1;
1096
- } else if (Array.isArray(elem) && elem.length === 4 && elem[0].trim().toLowerCase() === "case") {
1097
- if (languagesAlreadyFound === 1) {
1098
- newProp[j] = ["get", `name:${language}`];
1099
- break;
1100
- }
1101
- languagesAlreadyFound += 1;
1102
- }
1103
- }
1104
- this.setLayoutProperty(layer.id, "text-field", newProp);
1105
- } else if ((typeof textFieldLayoutProp === "string" || textFieldLayoutProp instanceof String) && (regexMatch = strBilingualRegex.exec(
1106
- textFieldLayoutProp.toString()
1107
- )) !== null) {
1108
- const langStr = language ? `name:${language}` : "name";
1109
- newProp = `{name${regexMatch[1] || ""}}${regexMatch[3]}{${langStr}}`;
1110
- this.setLayoutProperty(layer.id, "text-field", newProp);
1111
- }
1586
+ if (!isLanguageSupported(styleLanguage)) {
1587
+ console.warn("The language defined in the style is not valid.");
1588
+ return;
1112
1589
  }
1113
- });
1590
+ languageNonStyle = styleLanguage;
1591
+ }
1592
+ let langStr = Language.LOCAL;
1593
+ let replacer = `{${langStr}}`;
1594
+ if (languageNonStyle == Language.VISITOR) {
1595
+ langStr = getBrowserLanguage();
1596
+ replacer = [
1597
+ "case",
1598
+ ["all", ["has", langStr], ["has", Language.LOCAL]],
1599
+ [
1600
+ "case",
1601
+ ["==", ["get", langStr], ["get", Language.LOCAL]],
1602
+ ["get", Language.LOCAL],
1603
+ [
1604
+ "format",
1605
+ ["get", langStr],
1606
+ { "font-scale": 0.8 },
1607
+ "\n",
1608
+ ["get", Language.LOCAL],
1609
+ { "font-scale": 1.1 }
1610
+ ]
1611
+ ],
1612
+ ["get", Language.LOCAL]
1613
+ ];
1614
+ } else if (languageNonStyle == Language.VISITOR_ENGLISH) {
1615
+ langStr = Language.ENGLISH;
1616
+ replacer = [
1617
+ "case",
1618
+ ["all", ["has", langStr], ["has", Language.LOCAL]],
1619
+ [
1620
+ "case",
1621
+ ["==", ["get", langStr], ["get", Language.LOCAL]],
1622
+ ["get", Language.LOCAL],
1623
+ [
1624
+ "format",
1625
+ ["get", langStr],
1626
+ { "font-scale": 0.8 },
1627
+ "\n",
1628
+ ["get", Language.LOCAL],
1629
+ { "font-scale": 1.1 }
1630
+ ]
1631
+ ],
1632
+ ["get", Language.LOCAL]
1633
+ ];
1634
+ } else if (languageNonStyle === Language.AUTO) {
1635
+ langStr = getBrowserLanguage();
1636
+ replacer = [
1637
+ "case",
1638
+ ["has", langStr],
1639
+ ["get", langStr],
1640
+ ["get", Language.LOCAL]
1641
+ ];
1642
+ } else if (languageNonStyle === Language.LOCAL) {
1643
+ langStr = Language.LOCAL;
1644
+ replacer = `{${langStr}}`;
1645
+ } else {
1646
+ langStr = languageNonStyle;
1647
+ replacer = [
1648
+ "case",
1649
+ ["has", langStr],
1650
+ ["get", langStr],
1651
+ ["get", Language.LOCAL]
1652
+ ];
1653
+ }
1654
+ const { layers } = this.getStyle();
1655
+ for (const { id, layout } of layers) {
1656
+ if (!layout) {
1657
+ continue;
1658
+ }
1659
+ if (!("text-field" in layout)) {
1660
+ continue;
1661
+ }
1662
+ const textFieldLayoutProp = this.getLayoutProperty(id, "text-field");
1663
+ if (typeof textFieldLayoutProp === "string" && (textFieldLayoutProp.toLowerCase().includes("ref") || textFieldLayoutProp.toLowerCase().includes("housenumber"))) {
1664
+ continue;
1665
+ }
1666
+ this.setLayoutProperty(id, "text-field", replacer);
1667
+ }
1114
1668
  }
1115
1669
  /**
1116
1670
  * Get the primary language
@@ -1119,13 +1673,6 @@ class Map extends maplibregl__default.Map {
1119
1673
  getPrimaryLanguage() {
1120
1674
  return this.primaryLanguage;
1121
1675
  }
1122
- /**
1123
- * Get the secondary language
1124
- * @returns
1125
- */
1126
- getSecondaryLanguage() {
1127
- return this.secondaryLanguage;
1128
- }
1129
1676
  /**
1130
1677
  * Get the exaggeration factor applied to the terrain
1131
1678
  * @returns
@@ -1173,15 +1720,13 @@ class Map extends maplibregl__default.Map {
1173
1720
  }
1174
1721
  /**
1175
1722
  * Enables the 3D terrain visualization
1176
- * @param exaggeration
1177
- * @returns
1178
1723
  */
1179
1724
  enableTerrain(exaggeration = this.terrainExaggeration) {
1180
1725
  if (exaggeration < 0) {
1181
1726
  console.warn("Terrain exaggeration cannot be negative.");
1182
1727
  return;
1183
1728
  }
1184
- const dataEventTerrainGrow = (evt) => __async(this, null, function* () {
1729
+ const dataEventTerrainGrow = (evt) => __async$1(this, null, function* () {
1185
1730
  if (!this.terrain) {
1186
1731
  return;
1187
1732
  }
@@ -1258,7 +1803,7 @@ class Map extends maplibregl__default.Map {
1258
1803
  this.terrain.exaggeration = 0;
1259
1804
  this.terrainGrowing = false;
1260
1805
  this.terrainFlattening = false;
1261
- this.setTerrain(null);
1806
+ this.setTerrain();
1262
1807
  if (this.getSource(defaults.terrainSourceId)) {
1263
1808
  this.removeSource(defaults.terrainSourceId);
1264
1809
  }
@@ -1275,8 +1820,6 @@ class Map extends maplibregl__default.Map {
1275
1820
  * the method `.enableTerrain()` will be called.
1276
1821
  * If `animate` is `true`, the terrain transformation will be animated in the span of 1 second.
1277
1822
  * If `animate` is `false`, no animated transition to the newly defined exaggeration.
1278
- * @param exaggeration
1279
- * @param animate
1280
1823
  */
1281
1824
  setTerrainExaggeration(exaggeration, animate = true) {
1282
1825
  if (!animate && this.terrain) {
@@ -1290,7 +1833,6 @@ class Map extends maplibregl__default.Map {
1290
1833
  /**
1291
1834
  * Perform an action when the style is ready. It could be at the moment of calling this method
1292
1835
  * or later.
1293
- * @param cb
1294
1836
  */
1295
1837
  onStyleReady(cb) {
1296
1838
  if (this.isStyleLoaded()) {
@@ -1302,7 +1844,7 @@ class Map extends maplibregl__default.Map {
1302
1844
  }
1303
1845
  }
1304
1846
  fitToIpBounds() {
1305
- return __async(this, null, function* () {
1847
+ return __async$1(this, null, function* () {
1306
1848
  const ipGeolocateResult = yield geolocation.info();
1307
1849
  this.fitBounds(
1308
1850
  ipGeolocateResult.country_bounds,
@@ -1314,10 +1856,14 @@ class Map extends maplibregl__default.Map {
1314
1856
  });
1315
1857
  }
1316
1858
  centerOnIpPoint(zoom) {
1317
- return __async(this, null, function* () {
1859
+ return __async$1(this, null, function* () {
1860
+ var _a, _b;
1318
1861
  const ipGeolocateResult = yield geolocation.info();
1319
1862
  this.jumpTo({
1320
- center: [ipGeolocateResult.longitude, ipGeolocateResult.latitude],
1863
+ center: [
1864
+ (_a = ipGeolocateResult == null ? void 0 : ipGeolocateResult.longitude) != null ? _a : 0,
1865
+ (_b = ipGeolocateResult == null ? void 0 : ipGeolocateResult.latitude) != null ? _b : 0
1866
+ ],
1321
1867
  zoom: zoom || 11
1322
1868
  });
1323
1869
  });
@@ -1336,7 +1882,6 @@ class Map extends maplibregl__default.Map {
1336
1882
  * Get the SDK config object.
1337
1883
  * This is convenient to dispatch the SDK configuration to externally built layers
1338
1884
  * that do not directly have access to the SDK configuration but do have access to a Map instance.
1339
- * @returns
1340
1885
  */
1341
1886
  getSdkConfig() {
1342
1887
  return config;
@@ -1364,6 +1909,25 @@ class Map extends maplibregl__default.Map {
1364
1909
  super.setTransformRequest(combineTransformRequest(transformRequest));
1365
1910
  return this;
1366
1911
  }
1912
+ /**
1913
+ * Loads an image. This is an async equivalent of `Map.loadImage`
1914
+ */
1915
+ loadImageAsync(url) {
1916
+ return __async$1(this, null, function* () {
1917
+ return new Promise((resolve, reject) => {
1918
+ this.loadImage(
1919
+ url,
1920
+ (error, image) => {
1921
+ if (error) {
1922
+ reject(error);
1923
+ return;
1924
+ }
1925
+ resolve(image);
1926
+ }
1927
+ );
1928
+ });
1929
+ });
1930
+ }
1367
1931
  }
1368
1932
 
1369
1933
  class Marker extends maplibregl__default.Marker {
@@ -1432,8 +1996,16 @@ class TerrainControl extends maplibregl__default.TerrainControl {
1432
1996
  }
1433
1997
  }
1434
1998
 
1999
+ var __defProp$3 = Object.defineProperty;
2000
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2001
+ var __publicField$1 = (obj, key, value) => {
2002
+ __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
2003
+ return value;
2004
+ };
1435
2005
  class Point {
1436
2006
  constructor(x, y) {
2007
+ __publicField$1(this, "x");
2008
+ __publicField$1(this, "y");
1437
2009
  this.x = x;
1438
2010
  this.y = y;
1439
2011
  }
@@ -1717,6 +2289,2510 @@ class Point {
1717
2289
  }
1718
2290
  }
1719
2291
 
2292
+ var __defProp$2 = Object.defineProperty;
2293
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
2294
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
2295
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
2296
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2297
+ var __spreadValues$1 = (a, b) => {
2298
+ for (var prop in b || (b = {}))
2299
+ if (__hasOwnProp$1.call(b, prop))
2300
+ __defNormalProp$2(a, prop, b[prop]);
2301
+ if (__getOwnPropSymbols$1)
2302
+ for (var prop of __getOwnPropSymbols$1(b)) {
2303
+ if (__propIsEnum$1.call(b, prop))
2304
+ __defNormalProp$2(a, prop, b[prop]);
2305
+ }
2306
+ return a;
2307
+ };
2308
+ function str2xml(str) {
2309
+ if (typeof DOMParser !== "undefined") {
2310
+ const doc = new DOMParser().parseFromString(str, "application/xml");
2311
+ if (doc.querySelector("parsererror")) {
2312
+ throw new Error("The provided string is not valid XML");
2313
+ }
2314
+ return doc;
2315
+ } else {
2316
+ throw new Error("No XML parser found");
2317
+ }
2318
+ }
2319
+ function hasChildNodeWithName(doc, nodeName) {
2320
+ if (!doc.hasChildNodes()) {
2321
+ return false;
2322
+ }
2323
+ for (const childNode of Array.from(doc.childNodes)) {
2324
+ const currentNodeName = childNode.nodeName;
2325
+ if (typeof currentNodeName === "string" && currentNodeName.trim().toLowerCase() === nodeName.toLowerCase()) {
2326
+ return true;
2327
+ }
2328
+ }
2329
+ return false;
2330
+ }
2331
+ function xml2str(node) {
2332
+ if (typeof XMLSerializer !== "undefined") {
2333
+ return new XMLSerializer().serializeToString(node);
2334
+ }
2335
+ throw new Error("No XML serializer found");
2336
+ }
2337
+ function gpx(doc) {
2338
+ if (typeof doc === "string")
2339
+ doc = str2xml(doc);
2340
+ if (!hasChildNodeWithName(doc, "gpx")) {
2341
+ throw new Error("The XML document is not valid GPX");
2342
+ }
2343
+ const tracks = get(doc, "trk");
2344
+ const routes = get(doc, "rte");
2345
+ const waypoints = get(doc, "wpt");
2346
+ const gj = {
2347
+ type: "FeatureCollection",
2348
+ features: []
2349
+ };
2350
+ for (const track of Array.from(tracks)) {
2351
+ const feature = getTrack(track);
2352
+ if (feature)
2353
+ gj.features.push(feature);
2354
+ }
2355
+ for (const route of Array.from(routes)) {
2356
+ const feature = getRoute(route);
2357
+ if (feature)
2358
+ gj.features.push(feature);
2359
+ }
2360
+ for (const waypoint of Array.from(waypoints)) {
2361
+ gj.features.push(getPoint(waypoint));
2362
+ }
2363
+ return gj;
2364
+ }
2365
+ function kml(doc, xml2string) {
2366
+ var _a;
2367
+ if (typeof doc === "string")
2368
+ doc = str2xml(doc);
2369
+ if (!hasChildNodeWithName(doc, "kml")) {
2370
+ throw new Error("The XML document is not valid KML");
2371
+ }
2372
+ const gj = {
2373
+ type: "FeatureCollection",
2374
+ features: []
2375
+ };
2376
+ const styleIndex = {};
2377
+ const styleByHash = {};
2378
+ const styleMapIndex = {};
2379
+ const placemarks = get(doc, "Placemark");
2380
+ const styles = get(doc, "Style");
2381
+ const styleMaps = get(doc, "StyleMap");
2382
+ for (const style of Array.from(styles)) {
2383
+ const hash = okhash(
2384
+ xml2string !== void 0 ? xml2string(style) : xml2str(style)
2385
+ ).toString(16);
2386
+ styleIndex["#" + attr(style, "id")] = hash;
2387
+ styleByHash[hash] = style;
2388
+ }
2389
+ for (const styleMap of Array.from(styleMaps)) {
2390
+ styleIndex["#" + attr(styleMap, "id")] = okhash(
2391
+ xml2string !== void 0 ? xml2string(styleMap) : xml2str(styleMap)
2392
+ ).toString(16);
2393
+ const pairs = get(styleMap, "Pair");
2394
+ const pairsMap = {};
2395
+ for (const pair of Array.from(pairs)) {
2396
+ pairsMap[(_a = nodeVal(get1(pair, "key"))) != null ? _a : ""] = nodeVal(
2397
+ get1(pair, "styleUrl")
2398
+ );
2399
+ }
2400
+ styleMapIndex["#" + attr(styleMap, "id")] = pairsMap;
2401
+ }
2402
+ for (const placemark of Array.from(placemarks)) {
2403
+ gj.features = gj.features.concat(
2404
+ getPlacemark(placemark, styleIndex, styleByHash, styleMapIndex)
2405
+ );
2406
+ }
2407
+ return gj;
2408
+ }
2409
+ function kmlColor(v) {
2410
+ if (v === null)
2411
+ return ["#000000", 1];
2412
+ let color = "";
2413
+ let opacity = 1;
2414
+ if (v.substring(0, 1) === "#")
2415
+ v = v.substring(1);
2416
+ if (v.length === 6 || v.length === 3)
2417
+ color = v;
2418
+ if (v.length === 8) {
2419
+ opacity = parseInt(v.substring(0, 2), 16) / 255;
2420
+ color = "#" + v.substring(6, 8) + v.substring(4, 6) + v.substring(2, 4);
2421
+ }
2422
+ return [color != null ? color : "#000000", opacity != null ? opacity : 1];
2423
+ }
2424
+ function gxCoord(v) {
2425
+ return numarray(v.split(" "));
2426
+ }
2427
+ function gxCoords(root) {
2428
+ var _a;
2429
+ let elems = get(root, "coord");
2430
+ const coords = [];
2431
+ const times = [];
2432
+ if (elems.length === 0)
2433
+ elems = get(root, "gx:coord");
2434
+ for (const elem of Array.from(elems)) {
2435
+ coords.push(gxCoord((_a = nodeVal(elem)) != null ? _a : ""));
2436
+ }
2437
+ const timeElems = get(root, "when");
2438
+ for (const timeElem of Array.from(timeElems))
2439
+ times.push(nodeVal(timeElem));
2440
+ return {
2441
+ coords,
2442
+ times
2443
+ };
2444
+ }
2445
+ function getGeometry(root) {
2446
+ var _a, _b, _c;
2447
+ const geotypes = ["Polygon", "LineString", "Point", "Track", "gx:Track"];
2448
+ let geomNode, geomNodes, i, j, k;
2449
+ const geoms = [];
2450
+ const coordTimes = [];
2451
+ if (get1(root, "MultiGeometry") !== null) {
2452
+ return getGeometry(get1(root, "MultiGeometry"));
2453
+ }
2454
+ if (get1(root, "MultiTrack") !== null) {
2455
+ return getGeometry(get1(root, "MultiTrack"));
2456
+ }
2457
+ if (get1(root, "gx:MultiTrack") !== null) {
2458
+ return getGeometry(get1(root, "gx:MultiTrack"));
2459
+ }
2460
+ for (i = 0; i < geotypes.length; i++) {
2461
+ geomNodes = get(root, geotypes[i]);
2462
+ if (geomNodes) {
2463
+ for (j = 0; j < geomNodes.length; j++) {
2464
+ geomNode = geomNodes[j];
2465
+ if (geotypes[i] === "Point") {
2466
+ geoms.push({
2467
+ type: "Point",
2468
+ coordinates: coord1((_a = nodeVal(get1(geomNode, "coordinates"))) != null ? _a : "")
2469
+ });
2470
+ } else if (geotypes[i] === "LineString") {
2471
+ geoms.push({
2472
+ type: "LineString",
2473
+ coordinates: coord((_b = nodeVal(get1(geomNode, "coordinates"))) != null ? _b : "")
2474
+ });
2475
+ } else if (geotypes[i] === "Polygon") {
2476
+ const rings = get(geomNode, "LinearRing");
2477
+ const coords = [];
2478
+ for (k = 0; k < rings.length; k++) {
2479
+ coords.push(coord((_c = nodeVal(get1(rings[k], "coordinates"))) != null ? _c : ""));
2480
+ }
2481
+ geoms.push({
2482
+ type: "Polygon",
2483
+ coordinates: coords
2484
+ });
2485
+ } else if (geotypes[i] === "Track" || geotypes[i] === "gx:Track") {
2486
+ const track = gxCoords(geomNode);
2487
+ geoms.push({
2488
+ type: "LineString",
2489
+ coordinates: track.coords
2490
+ });
2491
+ if (track.times.length)
2492
+ coordTimes.push(track.times);
2493
+ }
2494
+ }
2495
+ }
2496
+ }
2497
+ return { geoms, coordTimes };
2498
+ }
2499
+ function getPlacemark(root, styleIndex, styleByHash, styleMapIndex) {
2500
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2501
+ const geomsAndTimes = getGeometry(root);
2502
+ const properties = {};
2503
+ const name = nodeVal(get1(root, "name"));
2504
+ const address = nodeVal(get1(root, "address"));
2505
+ const description = nodeVal(get1(root, "description"));
2506
+ const timeSpan = get1(root, "TimeSpan");
2507
+ const timeStamp = get1(root, "TimeStamp");
2508
+ const extendedData = get1(root, "ExtendedData");
2509
+ const visibility = get1(root, "visibility");
2510
+ let i;
2511
+ let styleUrl = nodeVal(get1(root, "styleUrl"));
2512
+ let lineStyle = get1(root, "LineStyle");
2513
+ let polyStyle = get1(root, "PolyStyle");
2514
+ if (!geomsAndTimes.geoms.length)
2515
+ return [];
2516
+ if (name)
2517
+ properties.name = name;
2518
+ if (address)
2519
+ properties.address = address;
2520
+ if (styleUrl) {
2521
+ if (styleUrl[0] !== "#")
2522
+ styleUrl = "#" + styleUrl;
2523
+ properties.styleUrl = styleUrl;
2524
+ if (styleIndex[styleUrl]) {
2525
+ properties.styleHash = styleIndex[styleUrl];
2526
+ }
2527
+ if (styleMapIndex[styleUrl]) {
2528
+ properties.styleMapHash = styleMapIndex[styleUrl];
2529
+ properties.styleHash = styleIndex[(_a = styleMapIndex[styleUrl].normal) != null ? _a : ""];
2530
+ }
2531
+ const style = styleByHash[(_b = properties.styleHash) != null ? _b : ""];
2532
+ if (style) {
2533
+ if (!lineStyle)
2534
+ lineStyle = get1(style, "LineStyle");
2535
+ if (!polyStyle)
2536
+ polyStyle = get1(style, "PolyStyle");
2537
+ const iconStyle = get1(style, "IconStyle");
2538
+ if (iconStyle) {
2539
+ const icon = get1(iconStyle, "Icon");
2540
+ if (icon) {
2541
+ const href = nodeVal(get1(icon, "href"));
2542
+ if (href)
2543
+ properties.icon = href;
2544
+ }
2545
+ }
2546
+ }
2547
+ }
2548
+ if (description)
2549
+ properties.description = description;
2550
+ if (timeSpan) {
2551
+ const begin = nodeVal(get1(timeSpan, "begin"));
2552
+ const end = nodeVal(get1(timeSpan, "end"));
2553
+ if (begin && end)
2554
+ properties.timespan = { begin, end };
2555
+ }
2556
+ if (timeStamp !== null) {
2557
+ properties.timestamp = (_c = nodeVal(get1(timeStamp, "when"))) != null ? _c : (/* @__PURE__ */ new Date()).toISOString();
2558
+ }
2559
+ if (lineStyle !== null) {
2560
+ const linestyles = kmlColor(nodeVal(get1(lineStyle, "color")));
2561
+ const color = linestyles[0];
2562
+ const opacity = linestyles[1];
2563
+ const width = parseFloat((_d = nodeVal(get1(lineStyle, "width"))) != null ? _d : "");
2564
+ if (color)
2565
+ properties.stroke = color;
2566
+ if (!isNaN(opacity))
2567
+ properties["stroke-opacity"] = opacity;
2568
+ if (!isNaN(width))
2569
+ properties["stroke-width"] = width;
2570
+ }
2571
+ if (polyStyle) {
2572
+ const polystyles = kmlColor(nodeVal(get1(polyStyle, "color")));
2573
+ const pcolor = polystyles[0];
2574
+ const popacity = polystyles[1];
2575
+ const fill = nodeVal(get1(polyStyle, "fill"));
2576
+ const outline = nodeVal(get1(polyStyle, "outline"));
2577
+ if (pcolor)
2578
+ properties.fill = pcolor;
2579
+ if (!isNaN(popacity))
2580
+ properties["fill-opacity"] = popacity;
2581
+ if (fill)
2582
+ properties["fill-opacity"] = fill === "1" ? properties["fill-opacity"] || 1 : 0;
2583
+ if (outline)
2584
+ properties["stroke-opacity"] = outline === "1" ? properties["stroke-opacity"] || 1 : 0;
2585
+ }
2586
+ if (extendedData) {
2587
+ const datas = get(extendedData, "Data"), simpleDatas = get(extendedData, "SimpleData");
2588
+ for (i = 0; i < datas.length; i++) {
2589
+ properties[(_e = datas[i].getAttribute("name")) != null ? _e : ""] = (_f = nodeVal(get1(datas[i], "value"))) != null ? _f : "";
2590
+ }
2591
+ for (i = 0; i < simpleDatas.length; i++) {
2592
+ properties[(_g = simpleDatas[i].getAttribute("name")) != null ? _g : ""] = (_h = nodeVal(simpleDatas[i])) != null ? _h : "";
2593
+ }
2594
+ }
2595
+ if (visibility !== null) {
2596
+ properties.visibility = (_i = nodeVal(visibility)) != null ? _i : "";
2597
+ }
2598
+ if (geomsAndTimes.coordTimes.length !== 0) {
2599
+ properties.coordTimes = geomsAndTimes.coordTimes.length === 1 ? geomsAndTimes.coordTimes[0] : geomsAndTimes.coordTimes;
2600
+ }
2601
+ const feature = {
2602
+ type: "Feature",
2603
+ geometry: geomsAndTimes.geoms.length === 1 ? geomsAndTimes.geoms[0] : {
2604
+ type: "GeometryCollection",
2605
+ geometries: geomsAndTimes.geoms
2606
+ },
2607
+ properties
2608
+ };
2609
+ if (attr(root, "id"))
2610
+ feature.id = (_j = attr(root, "id")) != null ? _j : void 0;
2611
+ return [feature];
2612
+ }
2613
+ function getPoints(node, pointname) {
2614
+ const pts = get(node, pointname);
2615
+ const line = [];
2616
+ const times = [];
2617
+ let heartRates = [];
2618
+ const ptsLength = pts.length;
2619
+ if (ptsLength < 2)
2620
+ return;
2621
+ for (let i = 0; i < ptsLength; i++) {
2622
+ const cPair = coordPair(pts[i]);
2623
+ line.push(cPair.coordinates);
2624
+ if (cPair.time)
2625
+ times.push(cPair.time);
2626
+ if (cPair.heartRate || heartRates.length) {
2627
+ if (heartRates.length === 0)
2628
+ heartRates = new Array(i).fill(null);
2629
+ heartRates.push(cPair.heartRate);
2630
+ }
2631
+ }
2632
+ return {
2633
+ line,
2634
+ times,
2635
+ heartRates
2636
+ };
2637
+ }
2638
+ function getTrack(node) {
2639
+ const segments = get(node, "trkseg");
2640
+ const track = [];
2641
+ const times = [];
2642
+ const heartRates = [];
2643
+ let line;
2644
+ for (let i = 0; i < segments.length; i++) {
2645
+ line = getPoints(segments[i], "trkpt");
2646
+ if (line !== void 0) {
2647
+ if (line.line)
2648
+ track.push(line.line);
2649
+ if (line.times && line.times.length)
2650
+ times.push(line.times);
2651
+ if (heartRates.length || line.heartRates && line.heartRates.length) {
2652
+ if (!heartRates.length) {
2653
+ for (let s = 0; s < i; s++) {
2654
+ heartRates.push(new Array(track[s].length).fill(null));
2655
+ }
2656
+ }
2657
+ if (line.heartRates && line.heartRates.length) {
2658
+ heartRates.push(line.heartRates);
2659
+ } else {
2660
+ heartRates.push(new Array(line.line.length).fill(null));
2661
+ }
2662
+ }
2663
+ }
2664
+ }
2665
+ if (track.length === 0)
2666
+ return;
2667
+ const properties = __spreadValues$1(__spreadValues$1({}, getProperties(node)), getLineStyle(get1(node, "extensions")));
2668
+ if (times.length !== 0)
2669
+ properties.coordTimes = track.length === 1 ? times[0] : times;
2670
+ if (heartRates.length !== 0) {
2671
+ properties.heartRates = track.length === 1 ? heartRates[0] : heartRates;
2672
+ }
2673
+ if (track.length === 1) {
2674
+ return {
2675
+ type: "Feature",
2676
+ properties,
2677
+ geometry: {
2678
+ type: "LineString",
2679
+ coordinates: track[0]
2680
+ }
2681
+ };
2682
+ } else {
2683
+ return {
2684
+ type: "Feature",
2685
+ properties,
2686
+ geometry: {
2687
+ type: "MultiLineString",
2688
+ coordinates: track
2689
+ }
2690
+ };
2691
+ }
2692
+ }
2693
+ function getRoute(node) {
2694
+ const line = getPoints(node, "rtept");
2695
+ if (line === void 0)
2696
+ return;
2697
+ const prop = __spreadValues$1(__spreadValues$1({}, getProperties(node)), getLineStyle(get1(node, "extensions")));
2698
+ return {
2699
+ type: "Feature",
2700
+ properties: prop,
2701
+ geometry: {
2702
+ type: "LineString",
2703
+ coordinates: line.line
2704
+ }
2705
+ };
2706
+ }
2707
+ function getPoint(node) {
2708
+ const prop = __spreadValues$1(__spreadValues$1({}, getProperties(node)), getMulti(node, ["sym"]));
2709
+ return {
2710
+ type: "Feature",
2711
+ properties: prop,
2712
+ geometry: {
2713
+ type: "Point",
2714
+ coordinates: coordPair(node).coordinates
2715
+ }
2716
+ };
2717
+ }
2718
+ function getLineStyle(extensions) {
2719
+ var _a, _b;
2720
+ const style = {};
2721
+ if (extensions) {
2722
+ const lineStyle = get1(extensions, "line");
2723
+ if (lineStyle) {
2724
+ const color = nodeVal(get1(lineStyle, "color"));
2725
+ const opacity = parseFloat((_a = nodeVal(get1(lineStyle, "opacity"))) != null ? _a : "0");
2726
+ const width = parseFloat((_b = nodeVal(get1(lineStyle, "width"))) != null ? _b : "0");
2727
+ if (color)
2728
+ style.stroke = color;
2729
+ if (!isNaN(opacity))
2730
+ style["stroke-opacity"] = opacity;
2731
+ if (!isNaN(width))
2732
+ style["stroke-width"] = width * 96 / 25.4;
2733
+ }
2734
+ }
2735
+ return style;
2736
+ }
2737
+ function getProperties(node) {
2738
+ const prop = getMulti(node, [
2739
+ "name",
2740
+ "cmt",
2741
+ "desc",
2742
+ "type",
2743
+ "time",
2744
+ "keywords"
2745
+ ]);
2746
+ const links = get(node, "link");
2747
+ if (links.length !== 0) {
2748
+ prop.links = [];
2749
+ for (const l of Array.from(links)) {
2750
+ const link = __spreadValues$1({
2751
+ href: attr(l, "href")
2752
+ }, getMulti(l, ["text", "type"]));
2753
+ prop.links.push(link);
2754
+ }
2755
+ }
2756
+ return prop;
2757
+ }
2758
+ function okhash(x) {
2759
+ let h = 0;
2760
+ if (!x || !x.length)
2761
+ return h;
2762
+ for (let i = 0; i < x.length; i++) {
2763
+ h = (h << 5) - h + x.charCodeAt(i) | 0;
2764
+ }
2765
+ return h;
2766
+ }
2767
+ function get(x, y) {
2768
+ return x.getElementsByTagName(y);
2769
+ }
2770
+ function attr(x, y) {
2771
+ return x.getAttribute(y);
2772
+ }
2773
+ function attrf(x, y) {
2774
+ var _a;
2775
+ return parseFloat((_a = attr(x, y)) != null ? _a : "0");
2776
+ }
2777
+ function get1(x, y) {
2778
+ const n = get(x, y);
2779
+ return n.length ? n[0] : null;
2780
+ }
2781
+ function norm(el) {
2782
+ if (el.normalize)
2783
+ el.normalize();
2784
+ return el;
2785
+ }
2786
+ function numarray(x) {
2787
+ return x.map(parseFloat).map((n) => isNaN(n) ? null : n);
2788
+ }
2789
+ function nodeVal(x) {
2790
+ if (x)
2791
+ norm(x);
2792
+ return x && x.textContent;
2793
+ }
2794
+ function getMulti(x, ys) {
2795
+ var _a;
2796
+ const o = {};
2797
+ let n;
2798
+ let k;
2799
+ for (k = 0; k < ys.length; k++) {
2800
+ n = get1(x, ys[k]);
2801
+ if (n)
2802
+ o[ys[k]] = (_a = nodeVal(n)) != null ? _a : "";
2803
+ }
2804
+ return o;
2805
+ }
2806
+ function coord1(v) {
2807
+ return numarray(v.replace(/\s*/g, "").split(","));
2808
+ }
2809
+ function coord(v) {
2810
+ const coords = v.replace(/^\s*|\s*$/g, "").split(/\s+/);
2811
+ const out = [];
2812
+ for (const coord2 of coords)
2813
+ out.push(coord1(coord2));
2814
+ return out;
2815
+ }
2816
+ function coordPair(x) {
2817
+ var _a, _b;
2818
+ const ll = [attrf(x, "lon"), attrf(x, "lat")];
2819
+ const ele = get1(x, "ele");
2820
+ const heartRate = get1(x, "gpxtpx:hr") || get1(x, "hr");
2821
+ const time = get1(x, "time");
2822
+ let e;
2823
+ if (ele) {
2824
+ e = parseFloat((_a = nodeVal(ele)) != null ? _a : "0");
2825
+ if (!isNaN(e))
2826
+ ll.push(e);
2827
+ }
2828
+ return {
2829
+ coordinates: ll,
2830
+ time: time ? nodeVal(time) : null,
2831
+ heartRate: heartRate !== null ? parseFloat((_b = nodeVal(heartRate)) != null ? _b : "0") : null
2832
+ };
2833
+ }
2834
+ function gpxOrKml(doc) {
2835
+ try {
2836
+ if (typeof doc === "string")
2837
+ doc = str2xml(doc);
2838
+ } catch (e) {
2839
+ return null;
2840
+ }
2841
+ try {
2842
+ const result = gpx(doc);
2843
+ return result;
2844
+ } catch (e) {
2845
+ }
2846
+ try {
2847
+ const result = kml(doc);
2848
+ return result;
2849
+ } catch (e) {
2850
+ }
2851
+ return null;
2852
+ }
2853
+
2854
+ var __defProp$1 = Object.defineProperty;
2855
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2856
+ var __publicField = (obj, key, value) => {
2857
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
2858
+ return value;
2859
+ };
2860
+ function componentToHex(c) {
2861
+ const hex = c.toString(16);
2862
+ return hex.length == 1 ? "0" + hex : hex;
2863
+ }
2864
+ function rgbToHex(rgb) {
2865
+ return "#" + componentToHex(rgb[0]) + componentToHex(rgb[1]) + componentToHex(rgb[2]) + (rgb.length === 4 ? componentToHex(rgb[3]) : "");
2866
+ }
2867
+ class ColorRamp extends Array {
2868
+ constructor(options = {}) {
2869
+ super();
2870
+ __publicField(this, "min", 0);
2871
+ __publicField(this, "max", 1);
2872
+ if ("min" in options) {
2873
+ this.min = options.min;
2874
+ }
2875
+ if ("max" in options) {
2876
+ this.max = options.max;
2877
+ }
2878
+ if ("stops" in options) {
2879
+ this.setStops(options.stops, { clone: false });
2880
+ }
2881
+ }
2882
+ /**
2883
+ * Converts a array-definition color ramp definition into a usable ColorRamp instance.
2884
+ * Note: units are not converted and may need to to be converted beforehand (eg. kelvin to centigrade)
2885
+ * @param cr
2886
+ * @returns
2887
+ */
2888
+ static fromArrayDefinition(cr) {
2889
+ return new ColorRamp({
2890
+ stops: cr.map((cs) => ({
2891
+ value: cs[0],
2892
+ color: cs[1]
2893
+ }))
2894
+ });
2895
+ }
2896
+ setStops(stops, options = { clone: true }) {
2897
+ const colorRamp = options.clone ? this.clone() : this;
2898
+ colorRamp.length = 0;
2899
+ let min = Infinity;
2900
+ let max = -Infinity;
2901
+ for (let i = 0; i < stops.length; i += 1) {
2902
+ min = Math.min(min, stops[i].value);
2903
+ max = Math.max(max, stops[i].value);
2904
+ colorRamp.push({
2905
+ value: stops[i].value,
2906
+ color: stops[i].color.slice()
2907
+ // we want to make sure we do a deep copy and not a reference
2908
+ });
2909
+ }
2910
+ colorRamp.sort(
2911
+ (a, b) => a.value < b.value ? -1 : 1
2912
+ );
2913
+ this.min = min;
2914
+ this.max = max;
2915
+ return colorRamp;
2916
+ }
2917
+ scale(min, max, options = { clone: true }) {
2918
+ const clone = options.clone;
2919
+ const currentMin = this[0].value;
2920
+ const currentMax = this.at(-1).value;
2921
+ const currentSpan = currentMax - currentMin;
2922
+ const newSpan = max - min;
2923
+ const stops = [];
2924
+ for (let i = 0; i < this.length; i += 1) {
2925
+ const currentValue = this[i].value;
2926
+ const normalizedValue = (currentValue - currentMin) / currentSpan;
2927
+ const newValue = normalizedValue * newSpan + min;
2928
+ if (clone) {
2929
+ stops.push({
2930
+ value: newValue,
2931
+ color: this[i].color.slice()
2932
+ });
2933
+ } else {
2934
+ this[i].value = newValue;
2935
+ }
2936
+ }
2937
+ return clone ? new ColorRamp({ stops }) : this;
2938
+ }
2939
+ // for some reason, I had to reimplement this
2940
+ at(pos) {
2941
+ if (pos < 0) {
2942
+ return this[this.length + pos];
2943
+ } else {
2944
+ return this[pos];
2945
+ }
2946
+ }
2947
+ clone() {
2948
+ return new ColorRamp({ stops: this.getRawColorStops() });
2949
+ }
2950
+ getRawColorStops() {
2951
+ const stops = [];
2952
+ for (let i = 0; i < this.length; i += 1) {
2953
+ stops.push({ value: this[i].value, color: this[i].color });
2954
+ }
2955
+ return stops;
2956
+ }
2957
+ reverse(options = { clone: true }) {
2958
+ const colorRamp = options.clone ? this.clone() : this;
2959
+ for (let i = 0; i < ~~(colorRamp.length / 2); i += 1) {
2960
+ const c = colorRamp[i].color;
2961
+ colorRamp[i].color = colorRamp.at(-(i + 1)).color;
2962
+ colorRamp.at(-(i + 1)).color = c;
2963
+ }
2964
+ return colorRamp;
2965
+ }
2966
+ getBounds() {
2967
+ return { min: this.min, max: this.max };
2968
+ }
2969
+ getColor(value, options = { smooth: true }) {
2970
+ if (value <= this[0].value) {
2971
+ return this[0].color;
2972
+ }
2973
+ if (value >= this.at(-1).value) {
2974
+ return this.at(-1).color;
2975
+ }
2976
+ for (let i = 0; i < this.length - 1; i += 1) {
2977
+ if (value > this[i + 1].value) {
2978
+ continue;
2979
+ }
2980
+ const colorBefore = this[i].color;
2981
+ if (!options.smooth) {
2982
+ return colorBefore.slice();
2983
+ }
2984
+ const valueBefore = this[i].value;
2985
+ const valueAfter = this[i + 1].value;
2986
+ const colorAfter = this[i + 1].color;
2987
+ const beforeRatio = (valueAfter - value) / (valueAfter - valueBefore);
2988
+ return colorBefore.map(
2989
+ (chan, i2) => Math.round(chan * beforeRatio + colorAfter[i2] * (1 - beforeRatio))
2990
+ );
2991
+ }
2992
+ return [0, 0, 0];
2993
+ }
2994
+ /**
2995
+ * Get the color as an hexadecimal string
2996
+ */
2997
+ getColorHex(value, options = {
2998
+ smooth: true,
2999
+ withAlpha: false
3000
+ }) {
3001
+ return rgbToHex(this.getColor(value, options));
3002
+ }
3003
+ /**
3004
+ * Get the color of the color ramp at a relative position in [0, 1]
3005
+ */
3006
+ getColorRelative(value, options = { smooth: true }) {
3007
+ const bounds = this.getBounds();
3008
+ return this.getColor(
3009
+ bounds.min + value * (bounds.max - bounds.min),
3010
+ options
3011
+ );
3012
+ }
3013
+ getCanvasStrip(options = {
3014
+ horizontal: true,
3015
+ size: 512,
3016
+ smooth: true
3017
+ }) {
3018
+ const canvas = document.createElement("canvas");
3019
+ canvas.width = options.horizontal ? options.size : 1;
3020
+ canvas.height = options.horizontal ? 1 : options.size;
3021
+ const ctx = canvas.getContext("2d");
3022
+ if (!ctx)
3023
+ throw new Error("Canvs context is missing");
3024
+ const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
3025
+ const imageDataArray = imageData.data;
3026
+ const size = options.size;
3027
+ const startValue = this[0].value;
3028
+ const endValue = this.at(-1).value;
3029
+ const valueSpan = endValue - startValue;
3030
+ const valueStep = valueSpan / size;
3031
+ for (let i = 0; i < size; i += 1) {
3032
+ const color = this.getColor(startValue + i * valueStep, {
3033
+ smooth: options.smooth
3034
+ });
3035
+ imageDataArray[i * 4] = color[0];
3036
+ imageDataArray[i * 4 + 1] = color[1];
3037
+ imageDataArray[i * 4 + 2] = color[2];
3038
+ imageDataArray[i * 4 + 3] = color.length > 3 ? color[3] : 255;
3039
+ }
3040
+ ctx.putImageData(imageData, 0, 0);
3041
+ return canvas;
3042
+ }
3043
+ /**
3044
+ * Apply a non-linear ressampling. This will create a new instance of ColorRamp with the same bounds.
3045
+ */
3046
+ resample(method, samples = 15) {
3047
+ const inputBounds = this.getBounds();
3048
+ const inputNormalized = this.scale(0, 1);
3049
+ const step = 1 / (samples - 1);
3050
+ let stops;
3051
+ if (method === "ease-in-square") {
3052
+ stops = Array.from({ length: samples }, (_, i) => {
3053
+ const x = i * step;
3054
+ const y = Math.pow(x, 2);
3055
+ const color = inputNormalized.getColor(y);
3056
+ return { value: x, color };
3057
+ });
3058
+ } else if (method === "ease-out-square") {
3059
+ stops = Array.from({ length: samples }, (_, i) => {
3060
+ const x = i * step;
3061
+ const y = 1 - Math.pow(1 - x, 2);
3062
+ const color = inputNormalized.getColor(y);
3063
+ return { value: x, color };
3064
+ });
3065
+ } else if (method === "ease-out-sqrt") {
3066
+ stops = Array.from({ length: samples }, (_, i) => {
3067
+ const x = i * step;
3068
+ const y = Math.pow(x, 0.5);
3069
+ const color = inputNormalized.getColor(y);
3070
+ return { value: x, color };
3071
+ });
3072
+ } else if (method === "ease-in-sqrt") {
3073
+ stops = Array.from({ length: samples }, (_, i) => {
3074
+ const x = i * step;
3075
+ const y = 1 - Math.pow(1 - x, 0.5);
3076
+ const color = inputNormalized.getColor(y);
3077
+ return { value: x, color };
3078
+ });
3079
+ } else if (method === "ease-out-exp") {
3080
+ stops = Array.from({ length: samples }, (_, i) => {
3081
+ const x = i * step;
3082
+ const y = 1 - Math.pow(2, -10 * x);
3083
+ const color = inputNormalized.getColor(y);
3084
+ return { value: x, color };
3085
+ });
3086
+ } else if (method === "ease-in-exp") {
3087
+ stops = Array.from({ length: samples }, (_, i) => {
3088
+ const x = i * step;
3089
+ const y = Math.pow(2, 10 * x - 10);
3090
+ const color = inputNormalized.getColor(y);
3091
+ return { value: x, color };
3092
+ });
3093
+ } else {
3094
+ throw new Error("Invalid ressampling method.");
3095
+ }
3096
+ const outputNormalized = new ColorRamp({ stops });
3097
+ const output = outputNormalized.scale(inputBounds.min, inputBounds.max);
3098
+ return output;
3099
+ }
3100
+ /**
3101
+ * Makes a clone of this color ramp that is fully transparant at the begining of their range
3102
+ */
3103
+ transparentStart() {
3104
+ const stops = this.getRawColorStops();
3105
+ stops.unshift({
3106
+ value: stops[0].value,
3107
+ color: stops[0].color.slice()
3108
+ });
3109
+ stops[1].value += 1e-3;
3110
+ stops.forEach((s) => {
3111
+ if (s.color.length === 3) {
3112
+ s.color.push(255);
3113
+ }
3114
+ });
3115
+ stops[0].color[3] = 0;
3116
+ return new ColorRamp({ stops });
3117
+ }
3118
+ /**
3119
+ * Check if this color ramp has a transparent start
3120
+ */
3121
+ hasTransparentStart() {
3122
+ return this[0].color.length === 4 && this[0].color[3] === 0;
3123
+ }
3124
+ }
3125
+ const ColorRampCollection = {
3126
+ /**
3127
+ * A fully transparent [0, 0, 0, 0] colorramp to hide data.
3128
+ * Defined in interval [0, 1], without unit.
3129
+ */
3130
+ NULL: new ColorRamp({
3131
+ stops: [
3132
+ { value: 0, color: [0, 0, 0, 0] },
3133
+ { value: 1, color: [0, 0, 0, 0] }
3134
+ ]
3135
+ }),
3136
+ GRAY: new ColorRamp({
3137
+ stops: [
3138
+ { value: 0, color: [0, 0, 0] },
3139
+ { value: 1, color: [255, 255, 255] }
3140
+ ]
3141
+ }),
3142
+ /**
3143
+ * Classic jet color ramp.
3144
+ * Defined in interval [0, 1], without unit.
3145
+ */
3146
+ JET: new ColorRamp({
3147
+ stops: [
3148
+ { value: 0, color: [0, 0, 131] },
3149
+ { value: 0.125, color: [0, 60, 170] },
3150
+ { value: 0.375, color: [5, 255, 255] },
3151
+ { value: 0.625, color: [255, 255, 0] },
3152
+ { value: 0.875, color: [250, 0, 0] },
3153
+ { value: 1, color: [128, 0, 0] }
3154
+ ]
3155
+ }),
3156
+ /**
3157
+ * Classic HSV color ramp (hue, saturation, value).
3158
+ * Defined in interval [0, 1], without unit.
3159
+ */
3160
+ HSV: new ColorRamp({
3161
+ stops: [
3162
+ { value: 0, color: [255, 0, 0] },
3163
+ { value: 0.169, color: [253, 255, 2] },
3164
+ { value: 0.173, color: [247, 255, 2] },
3165
+ { value: 0.337, color: [0, 252, 4] },
3166
+ { value: 0.341, color: [0, 252, 10] },
3167
+ { value: 0.506, color: [1, 249, 255] },
3168
+ { value: 0.671, color: [2, 0, 253] },
3169
+ { value: 0.675, color: [8, 0, 253] },
3170
+ { value: 0.839, color: [255, 0, 251] },
3171
+ { value: 0.843, color: [255, 0, 245] },
3172
+ { value: 1, color: [255, 0, 6] }
3173
+ ]
3174
+ }),
3175
+ /**
3176
+ * Classic hot color ramp.
3177
+ * Defined in interval [0, 1], without unit.
3178
+ */
3179
+ HOT: new ColorRamp({
3180
+ stops: [
3181
+ { value: 0, color: [0, 0, 0] },
3182
+ { value: 0.3, color: [230, 0, 0] },
3183
+ { value: 0.6, color: [255, 210, 0] },
3184
+ { value: 1, color: [255, 255, 255] }
3185
+ ]
3186
+ }),
3187
+ /**
3188
+ * Classic spring color ramp.
3189
+ * Defined in interval [0, 1], without unit.
3190
+ */
3191
+ SPRING: new ColorRamp({
3192
+ stops: [
3193
+ { value: 0, color: [255, 0, 255] },
3194
+ { value: 1, color: [255, 255, 0] }
3195
+ ]
3196
+ }),
3197
+ /**
3198
+ * Classic summer color ramp.
3199
+ * Defined in interval [0, 1], without unit.
3200
+ */
3201
+ SUMMER: new ColorRamp({
3202
+ stops: [
3203
+ { value: 0, color: [0, 128, 102] },
3204
+ { value: 1, color: [255, 255, 102] }
3205
+ ]
3206
+ }),
3207
+ /**
3208
+ * Classic autommn color ramp.
3209
+ * Defined in interval [0, 1], without unit.
3210
+ */
3211
+ AUTOMN: new ColorRamp({
3212
+ stops: [
3213
+ { value: 0, color: [255, 0, 0] },
3214
+ { value: 1, color: [255, 255, 0] }
3215
+ ]
3216
+ }),
3217
+ /**
3218
+ * Classic winter color ramp.
3219
+ * Defined in interval [0, 1], without unit.
3220
+ */
3221
+ WINTER: new ColorRamp({
3222
+ stops: [
3223
+ { value: 0, color: [0, 0, 255] },
3224
+ { value: 1, color: [0, 255, 128] }
3225
+ ]
3226
+ }),
3227
+ /**
3228
+ * Classic bone color ramp.
3229
+ * Defined in interval [0, 1], without unit.
3230
+ */
3231
+ BONE: new ColorRamp({
3232
+ stops: [
3233
+ { value: 0, color: [0, 0, 0] },
3234
+ { value: 0.376, color: [84, 84, 116] },
3235
+ { value: 0.753, color: [169, 200, 200] },
3236
+ { value: 1, color: [255, 255, 255] }
3237
+ ]
3238
+ }),
3239
+ /**
3240
+ * Classic copper color ramp.
3241
+ * Defined in interval [0, 1], without unit.
3242
+ */
3243
+ COPPER: new ColorRamp({
3244
+ stops: [
3245
+ { value: 0, color: [0, 0, 0] },
3246
+ { value: 0.804, color: [255, 160, 102] },
3247
+ { value: 1, color: [255, 199, 127] }
3248
+ ]
3249
+ }),
3250
+ /**
3251
+ * Classic greys color ramp.
3252
+ * Defined in interval [0, 1], without unit.
3253
+ */
3254
+ GREYS: new ColorRamp({
3255
+ stops: [
3256
+ { value: 0, color: [0, 0, 0] },
3257
+ { value: 1, color: [255, 255, 255] }
3258
+ ]
3259
+ }),
3260
+ /**
3261
+ * Classic yignbu color ramp (blue to light yellow).
3262
+ * Defined in interval [0, 1], without unit.
3263
+ */
3264
+ YIGNBU: new ColorRamp({
3265
+ stops: [
3266
+ { value: 0, color: [8, 29, 88] },
3267
+ { value: 0.125, color: [37, 52, 148] },
3268
+ { value: 0.25, color: [34, 94, 168] },
3269
+ { value: 0.375, color: [29, 145, 192] },
3270
+ { value: 0.5, color: [65, 182, 196] },
3271
+ { value: 0.625, color: [127, 205, 187] },
3272
+ { value: 0.75, color: [199, 233, 180] },
3273
+ { value: 0.875, color: [237, 248, 217] },
3274
+ { value: 1, color: [255, 255, 217] }
3275
+ ]
3276
+ }),
3277
+ /**
3278
+ * Classic greens color ramp.
3279
+ * Defined in interval [0, 1], without unit.
3280
+ */
3281
+ GREENS: new ColorRamp({
3282
+ stops: [
3283
+ { value: 0, color: [0, 68, 27] },
3284
+ { value: 0.125, color: [0, 109, 44] },
3285
+ { value: 0.25, color: [35, 139, 69] },
3286
+ { value: 0.375, color: [65, 171, 93] },
3287
+ { value: 0.5, color: [116, 196, 118] },
3288
+ { value: 0.625, color: [161, 217, 155] },
3289
+ { value: 0.75, color: [199, 233, 192] },
3290
+ { value: 0.875, color: [229, 245, 224] },
3291
+ { value: 1, color: [247, 252, 245] }
3292
+ ]
3293
+ }),
3294
+ /**
3295
+ * Classic yiorrd color ramp (red to light yellow).
3296
+ * Defined in interval [0, 1], without unit.
3297
+ */
3298
+ YIORRD: new ColorRamp({
3299
+ stops: [
3300
+ { value: 0, color: [128, 0, 38] },
3301
+ { value: 0.125, color: [189, 0, 38] },
3302
+ { value: 0.25, color: [227, 26, 28] },
3303
+ { value: 0.375, color: [252, 78, 42] },
3304
+ { value: 0.5, color: [253, 141, 60] },
3305
+ { value: 0.625, color: [254, 178, 76] },
3306
+ { value: 0.75, color: [254, 217, 118] },
3307
+ { value: 0.875, color: [255, 237, 160] },
3308
+ { value: 1, color: [255, 255, 204] }
3309
+ ]
3310
+ }),
3311
+ /**
3312
+ * Classic blue-red color ramp.
3313
+ * Defined in interval [0, 1], without unit.
3314
+ */
3315
+ BLUERED: new ColorRamp({
3316
+ stops: [
3317
+ { value: 0, color: [0, 0, 255] },
3318
+ { value: 1, color: [255, 0, 0] }
3319
+ ]
3320
+ }),
3321
+ /**
3322
+ * Classic rdbu color ramp.
3323
+ * Defined in interval [0, 1], without unit.
3324
+ */
3325
+ RDBU: new ColorRamp({
3326
+ stops: [
3327
+ { value: 0, color: [5, 10, 172] },
3328
+ { value: 0.35, color: [106, 137, 247] },
3329
+ { value: 0.5, color: [190, 190, 190] },
3330
+ { value: 0.6, color: [220, 170, 132] },
3331
+ { value: 0.7, color: [230, 145, 90] },
3332
+ { value: 1, color: [178, 10, 28] }
3333
+ ]
3334
+ }),
3335
+ /**
3336
+ * Classic picnic color ramp.
3337
+ * Defined in interval [0, 1], without unit.
3338
+ */
3339
+ PICNIC: new ColorRamp({
3340
+ stops: [
3341
+ { value: 0, color: [0, 0, 255] },
3342
+ { value: 0.1, color: [51, 153, 255] },
3343
+ { value: 0.2, color: [102, 204, 255] },
3344
+ { value: 0.3, color: [153, 204, 255] },
3345
+ { value: 0.4, color: [204, 204, 255] },
3346
+ { value: 0.5, color: [255, 255, 255] },
3347
+ { value: 0.6, color: [255, 204, 255] },
3348
+ { value: 0.7, color: [255, 153, 255] },
3349
+ { value: 0.8, color: [255, 102, 204] },
3350
+ { value: 0.9, color: [255, 102, 102] },
3351
+ { value: 1, color: [255, 0, 0] }
3352
+ ]
3353
+ }),
3354
+ /**
3355
+ * Classic rainbow color ramp.
3356
+ * Defined in interval [0, 1], without unit.
3357
+ */
3358
+ RAINBOW: new ColorRamp({
3359
+ stops: [
3360
+ { value: 0, color: [150, 0, 90] },
3361
+ { value: 0.125, color: [0, 0, 200] },
3362
+ { value: 0.25, color: [0, 25, 255] },
3363
+ { value: 0.375, color: [0, 152, 255] },
3364
+ { value: 0.5, color: [44, 255, 150] },
3365
+ { value: 0.625, color: [151, 255, 0] },
3366
+ { value: 0.75, color: [255, 234, 0] },
3367
+ { value: 0.875, color: [255, 111, 0] },
3368
+ { value: 1, color: [255, 0, 0] }
3369
+ ]
3370
+ }),
3371
+ /**
3372
+ * Classic Portland color ramp.
3373
+ * Defined in interval [0, 1], without unit.
3374
+ */
3375
+ PORTLAND: new ColorRamp({
3376
+ stops: [
3377
+ { value: 0, color: [12, 51, 131] },
3378
+ { value: 0.25, color: [10, 136, 186] },
3379
+ { value: 0.5, color: [242, 211, 56] },
3380
+ { value: 0.75, color: [242, 143, 56] },
3381
+ { value: 1, color: [217, 30, 30] }
3382
+ ]
3383
+ }),
3384
+ /**
3385
+ * Classic blackbody color ramp.
3386
+ * Defined in interval [0, 1], without unit.
3387
+ */
3388
+ BLACKBODY: new ColorRamp({
3389
+ stops: [
3390
+ { value: 0, color: [0, 0, 0] },
3391
+ { value: 0.2, color: [230, 0, 0] },
3392
+ { value: 0.4, color: [230, 210, 0] },
3393
+ { value: 0.7, color: [255, 255, 255] },
3394
+ { value: 1, color: [160, 200, 255] }
3395
+ ]
3396
+ }),
3397
+ /**
3398
+ * Classic earth color ramp.
3399
+ * Defined in interval [0, 1], without unit.
3400
+ */
3401
+ EARTH: new ColorRamp({
3402
+ stops: [
3403
+ { value: 0, color: [0, 0, 130] },
3404
+ { value: 0.1, color: [0, 180, 180] },
3405
+ { value: 0.2, color: [40, 210, 40] },
3406
+ { value: 0.4, color: [230, 230, 50] },
3407
+ { value: 0.6, color: [120, 70, 20] },
3408
+ { value: 1, color: [255, 255, 255] }
3409
+ ]
3410
+ }),
3411
+ /**
3412
+ * Classic electric color ramp.
3413
+ * Defined in interval [0, 1], without unit.
3414
+ */
3415
+ ELECTRIC: new ColorRamp({
3416
+ stops: [
3417
+ { value: 0, color: [0, 0, 0] },
3418
+ { value: 0.15, color: [30, 0, 100] },
3419
+ { value: 0.4, color: [120, 0, 100] },
3420
+ { value: 0.6, color: [160, 90, 0] },
3421
+ { value: 0.8, color: [230, 200, 0] },
3422
+ { value: 1, color: [255, 250, 220] }
3423
+ ]
3424
+ }),
3425
+ /**
3426
+ * Classic viridis color ramp.
3427
+ * Defined in interval [0, 1], without unit.
3428
+ */
3429
+ VIRIDIS: new ColorRamp({
3430
+ stops: [
3431
+ { value: 0, color: [68, 1, 84] },
3432
+ { value: 0.13, color: [71, 44, 122] },
3433
+ { value: 0.25, color: [59, 81, 139] },
3434
+ { value: 0.38, color: [44, 113, 142] },
3435
+ { value: 0.5, color: [33, 144, 141] },
3436
+ { value: 0.63, color: [39, 173, 129] },
3437
+ { value: 0.75, color: [92, 200, 99] },
3438
+ { value: 0.88, color: [170, 220, 50] },
3439
+ { value: 1, color: [253, 231, 37] }
3440
+ ]
3441
+ }),
3442
+ /**
3443
+ * Classic inferno color ramp.
3444
+ * Defined in interval [0, 1], without unit.
3445
+ */
3446
+ INFERNO: new ColorRamp({
3447
+ stops: [
3448
+ { value: 0, color: [0, 0, 4] },
3449
+ { value: 0.13, color: [31, 12, 72] },
3450
+ { value: 0.25, color: [85, 15, 109] },
3451
+ { value: 0.38, color: [136, 34, 106] },
3452
+ { value: 0.5, color: [186, 54, 85] },
3453
+ { value: 0.63, color: [227, 89, 51] },
3454
+ { value: 0.75, color: [249, 140, 10] },
3455
+ { value: 0.88, color: [249, 201, 50] },
3456
+ { value: 1, color: [252, 255, 164] }
3457
+ ]
3458
+ }),
3459
+ /**
3460
+ * Classic magma color ramp.
3461
+ * Defined in interval [0, 1], without unit.
3462
+ */
3463
+ MAGMA: new ColorRamp({
3464
+ stops: [
3465
+ { value: 0, color: [0, 0, 4] },
3466
+ { value: 0.13, color: [28, 16, 68] },
3467
+ { value: 0.25, color: [79, 18, 123] },
3468
+ { value: 0.38, color: [129, 37, 129] },
3469
+ { value: 0.5, color: [181, 54, 122] },
3470
+ { value: 0.63, color: [229, 80, 100] },
3471
+ { value: 0.75, color: [251, 135, 97] },
3472
+ { value: 0.88, color: [254, 194, 135] },
3473
+ { value: 1, color: [252, 253, 191] }
3474
+ ]
3475
+ }),
3476
+ /**
3477
+ * Classic plasma color ramp.
3478
+ * Defined in interval [0, 1], without unit.
3479
+ */
3480
+ PLASMA: new ColorRamp({
3481
+ stops: [
3482
+ { value: 0, color: [13, 8, 135] },
3483
+ { value: 0.13, color: [75, 3, 161] },
3484
+ { value: 0.25, color: [125, 3, 168] },
3485
+ { value: 0.38, color: [168, 34, 150] },
3486
+ { value: 0.5, color: [203, 70, 121] },
3487
+ { value: 0.63, color: [229, 107, 93] },
3488
+ { value: 0.75, color: [248, 148, 65] },
3489
+ { value: 0.88, color: [253, 195, 40] },
3490
+ { value: 1, color: [240, 249, 33] }
3491
+ ]
3492
+ }),
3493
+ /**
3494
+ * Classic warm color ramp.
3495
+ * Defined in interval [0, 1], without unit.
3496
+ */
3497
+ WARM: new ColorRamp({
3498
+ stops: [
3499
+ { value: 0, color: [125, 0, 179] },
3500
+ { value: 0.13, color: [172, 0, 187] },
3501
+ { value: 0.25, color: [219, 0, 170] },
3502
+ { value: 0.38, color: [255, 0, 130] },
3503
+ { value: 0.5, color: [255, 63, 74] },
3504
+ { value: 0.63, color: [255, 123, 0] },
3505
+ { value: 0.75, color: [234, 176, 0] },
3506
+ { value: 0.88, color: [190, 228, 0] },
3507
+ { value: 1, color: [147, 255, 0] }
3508
+ ]
3509
+ }),
3510
+ /**
3511
+ * Classic cool color ramp.
3512
+ * Defined in interval [0, 1], without unit.
3513
+ */
3514
+ COOL: new ColorRamp({
3515
+ stops: [
3516
+ { value: 0, color: [125, 0, 179] },
3517
+ { value: 0.13, color: [116, 0, 218] },
3518
+ { value: 0.25, color: [98, 74, 237] },
3519
+ { value: 0.38, color: [68, 146, 231] },
3520
+ { value: 0.5, color: [0, 204, 197] },
3521
+ { value: 0.63, color: [0, 247, 146] },
3522
+ { value: 0.75, color: [0, 255, 88] },
3523
+ { value: 0.88, color: [40, 255, 8] },
3524
+ { value: 1, color: [147, 255, 0] }
3525
+ ]
3526
+ }),
3527
+ /**
3528
+ * Classic rainboz soft color ramp.
3529
+ * Defined in interval [0, 1], without unit.
3530
+ */
3531
+ RAINBOW_SOFT: new ColorRamp({
3532
+ stops: [
3533
+ { value: 0, color: [125, 0, 179] },
3534
+ { value: 0.1, color: [199, 0, 180] },
3535
+ { value: 0.2, color: [255, 0, 121] },
3536
+ { value: 0.3, color: [255, 108, 0] },
3537
+ { value: 0.4, color: [222, 194, 0] },
3538
+ { value: 0.5, color: [150, 255, 0] },
3539
+ { value: 0.6, color: [0, 255, 55] },
3540
+ { value: 0.7, color: [0, 246, 150] },
3541
+ { value: 0.8, color: [50, 167, 222] },
3542
+ { value: 0.9, color: [103, 51, 235] },
3543
+ { value: 1, color: [124, 0, 186] }
3544
+ ]
3545
+ }),
3546
+ /**
3547
+ * Classic bathymetry color ramp.
3548
+ * Defined in interval [0, 1], without unit.
3549
+ */
3550
+ BATHYMETRY: new ColorRamp({
3551
+ stops: [
3552
+ { value: 0, color: [40, 26, 44] },
3553
+ { value: 0.13, color: [59, 49, 90] },
3554
+ { value: 0.25, color: [64, 76, 139] },
3555
+ { value: 0.38, color: [63, 110, 151] },
3556
+ { value: 0.5, color: [72, 142, 158] },
3557
+ { value: 0.63, color: [85, 174, 163] },
3558
+ { value: 0.75, color: [120, 206, 163] },
3559
+ { value: 0.88, color: [187, 230, 172] },
3560
+ { value: 1, color: [253, 254, 204] }
3561
+ ]
3562
+ }),
3563
+ /**
3564
+ * Classic cdom color ramp.
3565
+ * Defined in interval [0, 1], without unit.
3566
+ */
3567
+ CDOM: new ColorRamp({
3568
+ stops: [
3569
+ { value: 0, color: [47, 15, 62] },
3570
+ { value: 0.13, color: [87, 23, 86] },
3571
+ { value: 0.25, color: [130, 28, 99] },
3572
+ { value: 0.38, color: [171, 41, 96] },
3573
+ { value: 0.5, color: [206, 67, 86] },
3574
+ { value: 0.63, color: [230, 106, 84] },
3575
+ { value: 0.75, color: [242, 149, 103] },
3576
+ { value: 0.88, color: [249, 193, 135] },
3577
+ { value: 1, color: [254, 237, 176] }
3578
+ ]
3579
+ }),
3580
+ /**
3581
+ * Classic chlorophyll color ramp.
3582
+ * Defined in interval [0, 1], without unit.
3583
+ */
3584
+ CHLOROPHYLL: new ColorRamp({
3585
+ stops: [
3586
+ { value: 0, color: [18, 36, 20] },
3587
+ { value: 0.13, color: [25, 63, 41] },
3588
+ { value: 0.25, color: [24, 91, 59] },
3589
+ { value: 0.38, color: [13, 119, 72] },
3590
+ { value: 0.5, color: [18, 148, 80] },
3591
+ { value: 0.63, color: [80, 173, 89] },
3592
+ { value: 0.75, color: [132, 196, 122] },
3593
+ { value: 0.88, color: [175, 221, 162] },
3594
+ { value: 1, color: [215, 249, 208] }
3595
+ ]
3596
+ }),
3597
+ /**
3598
+ * Classic density color ramp.
3599
+ * Defined in interval [0, 1], without unit.
3600
+ */
3601
+ DENSITY: new ColorRamp({
3602
+ stops: [
3603
+ { value: 0, color: [54, 14, 36] },
3604
+ { value: 0.13, color: [89, 23, 80] },
3605
+ { value: 0.25, color: [110, 45, 132] },
3606
+ { value: 0.38, color: [120, 77, 178] },
3607
+ { value: 0.5, color: [120, 113, 213] },
3608
+ { value: 0.63, color: [115, 151, 228] },
3609
+ { value: 0.75, color: [134, 185, 227] },
3610
+ { value: 0.88, color: [177, 214, 227] },
3611
+ { value: 1, color: [230, 241, 241] }
3612
+ ]
3613
+ }),
3614
+ /**
3615
+ * Classic freesurface blue color ramp.
3616
+ * Defined in interval [0, 1], without unit.
3617
+ */
3618
+ FREESURFACE_BLUE: new ColorRamp({
3619
+ stops: [
3620
+ { value: 0, color: [30, 4, 110] },
3621
+ { value: 0.13, color: [47, 14, 176] },
3622
+ { value: 0.25, color: [41, 45, 236] },
3623
+ { value: 0.38, color: [25, 99, 212] },
3624
+ { value: 0.5, color: [68, 131, 200] },
3625
+ { value: 0.63, color: [114, 156, 197] },
3626
+ { value: 0.75, color: [157, 181, 203] },
3627
+ { value: 0.88, color: [200, 208, 216] },
3628
+ { value: 1, color: [241, 237, 236] }
3629
+ ]
3630
+ }),
3631
+ /**
3632
+ * Classic freesurface red color ramp.
3633
+ * Defined in interval [0, 1], without unit.
3634
+ */
3635
+ FREESURFACE_RED: new ColorRamp({
3636
+ stops: [
3637
+ { value: 0, color: [60, 9, 18] },
3638
+ { value: 0.13, color: [100, 17, 27] },
3639
+ { value: 0.25, color: [142, 20, 29] },
3640
+ { value: 0.38, color: [177, 43, 27] },
3641
+ { value: 0.5, color: [192, 87, 63] },
3642
+ { value: 0.63, color: [205, 125, 105] },
3643
+ { value: 0.75, color: [216, 162, 148] },
3644
+ { value: 0.88, color: [227, 199, 193] },
3645
+ { value: 1, color: [241, 237, 236] }
3646
+ ]
3647
+ }),
3648
+ /**
3649
+ * Classic oxygen color ramp.
3650
+ * Defined in interval [0, 1], without unit.
3651
+ */
3652
+ OXYGEN: new ColorRamp({
3653
+ stops: [
3654
+ { value: 0, color: [64, 5, 5] },
3655
+ { value: 0.13, color: [106, 6, 15] },
3656
+ { value: 0.25, color: [144, 26, 7] },
3657
+ { value: 0.38, color: [168, 64, 3] },
3658
+ { value: 0.5, color: [188, 100, 4] },
3659
+ { value: 0.63, color: [206, 136, 11] },
3660
+ { value: 0.75, color: [220, 174, 25] },
3661
+ { value: 0.88, color: [231, 215, 44] },
3662
+ { value: 1, color: [248, 254, 105] }
3663
+ ]
3664
+ }),
3665
+ /**
3666
+ * Classic par color ramp.
3667
+ * Defined in interval [0, 1], without unit.
3668
+ */
3669
+ PAR: new ColorRamp({
3670
+ stops: [
3671
+ { value: 0, color: [51, 20, 24] },
3672
+ { value: 0.13, color: [90, 32, 35] },
3673
+ { value: 0.25, color: [129, 44, 34] },
3674
+ { value: 0.38, color: [159, 68, 25] },
3675
+ { value: 0.5, color: [182, 99, 19] },
3676
+ { value: 0.63, color: [199, 134, 22] },
3677
+ { value: 0.75, color: [212, 171, 35] },
3678
+ { value: 0.88, color: [221, 210, 54] },
3679
+ { value: 1, color: [225, 253, 75] }
3680
+ ]
3681
+ }),
3682
+ /**
3683
+ * Classic phase color ramp.
3684
+ * Defined in interval [0, 1], without unit.
3685
+ */
3686
+ PHASE: new ColorRamp({
3687
+ stops: [
3688
+ { value: 0, color: [145, 105, 18] },
3689
+ { value: 0.13, color: [184, 71, 38] },
3690
+ { value: 0.25, color: [186, 58, 115] },
3691
+ { value: 0.38, color: [160, 71, 185] },
3692
+ { value: 0.5, color: [110, 97, 218] },
3693
+ { value: 0.63, color: [50, 123, 164] },
3694
+ { value: 0.75, color: [31, 131, 110] },
3695
+ { value: 0.88, color: [77, 129, 34] },
3696
+ { value: 1, color: [145, 105, 18] }
3697
+ ]
3698
+ }),
3699
+ /**
3700
+ * Classic salinity color ramp.
3701
+ * Defined in interval [0, 1], without unit.
3702
+ */
3703
+ SALINITY: new ColorRamp({
3704
+ stops: [
3705
+ { value: 0, color: [42, 24, 108] },
3706
+ { value: 0.13, color: [33, 50, 162] },
3707
+ { value: 0.25, color: [15, 90, 145] },
3708
+ { value: 0.38, color: [40, 118, 137] },
3709
+ { value: 0.5, color: [59, 146, 135] },
3710
+ { value: 0.63, color: [79, 175, 126] },
3711
+ { value: 0.75, color: [120, 203, 104] },
3712
+ { value: 0.88, color: [193, 221, 100] },
3713
+ { value: 1, color: [253, 239, 154] }
3714
+ ]
3715
+ }),
3716
+ /**
3717
+ * Classic temperature color ramp.
3718
+ * Defined in interval [0, 1], without unit.
3719
+ */
3720
+ TEMPERATURE: new ColorRamp({
3721
+ stops: [
3722
+ { value: 0, color: [4, 35, 51] },
3723
+ { value: 0.13, color: [23, 51, 122] },
3724
+ { value: 0.25, color: [85, 59, 157] },
3725
+ { value: 0.38, color: [129, 79, 143] },
3726
+ { value: 0.5, color: [175, 95, 130] },
3727
+ { value: 0.63, color: [222, 112, 101] },
3728
+ { value: 0.75, color: [249, 146, 66] },
3729
+ { value: 0.88, color: [249, 196, 65] },
3730
+ { value: 1, color: [232, 250, 91] }
3731
+ ]
3732
+ }),
3733
+ /**
3734
+ * Classic turbidity color ramp.
3735
+ * Defined in interval [0, 1], without unit.
3736
+ */
3737
+ TURBIDITY: new ColorRamp({
3738
+ stops: [
3739
+ { value: 0, color: [34, 31, 27] },
3740
+ { value: 0.13, color: [65, 50, 41] },
3741
+ { value: 0.25, color: [98, 69, 52] },
3742
+ { value: 0.38, color: [131, 89, 57] },
3743
+ { value: 0.5, color: [161, 112, 59] },
3744
+ { value: 0.63, color: [185, 140, 66] },
3745
+ { value: 0.75, color: [202, 174, 88] },
3746
+ { value: 0.88, color: [216, 209, 126] },
3747
+ { value: 1, color: [233, 246, 171] }
3748
+ ]
3749
+ }),
3750
+ /**
3751
+ * Classic velocity blue color ramp.
3752
+ * Defined in interval [0, 1], without unit.
3753
+ */
3754
+ VELOCITY_BLUE: new ColorRamp({
3755
+ stops: [
3756
+ { value: 0, color: [17, 32, 64] },
3757
+ { value: 0.13, color: [35, 52, 116] },
3758
+ { value: 0.25, color: [29, 81, 156] },
3759
+ { value: 0.38, color: [31, 113, 162] },
3760
+ { value: 0.5, color: [50, 144, 169] },
3761
+ { value: 0.63, color: [87, 173, 176] },
3762
+ { value: 0.75, color: [149, 196, 189] },
3763
+ { value: 0.88, color: [203, 221, 211] },
3764
+ { value: 1, color: [254, 251, 230] }
3765
+ ]
3766
+ }),
3767
+ /**
3768
+ * Classic velocity green color ramp.
3769
+ * Defined in interval [0, 1], without unit.
3770
+ */
3771
+ VELOCITY_GREEN: new ColorRamp({
3772
+ stops: [
3773
+ { value: 0, color: [23, 35, 19] },
3774
+ { value: 0.13, color: [24, 64, 38] },
3775
+ { value: 0.25, color: [11, 95, 45] },
3776
+ { value: 0.38, color: [39, 123, 35] },
3777
+ { value: 0.5, color: [95, 146, 12] },
3778
+ { value: 0.63, color: [152, 165, 18] },
3779
+ { value: 0.75, color: [201, 186, 69] },
3780
+ { value: 0.88, color: [233, 216, 137] },
3781
+ { value: 1, color: [255, 253, 205] }
3782
+ ]
3783
+ }),
3784
+ /**
3785
+ * Classic cube helix color ramp.
3786
+ * Defined in interval [0, 1], without unit.
3787
+ */
3788
+ CUBEHELIX: new ColorRamp({
3789
+ stops: [
3790
+ { value: 0, color: [0, 0, 0] },
3791
+ { value: 0.07, color: [22, 5, 59] },
3792
+ { value: 0.13, color: [60, 4, 105] },
3793
+ { value: 0.2, color: [109, 1, 135] },
3794
+ { value: 0.27, color: [161, 0, 147] },
3795
+ { value: 0.33, color: [210, 2, 142] },
3796
+ { value: 0.4, color: [251, 11, 123] },
3797
+ { value: 0.47, color: [255, 29, 97] },
3798
+ { value: 0.53, color: [255, 54, 69] },
3799
+ { value: 0.6, color: [255, 85, 46] },
3800
+ { value: 0.67, color: [255, 120, 34] },
3801
+ { value: 0.73, color: [255, 157, 37] },
3802
+ { value: 0.8, color: [241, 191, 57] },
3803
+ { value: 0.87, color: [224, 220, 93] },
3804
+ { value: 0.93, color: [218, 241, 142] },
3805
+ { value: 1, color: [227, 253, 198] }
3806
+ ]
3807
+ }),
3808
+ /**
3809
+ * The cividis color ramp is color blind friendly.
3810
+ * Read more here https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0199239
3811
+ * Defined in interval [0, 1], without unit.
3812
+ */
3813
+ CIVIDIS: new ColorRamp({
3814
+ stops: [
3815
+ { value: 0, color: [0, 32, 77, 255] },
3816
+ { value: 0.125, color: [5, 54, 110, 255] },
3817
+ { value: 0.25, color: [65, 77, 108, 255] },
3818
+ { value: 0.375, color: [97, 100, 111, 255] },
3819
+ { value: 0.5, color: [125, 124, 121, 255] },
3820
+ { value: 0.625, color: [156, 149, 120, 255] },
3821
+ { value: 0.75, color: [190, 175, 111, 255] },
3822
+ { value: 0.875, color: [225, 204, 94, 255] },
3823
+ { value: 1, color: [255, 235, 70, 255] }
3824
+ ]
3825
+ }),
3826
+ /**
3827
+ * Classic turbo color ramp.
3828
+ * This is a luminance-constant alternative to the jet, making it more
3829
+ * clor-blind friendly.
3830
+ * Defined in interval [0, 1], without unit.
3831
+ */
3832
+ TURBO: new ColorRamp({
3833
+ stops: [
3834
+ { value: 0, color: [48, 18, 59, 255] },
3835
+ { value: 0.125, color: [70, 107, 227, 255] },
3836
+ { value: 0.25, color: [40, 187, 236, 255] },
3837
+ { value: 0.375, color: [49, 242, 153, 255] },
3838
+ { value: 0.5, color: [162, 252, 60, 255] },
3839
+ { value: 0.625, color: [237, 208, 58, 255] },
3840
+ { value: 0.75, color: [251, 128, 34, 255] },
3841
+ { value: 0.875, color: [210, 49, 5, 255] },
3842
+ { value: 1, color: [122, 4, 3, 255] }
3843
+ ]
3844
+ }),
3845
+ /**
3846
+ * The rocket color ramp is perceptually uniform, which makes it more
3847
+ * color bliend friendly than the classic magma color ramp.
3848
+ * Defined in interval [0, 1], without unit.
3849
+ */
3850
+ ROCKET: new ColorRamp({
3851
+ stops: [
3852
+ { value: 0, color: [250, 235, 221, 0] },
3853
+ { value: 0.133, color: [250, 235, 221, 255] },
3854
+ { value: 0.266, color: [246, 170, 130, 255] },
3855
+ { value: 0.4, color: [240, 96, 67, 255] },
3856
+ { value: 0.533, color: [203, 27, 79, 255] },
3857
+ { value: 0.666, color: [132, 30, 90, 255] },
3858
+ { value: 0.8, color: [63, 27, 68, 255] },
3859
+ { value: 1, color: [3, 5, 26, 255] }
3860
+ ]
3861
+ }),
3862
+ /**
3863
+ * The mako color ramp is perceptually uniform and can be seen as
3864
+ * a color blind friendly alternative to bathymetry or yignbu.
3865
+ * Defined in interval [0, 1], without unit.
3866
+ */
3867
+ MAKO: new ColorRamp({
3868
+ stops: [
3869
+ { value: 0, color: [11, 4, 5, 255] },
3870
+ { value: 0.125, color: [43, 28, 53, 255] },
3871
+ { value: 0.25, color: [62, 53, 107, 255] },
3872
+ { value: 0.375, color: [59, 86, 152, 255] },
3873
+ { value: 0.5, color: [53, 123, 162, 255] },
3874
+ { value: 0.625, color: [53, 158, 170, 255] },
3875
+ { value: 0.75, color: [73, 193, 173, 255] },
3876
+ { value: 0.875, color: [150, 221, 181, 255] },
3877
+ { value: 1, color: [222, 245, 229, 255] }
3878
+ ]
3879
+ })
3880
+ };
3881
+
3882
+ const colorPalettes = [
3883
+ // https://colorhunt.co/palette/1d5b79468b97ef6262f3aa60
3884
+ ["#1D5B79", "#468B97", "#EF6262", "#F3AA60"],
3885
+ // https://colorhunt.co/palette/614bc333bbc585e6c5c8ffe0
3886
+ ["#614BC3", "#33BBC5", "#85E6C5", "#C8FFE0"],
3887
+ // https://colorhunt.co/palette/4619597a316fcd6688aed8cc
3888
+ ["#461959", "#7A316F", "#CD6688", "#AED8CC"],
3889
+ // https://colorhunt.co/palette/0079ff00dfa2f6fa70ff0060
3890
+ ["#0079FF", "#00DFA2", "#F6FA70", "#FF0060"],
3891
+ //https://colorhunt.co/palette/39b5e0a31acbff78f0f5ea5a
3892
+ ["#39B5E0", "#A31ACB", "#FF78F0", "#F5EA5A"],
3893
+ // https://colorhunt.co/palette/37e2d5590696c70a80fbcb0a
3894
+ ["#37E2D5", "#590696", "#C70A80", "#FBCB0A"],
3895
+ // https://colorhunt.co/palette/ffd36efff56d99ffcd9fb4ff
3896
+ ["#FFD36E", "#FFF56D", "#99FFCD", "#9FB4FF"],
3897
+ // https://colorhunt.co/palette/00ead3fff5b7ff449f005f99
3898
+ ["#00EAD3", "#FFF5B7", "#FF449F", "#005F99"],
3899
+ // https://colorhunt.co/palette/10a19d540375ff7000ffbf00
3900
+ ["#10A19D", "#540375", "#FF7000", "#FFBF00"]
3901
+ ];
3902
+ function getRandomColor() {
3903
+ return colorPalettes[~~(Math.random() * colorPalettes.length)][~~(Math.random() * 4)];
3904
+ }
3905
+ function generateRandomSourceName() {
3906
+ return `maptiler_source_${generateRandomString()}`;
3907
+ }
3908
+ function generateRandomLayerName() {
3909
+ return `maptiler_layer_${generateRandomString()}`;
3910
+ }
3911
+ function lerpZoomNumberValues(znv, z) {
3912
+ if (z <= znv[0].zoom) {
3913
+ return znv[0].value;
3914
+ }
3915
+ if (z >= znv[znv.length - 1].zoom) {
3916
+ return znv[znv.length - 1].value;
3917
+ }
3918
+ for (let i = 0; i < znv.length - 1; i += 1) {
3919
+ if (z >= znv[i].zoom && z < znv[i + 1].zoom) {
3920
+ const zoomRange = znv[i + 1].zoom - znv[i].zoom;
3921
+ const normalizedDistanceFromLowerBound = (z - znv[i].zoom) / zoomRange;
3922
+ return normalizedDistanceFromLowerBound * znv[i + 1].value + (1 - normalizedDistanceFromLowerBound) * znv[i].value;
3923
+ }
3924
+ }
3925
+ return 0;
3926
+ }
3927
+ function paintColorOptionsToPaintSpec(color) {
3928
+ return [
3929
+ "interpolate",
3930
+ ["linear"],
3931
+ ["zoom"],
3932
+ ...color.map((el) => [el.zoom, el.value]).flat()
3933
+ ];
3934
+ }
3935
+ function rampedOptionsToLayerPaintSpec(ramp) {
3936
+ return [
3937
+ "interpolate",
3938
+ ["linear"],
3939
+ ["zoom"],
3940
+ ...ramp.map((el) => [el.zoom, el.value]).flat()
3941
+ ];
3942
+ }
3943
+ function computeRampedOutlineWidth(lineWidth, outlineWidth) {
3944
+ if (typeof outlineWidth === "number" && typeof lineWidth === "number") {
3945
+ return 2 * outlineWidth + lineWidth;
3946
+ } else if (typeof outlineWidth === "number" && Array.isArray(lineWidth)) {
3947
+ return [
3948
+ "interpolate",
3949
+ ["linear"],
3950
+ ["zoom"],
3951
+ ...lineWidth.map((el) => [el.zoom, 2 * outlineWidth + el.value]).flat()
3952
+ ];
3953
+ } else if (typeof lineWidth === "number" && Array.isArray(outlineWidth)) {
3954
+ return [
3955
+ "interpolate",
3956
+ ["linear"],
3957
+ ["zoom"],
3958
+ ...outlineWidth.map((el) => [el.zoom, 2 * el.value + lineWidth]).flat()
3959
+ ];
3960
+ }
3961
+ if (Array.isArray(lineWidth) && Array.isArray(outlineWidth)) {
3962
+ const allStops = Array.from(
3963
+ /* @__PURE__ */ new Set([
3964
+ ...lineWidth.map((el) => el.zoom),
3965
+ ...outlineWidth.map((el) => el.zoom)
3966
+ ])
3967
+ ).sort((a, b) => a < b ? -1 : 1);
3968
+ return [
3969
+ "interpolate",
3970
+ ["linear"],
3971
+ ["zoom"],
3972
+ ...allStops.map((z) => [
3973
+ z,
3974
+ 2 * lerpZoomNumberValues(outlineWidth, z) + lerpZoomNumberValues(lineWidth, z)
3975
+ ]).flat()
3976
+ ];
3977
+ }
3978
+ return 0;
3979
+ }
3980
+ function rampedPropertyValueWeight(ramp, property) {
3981
+ return [
3982
+ "interpolate",
3983
+ ["linear"],
3984
+ ["get", property],
3985
+ ...ramp.map((el) => [el.propertyValue, el.value]).flat()
3986
+ ];
3987
+ }
3988
+ function dashArrayMaker(pattern) {
3989
+ const startTrimmedPattern = pattern.trimStart();
3990
+ const fixedPattern = `${startTrimmedPattern}${" ".repeat(
3991
+ pattern.length - startTrimmedPattern.length
3992
+ )}`;
3993
+ const patternArr = Array.from(fixedPattern);
3994
+ const isOnlyDashesAndSpaces = patternArr.every((c) => c === " " || c === "_");
3995
+ if (!isOnlyDashesAndSpaces) {
3996
+ throw new Error(
3997
+ "A dash pattern must be composed only of whitespace and underscore characters."
3998
+ );
3999
+ }
4000
+ const hasBothDashesAndWhitespaces = patternArr.some((c) => c === "_") && patternArr.some((c) => c === " ");
4001
+ if (!hasBothDashesAndWhitespaces) {
4002
+ throw new Error(
4003
+ "A dash pattern must contain at least one underscore and one whitespace character"
4004
+ );
4005
+ }
4006
+ const dashArray = [1];
4007
+ for (let i = 1; i < patternArr.length; i += 1) {
4008
+ const previous = patternArr[i - 1];
4009
+ const current = patternArr[i];
4010
+ if (previous === current) {
4011
+ dashArray[dashArray.length - 1] += 1;
4012
+ } else {
4013
+ dashArray.push(1);
4014
+ }
4015
+ }
4016
+ return dashArray;
4017
+ }
4018
+ function colorDrivenByProperty(style, property) {
4019
+ return [
4020
+ "interpolate",
4021
+ ["linear"],
4022
+ ["get", property],
4023
+ ...style.map((el) => [el.value, el.color]).flat()
4024
+ ];
4025
+ }
4026
+ function radiusDrivenByProperty(style, property, zoomCompensation = true) {
4027
+ if (!zoomCompensation) {
4028
+ return [
4029
+ "interpolate",
4030
+ ["linear"],
4031
+ ["get", property],
4032
+ ...style.map((el) => [el.value, el.pointRadius]).flat()
4033
+ ];
4034
+ }
4035
+ return [
4036
+ "interpolate",
4037
+ ["linear"],
4038
+ ["zoom"],
4039
+ 0,
4040
+ [
4041
+ "interpolate",
4042
+ ["linear"],
4043
+ ["get", property],
4044
+ ...style.map((el) => [el.value, el.pointRadius * 0.025]).flat()
4045
+ ],
4046
+ 2,
4047
+ [
4048
+ "interpolate",
4049
+ ["linear"],
4050
+ ["get", property],
4051
+ ...style.map((el) => [el.value, el.pointRadius * 0.05]).flat()
4052
+ ],
4053
+ 4,
4054
+ [
4055
+ "interpolate",
4056
+ ["linear"],
4057
+ ["get", property],
4058
+ ...style.map((el) => [el.value, el.pointRadius * 0.1]).flat()
4059
+ ],
4060
+ 8,
4061
+ [
4062
+ "interpolate",
4063
+ ["linear"],
4064
+ ["get", property],
4065
+ ...style.map((el) => [el.value, el.pointRadius * 0.25]).flat()
4066
+ ],
4067
+ 16,
4068
+ [
4069
+ "interpolate",
4070
+ ["linear"],
4071
+ ["get", property],
4072
+ ...style.map((el) => [el.value, el.pointRadius]).flat()
4073
+ ]
4074
+ ];
4075
+ }
4076
+ function radiusDrivenByPropertyHeatmap(style, property, zoomCompensation = true) {
4077
+ if (!zoomCompensation) {
4078
+ return [
4079
+ "interpolate",
4080
+ ["linear"],
4081
+ ["get", property],
4082
+ ...style.map((el) => [el.propertyValue, el.value]).flat()
4083
+ ];
4084
+ }
4085
+ return [
4086
+ "interpolate",
4087
+ ["linear"],
4088
+ ["zoom"],
4089
+ 0,
4090
+ [
4091
+ "interpolate",
4092
+ ["linear"],
4093
+ ["get", property],
4094
+ ...style.map((el) => [el.propertyValue, el.value * 0.025]).flat()
4095
+ ],
4096
+ 2,
4097
+ [
4098
+ "interpolate",
4099
+ ["linear"],
4100
+ ["get", property],
4101
+ ...style.map((el) => [el.propertyValue, el.value * 0.05]).flat()
4102
+ ],
4103
+ 4,
4104
+ [
4105
+ "interpolate",
4106
+ ["linear"],
4107
+ ["get", property],
4108
+ ...style.map((el) => [el.propertyValue, el.value * 0.1]).flat()
4109
+ ],
4110
+ 8,
4111
+ [
4112
+ "interpolate",
4113
+ ["linear"],
4114
+ ["get", property],
4115
+ ...style.map((el) => [el.propertyValue, el.value * 0.25]).flat()
4116
+ ],
4117
+ 16,
4118
+ [
4119
+ "interpolate",
4120
+ ["linear"],
4121
+ ["get", property],
4122
+ ...style.map((el) => [el.propertyValue, el.value]).flat()
4123
+ ]
4124
+ ];
4125
+ }
4126
+ function opacityDrivenByProperty(colorramp, property) {
4127
+ if (colorramp.every((el) => el.color[3] === colorramp[0].color[3])) {
4128
+ return colorramp[0].color[3] ? colorramp[0].color[3] / 255 : 1;
4129
+ }
4130
+ return [
4131
+ "interpolate",
4132
+ ["linear"],
4133
+ ["get", property],
4134
+ ...colorramp.getRawColorStops().map((el) => {
4135
+ const value = el.value;
4136
+ const color = el.color;
4137
+ return [value, color.length === 4 ? color[3] / 255 : 1];
4138
+ }).flat()
4139
+ ];
4140
+ }
4141
+ function heatmapIntensityFromColorRamp(colorRamp, steps = 10) {
4142
+ return [
4143
+ "interpolate",
4144
+ ["linear"],
4145
+ ["heatmap-density"],
4146
+ ...Array.from({ length: steps + 1 }, (_, i) => {
4147
+ const unitStep = i / steps;
4148
+ return [unitStep, colorRamp.getColorHex(unitStep)];
4149
+ }).flat()
4150
+ ];
4151
+ }
4152
+
4153
+ var __defProp = Object.defineProperty;
4154
+ var __defProps = Object.defineProperties;
4155
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4156
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4157
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4158
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
4159
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4160
+ var __spreadValues = (a, b) => {
4161
+ for (var prop in b || (b = {}))
4162
+ if (__hasOwnProp.call(b, prop))
4163
+ __defNormalProp(a, prop, b[prop]);
4164
+ if (__getOwnPropSymbols)
4165
+ for (var prop of __getOwnPropSymbols(b)) {
4166
+ if (__propIsEnum.call(b, prop))
4167
+ __defNormalProp(a, prop, b[prop]);
4168
+ }
4169
+ return a;
4170
+ };
4171
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
4172
+ var __async = (__this, __arguments, generator) => {
4173
+ return new Promise((resolve, reject) => {
4174
+ var fulfilled = (value) => {
4175
+ try {
4176
+ step(generator.next(value));
4177
+ } catch (e) {
4178
+ reject(e);
4179
+ }
4180
+ };
4181
+ var rejected = (value) => {
4182
+ try {
4183
+ step(generator.throw(value));
4184
+ } catch (e) {
4185
+ reject(e);
4186
+ }
4187
+ };
4188
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
4189
+ step((generator = generator.apply(__this, __arguments)).next());
4190
+ });
4191
+ };
4192
+ function addPolyline(_0, _1) {
4193
+ return __async(this, arguments, function* (map, options, fetchOptions = {}) {
4194
+ var _a, _b, _c;
4195
+ if (!options.sourceId && !options.data) {
4196
+ throw new Error(
4197
+ "Creating a polyline layer requires an existing .sourceId or a valid .data property"
4198
+ );
4199
+ }
4200
+ let data = options.data;
4201
+ if (typeof data === "string") {
4202
+ if (isUUID(data)) {
4203
+ data = `https://api.maptiler.com/data/${options.data}/features.json?key=${config.apiKey}`;
4204
+ } else if (((_a = data.split(".").pop()) == null ? void 0 : _a.toLowerCase().trim()) === "gpx") {
4205
+ const res = yield fetch(data, fetchOptions);
4206
+ const gpxStr = yield res.text();
4207
+ data = gpx(gpxStr);
4208
+ } else if (((_b = data.split(".").pop()) == null ? void 0 : _b.toLowerCase().trim()) === "kml") {
4209
+ const res = yield fetch(data, fetchOptions);
4210
+ const kmlStr = yield res.text();
4211
+ data = kml(kmlStr);
4212
+ } else {
4213
+ const tmpData = (_c = jsonParseNoThrow(
4214
+ data
4215
+ )) != null ? _c : gpxOrKml(data);
4216
+ if (tmpData)
4217
+ data = tmpData;
4218
+ }
4219
+ if (!data) {
4220
+ throw new Error(
4221
+ "Polyline data was provided as string but is incompatible with valid formats."
4222
+ );
4223
+ }
4224
+ }
4225
+ return addGeoJSONPolyline(map, __spreadProps(__spreadValues({}, options), {
4226
+ data
4227
+ }));
4228
+ });
4229
+ }
4230
+ function addGeoJSONPolyline(map, options) {
4231
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
4232
+ if (options.layerId && map.getLayer(options.layerId)) {
4233
+ throw new Error(
4234
+ `A layer already exists with the layer id: ${options.layerId}`
4235
+ );
4236
+ }
4237
+ const sourceId = (_a = options.sourceId) != null ? _a : generateRandomSourceName();
4238
+ const layerId = (_b = options.layerId) != null ? _b : generateRandomLayerName();
4239
+ const returnedInfo = {
4240
+ polylineLayerId: layerId,
4241
+ polylineOutlineLayerId: "",
4242
+ polylineSourceId: sourceId
4243
+ };
4244
+ if (options.data && !map.getSource(sourceId)) {
4245
+ map.addSource(sourceId, {
4246
+ type: "geojson",
4247
+ data: options.data
4248
+ });
4249
+ }
4250
+ const lineWidth = (_c = options.lineWidth) != null ? _c : 3;
4251
+ const lineColor = (_d = options.lineColor) != null ? _d : getRandomColor();
4252
+ const lineOpacity = (_e = options.lineOpacity) != null ? _e : 1;
4253
+ const lineBlur = (_f = options.lineBlur) != null ? _f : 0;
4254
+ const lineGapWidth = (_g = options.lineGapWidth) != null ? _g : 0;
4255
+ let lineDashArray = (_h = options.lineDashArray) != null ? _h : null;
4256
+ const outlineWidth = (_i = options.outlineWidth) != null ? _i : 1;
4257
+ const outlineColor = (_j = options.outlineColor) != null ? _j : "#FFFFFF";
4258
+ const outlineOpacity = (_k = options.outlineOpacity) != null ? _k : 1;
4259
+ const outlineBlur = (_l = options.outlineBlur) != null ? _l : 0;
4260
+ if (typeof lineDashArray === "string") {
4261
+ lineDashArray = dashArrayMaker(lineDashArray);
4262
+ }
4263
+ if (options.outline === true) {
4264
+ const outlineLayerId = `${layerId}_outline`;
4265
+ returnedInfo.polylineOutlineLayerId = outlineLayerId;
4266
+ map.addLayer(
4267
+ {
4268
+ id: outlineLayerId,
4269
+ type: "line",
4270
+ source: sourceId,
4271
+ layout: {
4272
+ "line-join": (_m = options.lineJoin) != null ? _m : "round",
4273
+ "line-cap": (_n = options.lineCap) != null ? _n : "round"
4274
+ },
4275
+ minzoom: (_o = options.minzoom) != null ? _o : 0,
4276
+ maxzoom: (_p = options.maxzoom) != null ? _p : 23,
4277
+ paint: {
4278
+ "line-opacity": typeof outlineOpacity === "number" ? outlineOpacity : rampedOptionsToLayerPaintSpec(outlineOpacity),
4279
+ "line-color": typeof outlineColor === "string" ? outlineColor : paintColorOptionsToPaintSpec(outlineColor),
4280
+ "line-width": computeRampedOutlineWidth(lineWidth, outlineWidth),
4281
+ "line-blur": typeof outlineBlur === "number" ? outlineBlur : rampedOptionsToLayerPaintSpec(outlineBlur)
4282
+ }
4283
+ },
4284
+ options.beforeId
4285
+ );
4286
+ }
4287
+ map.addLayer(
4288
+ {
4289
+ id: layerId,
4290
+ type: "line",
4291
+ source: sourceId,
4292
+ layout: {
4293
+ "line-join": (_q = options.lineJoin) != null ? _q : "round",
4294
+ "line-cap": (_r = options.lineCap) != null ? _r : "round"
4295
+ },
4296
+ minzoom: (_s = options.minzoom) != null ? _s : 0,
4297
+ maxzoom: (_t = options.maxzoom) != null ? _t : 23,
4298
+ paint: __spreadValues({
4299
+ "line-opacity": typeof lineOpacity === "number" ? lineOpacity : rampedOptionsToLayerPaintSpec(lineOpacity),
4300
+ "line-color": typeof lineColor === "string" ? lineColor : paintColorOptionsToPaintSpec(lineColor),
4301
+ "line-width": typeof lineWidth === "number" ? lineWidth : rampedOptionsToLayerPaintSpec(lineWidth),
4302
+ "line-blur": typeof lineBlur === "number" ? lineBlur : rampedOptionsToLayerPaintSpec(lineBlur),
4303
+ "line-gap-width": typeof lineGapWidth === "number" ? lineGapWidth : rampedOptionsToLayerPaintSpec(lineGapWidth)
4304
+ }, lineDashArray && { "line-dasharray": lineDashArray })
4305
+ },
4306
+ options.beforeId
4307
+ );
4308
+ return returnedInfo;
4309
+ }
4310
+ function addPolygon(map, options) {
4311
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
4312
+ if (options.layerId && map.getLayer(options.layerId)) {
4313
+ throw new Error(
4314
+ `A layer already exists with the layer id: ${options.layerId}`
4315
+ );
4316
+ }
4317
+ const sourceId = (_a = options.sourceId) != null ? _a : generateRandomSourceName();
4318
+ const layerId = (_b = options.layerId) != null ? _b : generateRandomLayerName();
4319
+ const returnedInfo = {
4320
+ polygonLayerId: layerId,
4321
+ polygonOutlineLayerId: options.outline ? `${layerId}_outline` : "",
4322
+ polygonSourceId: sourceId
4323
+ };
4324
+ if (options.data && !map.getSource(sourceId)) {
4325
+ let data = options.data;
4326
+ if (typeof data === "string" && isUUID(data)) {
4327
+ data = `https://api.maptiler.com/data/${data}/features.json?key=${config.apiKey}`;
4328
+ }
4329
+ map.addSource(sourceId, {
4330
+ type: "geojson",
4331
+ data
4332
+ });
4333
+ }
4334
+ let outlineDashArray = (_c = options.outlineDashArray) != null ? _c : null;
4335
+ const outlineWidth = (_d = options.outlineWidth) != null ? _d : 1;
4336
+ const outlineColor = (_e = options.outlineColor) != null ? _e : "#FFFFFF";
4337
+ const outlineOpacity = (_f = options.outlineOpacity) != null ? _f : 1;
4338
+ const outlineBlur = (_g = options.outlineBlur) != null ? _g : 0;
4339
+ const fillColor = (_h = options.fillColor) != null ? _h : getRandomColor();
4340
+ const fillOpacity = (_i = options.fillOpacity) != null ? _i : 1;
4341
+ const outlinePosition = (_j = options.outlinePosition) != null ? _j : "center";
4342
+ const pattern = (_k = options.pattern) != null ? _k : null;
4343
+ if (typeof outlineDashArray === "string") {
4344
+ outlineDashArray = dashArrayMaker(outlineDashArray);
4345
+ }
4346
+ const addLayers = (patternImageId = null) => {
4347
+ var _a2, _b2, _c2, _d2, _e2, _f2;
4348
+ map.addLayer(
4349
+ {
4350
+ id: layerId,
4351
+ type: "fill",
4352
+ source: sourceId,
4353
+ minzoom: (_a2 = options.minzoom) != null ? _a2 : 0,
4354
+ maxzoom: (_b2 = options.maxzoom) != null ? _b2 : 23,
4355
+ paint: __spreadValues({
4356
+ "fill-color": typeof fillColor === "string" ? fillColor : paintColorOptionsToPaintSpec(fillColor),
4357
+ "fill-opacity": typeof fillOpacity === "number" ? fillOpacity : rampedOptionsToLayerPaintSpec(fillOpacity)
4358
+ }, patternImageId && { "fill-pattern": patternImageId })
4359
+ },
4360
+ options.beforeId
4361
+ );
4362
+ if (options.outline === true) {
4363
+ let computedOutlineOffset;
4364
+ if (outlinePosition === "inside") {
4365
+ if (typeof outlineWidth === "number") {
4366
+ computedOutlineOffset = 0.5 * outlineWidth;
4367
+ } else {
4368
+ computedOutlineOffset = rampedOptionsToLayerPaintSpec(
4369
+ outlineWidth.map(({ zoom, value }) => ({
4370
+ zoom,
4371
+ value: 0.5 * value
4372
+ }))
4373
+ );
4374
+ }
4375
+ } else if (outlinePosition === "outside") {
4376
+ if (typeof outlineWidth === "number") {
4377
+ computedOutlineOffset = -0.5 * outlineWidth;
4378
+ } else {
4379
+ computedOutlineOffset = rampedOptionsToLayerPaintSpec(
4380
+ outlineWidth.map((el) => ({
4381
+ zoom: el.zoom,
4382
+ value: -0.5 * el.value
4383
+ }))
4384
+ );
4385
+ }
4386
+ } else {
4387
+ computedOutlineOffset = 0;
4388
+ }
4389
+ map.addLayer(
4390
+ {
4391
+ id: returnedInfo.polygonOutlineLayerId,
4392
+ type: "line",
4393
+ source: sourceId,
4394
+ layout: {
4395
+ "line-join": (_c2 = options.outlineJoin) != null ? _c2 : "round",
4396
+ "line-cap": (_d2 = options.outlineCap) != null ? _d2 : "butt"
4397
+ },
4398
+ minzoom: (_e2 = options.minzoom) != null ? _e2 : 0,
4399
+ maxzoom: (_f2 = options.maxzoom) != null ? _f2 : 23,
4400
+ paint: __spreadValues({
4401
+ "line-opacity": typeof outlineOpacity === "number" ? outlineOpacity : rampedOptionsToLayerPaintSpec(outlineOpacity),
4402
+ "line-color": typeof outlineColor === "string" ? outlineColor : paintColorOptionsToPaintSpec(outlineColor),
4403
+ "line-width": typeof outlineWidth === "number" ? outlineWidth : rampedOptionsToLayerPaintSpec(outlineWidth),
4404
+ "line-blur": typeof outlineBlur === "number" ? outlineBlur : rampedOptionsToLayerPaintSpec(outlineBlur),
4405
+ "line-offset": computedOutlineOffset
4406
+ }, outlineDashArray && {
4407
+ "line-dasharray": outlineDashArray
4408
+ })
4409
+ },
4410
+ options.beforeId
4411
+ );
4412
+ }
4413
+ };
4414
+ if (pattern) {
4415
+ if (map.hasImage(pattern)) {
4416
+ addLayers(pattern);
4417
+ } else {
4418
+ map.loadImage(
4419
+ pattern,
4420
+ // (error?: Error | null, image?: HTMLImageElement | ImageBitmap | null, expiry?: ExpiryData | null)
4421
+ (error, image) => {
4422
+ if (error) {
4423
+ console.error("Could not load the pattern image.", error.message);
4424
+ return addLayers();
4425
+ }
4426
+ if (!image) {
4427
+ console.error(
4428
+ `An image cannot be created from the pattern URL ${pattern}.`
4429
+ );
4430
+ return addLayers();
4431
+ }
4432
+ map.addImage(pattern, image);
4433
+ addLayers(pattern);
4434
+ }
4435
+ );
4436
+ }
4437
+ } else {
4438
+ addLayers();
4439
+ }
4440
+ return returnedInfo;
4441
+ }
4442
+ function addPoint(map, options) {
4443
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
4444
+ if (options.layerId && map.getLayer(options.layerId)) {
4445
+ throw new Error(
4446
+ `A layer already exists with the layer id: ${options.layerId}`
4447
+ );
4448
+ }
4449
+ const minPointRadius = (_a = options.minPointRadius) != null ? _a : 10;
4450
+ const maxPointRadius = (_b = options.maxPointRadius) != null ? _b : 50;
4451
+ const cluster = (_c = options.cluster) != null ? _c : false;
4452
+ const nbDefaultDataDrivenStyleSteps = 20;
4453
+ const colorramp = Array.isArray(options.pointColor) ? options.pointColor : ColorRampCollection.TURBO.scale(
4454
+ 10,
4455
+ options.cluster ? 1e4 : 1e3
4456
+ ).resample("ease-out-square");
4457
+ const colorRampBounds = colorramp.getBounds();
4458
+ const sourceId = (_d = options.sourceId) != null ? _d : generateRandomSourceName();
4459
+ const layerId = (_e = options.layerId) != null ? _e : generateRandomLayerName();
4460
+ const showLabel = (_f = options.showLabel) != null ? _f : cluster;
4461
+ const alignOnViewport = (_g = options.alignOnViewport) != null ? _g : true;
4462
+ const outline = (_h = options.outline) != null ? _h : false;
4463
+ const outlineOpacity = (_i = options.outlineOpacity) != null ? _i : 1;
4464
+ const outlineWidth = (_j = options.outlineWidth) != null ? _j : 1;
4465
+ const outlineColor = (_k = options.outlineColor) != null ? _k : "#FFFFFF";
4466
+ let pointOpacity;
4467
+ const zoomCompensation = (_l = options.zoomCompensation) != null ? _l : true;
4468
+ const minzoom = (_m = options.minzoom) != null ? _m : 0;
4469
+ const maxzoom = (_n = options.maxzoom) != null ? _n : 23;
4470
+ if (typeof options.pointOpacity === "number") {
4471
+ pointOpacity = options.pointOpacity;
4472
+ } else if (Array.isArray(options.pointOpacity)) {
4473
+ pointOpacity = rampedOptionsToLayerPaintSpec(options.pointOpacity);
4474
+ } else if (options.cluster) {
4475
+ pointOpacity = opacityDrivenByProperty(colorramp, "point_count");
4476
+ } else if (options.property) {
4477
+ pointOpacity = opacityDrivenByProperty(colorramp, options.property);
4478
+ } else {
4479
+ pointOpacity = rampedOptionsToLayerPaintSpec([
4480
+ { zoom: minzoom, value: 0 },
4481
+ { zoom: minzoom + 0.25, value: 1 },
4482
+ { zoom: maxzoom - 0.25, value: 1 },
4483
+ { zoom: maxzoom, value: 0 }
4484
+ ]);
4485
+ }
4486
+ const returnedInfo = {
4487
+ pointLayerId: layerId,
4488
+ clusterLayerId: "",
4489
+ labelLayerId: "",
4490
+ pointSourceId: sourceId
4491
+ };
4492
+ if (options.data && !map.getSource(sourceId)) {
4493
+ let data = options.data;
4494
+ if (typeof data === "string" && isUUID(data)) {
4495
+ data = `https://api.maptiler.com/data/${data}/features.json?key=${config.apiKey}`;
4496
+ }
4497
+ map.addSource(sourceId, {
4498
+ type: "geojson",
4499
+ data,
4500
+ cluster
4501
+ });
4502
+ }
4503
+ if (cluster) {
4504
+ returnedInfo.clusterLayerId = `${layerId}_cluster`;
4505
+ const clusterStyle = Array.from(
4506
+ { length: nbDefaultDataDrivenStyleSteps },
4507
+ (_, i) => {
4508
+ const value = colorRampBounds.min + i * (colorRampBounds.max - colorRampBounds.min) / (nbDefaultDataDrivenStyleSteps - 1);
4509
+ return {
4510
+ value,
4511
+ pointRadius: minPointRadius + (maxPointRadius - minPointRadius) * Math.pow(i / (nbDefaultDataDrivenStyleSteps - 1), 0.5),
4512
+ color: colorramp.getColorHex(value)
4513
+ };
4514
+ }
4515
+ );
4516
+ map.addLayer(
4517
+ {
4518
+ id: returnedInfo.clusterLayerId,
4519
+ type: "circle",
4520
+ source: sourceId,
4521
+ filter: ["has", "point_count"],
4522
+ paint: __spreadValues({
4523
+ // 'circle-color': options.pointColor ?? colorDrivenByProperty(clusterStyle, "point_count"),
4524
+ "circle-color": typeof options.pointColor === "string" ? options.pointColor : colorDrivenByProperty(clusterStyle, "point_count"),
4525
+ "circle-radius": typeof options.pointRadius === "number" ? options.pointRadius : Array.isArray(options.pointRadius) ? rampedOptionsToLayerPaintSpec(options.pointRadius) : radiusDrivenByProperty(clusterStyle, "point_count", false),
4526
+ "circle-pitch-alignment": alignOnViewport ? "viewport" : "map",
4527
+ "circle-pitch-scale": "map",
4528
+ // scale with camera distance regardless of viewport/biewport alignement
4529
+ "circle-opacity": pointOpacity
4530
+ }, outline && {
4531
+ "circle-stroke-opacity": typeof outlineOpacity === "number" ? outlineOpacity : rampedOptionsToLayerPaintSpec(outlineOpacity),
4532
+ "circle-stroke-width": typeof outlineWidth === "number" ? outlineWidth : rampedOptionsToLayerPaintSpec(outlineWidth),
4533
+ "circle-stroke-color": typeof outlineColor === "string" ? outlineColor : paintColorOptionsToPaintSpec(outlineColor)
4534
+ }),
4535
+ minzoom,
4536
+ maxzoom
4537
+ },
4538
+ options.beforeId
4539
+ );
4540
+ map.addLayer(
4541
+ {
4542
+ id: returnedInfo.pointLayerId,
4543
+ type: "circle",
4544
+ source: sourceId,
4545
+ filter: ["!", ["has", "point_count"]],
4546
+ paint: __spreadValues({
4547
+ "circle-pitch-alignment": alignOnViewport ? "viewport" : "map",
4548
+ "circle-pitch-scale": "map",
4549
+ // scale with camera distance regardless of viewport/biewport alignement
4550
+ // 'circle-color': options.pointColor ?? clusterStyle[0].color,
4551
+ "circle-color": typeof options.pointColor === "string" ? options.pointColor : colorramp.getColorHex(colorramp.getBounds().min),
4552
+ "circle-radius": typeof options.pointRadius === "number" ? options.pointRadius : Array.isArray(options.pointRadius) ? rampedOptionsToLayerPaintSpec(options.pointRadius) : clusterStyle[0].pointRadius * 0.75,
4553
+ "circle-opacity": pointOpacity
4554
+ }, outline && {
4555
+ "circle-stroke-opacity": typeof outlineOpacity === "number" ? outlineOpacity : rampedOptionsToLayerPaintSpec(outlineOpacity),
4556
+ "circle-stroke-width": typeof outlineWidth === "number" ? outlineWidth : rampedOptionsToLayerPaintSpec(outlineWidth),
4557
+ "circle-stroke-color": typeof outlineColor === "string" ? outlineColor : paintColorOptionsToPaintSpec(outlineColor)
4558
+ }),
4559
+ minzoom,
4560
+ maxzoom
4561
+ },
4562
+ options.beforeId
4563
+ );
4564
+ } else {
4565
+ let pointColor = typeof options.pointColor === "string" ? options.pointColor : Array.isArray(options.pointColor) ? options.pointColor.getColorHex(options.pointColor.getBounds().min) : getRandomColor();
4566
+ let pointRadius = typeof options.pointRadius === "number" ? zoomCompensation ? rampedOptionsToLayerPaintSpec([
4567
+ { zoom: 0, value: options.pointRadius * 0.025 },
4568
+ { zoom: 2, value: options.pointRadius * 0.05 },
4569
+ { zoom: 4, value: options.pointRadius * 0.1 },
4570
+ { zoom: 8, value: options.pointRadius * 0.25 },
4571
+ { zoom: 16, value: options.pointRadius * 1 }
4572
+ ]) : options.pointRadius : Array.isArray(options.pointRadius) ? rampedOptionsToLayerPaintSpec(options.pointRadius) : zoomCompensation ? rampedOptionsToLayerPaintSpec([
4573
+ { zoom: 0, value: minPointRadius * 0.05 },
4574
+ { zoom: 2, value: minPointRadius * 0.1 },
4575
+ { zoom: 4, value: minPointRadius * 0.2 },
4576
+ { zoom: 8, value: minPointRadius * 0.5 },
4577
+ { zoom: 16, value: minPointRadius * 1 }
4578
+ ]) : minPointRadius;
4579
+ if (options.property && Array.isArray(options.pointColor)) {
4580
+ const dataDrivenStyle = Array.from(
4581
+ { length: nbDefaultDataDrivenStyleSteps },
4582
+ (_, i) => {
4583
+ const value = colorRampBounds.min + i * (colorRampBounds.max - colorRampBounds.min) / (nbDefaultDataDrivenStyleSteps - 1);
4584
+ return {
4585
+ value,
4586
+ pointRadius: typeof options.pointRadius === "number" ? options.pointRadius : minPointRadius + (maxPointRadius - minPointRadius) * Math.pow(i / (nbDefaultDataDrivenStyleSteps - 1), 0.5),
4587
+ color: typeof options.pointColor === "string" ? options.pointColor : colorramp.getColorHex(value)
4588
+ };
4589
+ }
4590
+ );
4591
+ pointColor = colorDrivenByProperty(dataDrivenStyle, options.property);
4592
+ pointRadius = radiusDrivenByProperty(
4593
+ dataDrivenStyle,
4594
+ options.property,
4595
+ zoomCompensation
4596
+ );
4597
+ }
4598
+ map.addLayer(
4599
+ {
4600
+ id: returnedInfo.pointLayerId,
4601
+ type: "circle",
4602
+ source: sourceId,
4603
+ layout: {
4604
+ // Contrary to labels, we want to see the small one in front. Weirdly "circle-sort-key" works in the opposite direction as "symbol-sort-key".
4605
+ "circle-sort-key": options.property ? ["/", 1, ["get", options.property]] : 0
4606
+ },
4607
+ paint: __spreadValues({
4608
+ "circle-pitch-alignment": alignOnViewport ? "viewport" : "map",
4609
+ "circle-pitch-scale": "map",
4610
+ // scale with camera distance regardless of viewport/biewport alignement
4611
+ "circle-color": pointColor,
4612
+ "circle-opacity": pointOpacity,
4613
+ "circle-radius": pointRadius
4614
+ }, outline && {
4615
+ "circle-stroke-opacity": typeof outlineOpacity === "number" ? outlineOpacity : rampedOptionsToLayerPaintSpec(outlineOpacity),
4616
+ "circle-stroke-width": typeof outlineWidth === "number" ? outlineWidth : rampedOptionsToLayerPaintSpec(outlineWidth),
4617
+ "circle-stroke-color": typeof outlineColor === "string" ? outlineColor : paintColorOptionsToPaintSpec(outlineColor)
4618
+ }),
4619
+ minzoom,
4620
+ maxzoom
4621
+ },
4622
+ options.beforeId
4623
+ );
4624
+ }
4625
+ if (showLabel !== false && (options.cluster || options.property)) {
4626
+ returnedInfo.labelLayerId = `${layerId}_label`;
4627
+ const labelColor = (_o = options.labelColor) != null ? _o : "#fff";
4628
+ const labelSize = (_p = options.labelSize) != null ? _p : 12;
4629
+ map.addLayer(
4630
+ {
4631
+ id: returnedInfo.labelLayerId,
4632
+ type: "symbol",
4633
+ source: sourceId,
4634
+ filter: [
4635
+ "has",
4636
+ options.cluster ? "point_count" : options.property
4637
+ ],
4638
+ layout: {
4639
+ "text-field": options.cluster ? "{point_count_abbreviated}" : `{${options.property}}`,
4640
+ "text-font": ["Noto Sans Regular"],
4641
+ "text-size": labelSize,
4642
+ "text-pitch-alignment": alignOnViewport ? "viewport" : "map",
4643
+ "symbol-sort-key": [
4644
+ "/",
4645
+ 1,
4646
+ [
4647
+ "get",
4648
+ options.cluster ? "point_count" : options.property
4649
+ ]
4650
+ ]
4651
+ // so that the largest value goes on top
4652
+ },
4653
+ paint: {
4654
+ "text-color": labelColor,
4655
+ "text-opacity": pointOpacity
4656
+ },
4657
+ minzoom,
4658
+ maxzoom
4659
+ },
4660
+ options.beforeId
4661
+ );
4662
+ }
4663
+ return returnedInfo;
4664
+ }
4665
+ function addHeatmap(map, options) {
4666
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
4667
+ if (options.layerId && map.getLayer(options.layerId)) {
4668
+ throw new Error(
4669
+ `A layer already exists with the layer id: ${options.layerId}`
4670
+ );
4671
+ }
4672
+ const sourceId = (_a = options.sourceId) != null ? _a : generateRandomSourceName();
4673
+ const layerId = (_b = options.layerId) != null ? _b : generateRandomLayerName();
4674
+ const minzoom = (_c = options.minzoom) != null ? _c : 0;
4675
+ const maxzoom = (_d = options.maxzoom) != null ? _d : 23;
4676
+ const zoomCompensation = (_e = options.zoomCompensation) != null ? _e : true;
4677
+ const opacity = (_f = options.opacity) != null ? _f : [
4678
+ { zoom: minzoom, value: 0 },
4679
+ { zoom: minzoom + 0.25, value: 1 },
4680
+ { zoom: maxzoom - 0.25, value: 1 },
4681
+ { zoom: maxzoom, value: 0 }
4682
+ ];
4683
+ let colorRamp = Array.isArray(options.colorRamp) ? options.colorRamp : ColorRampCollection.TURBO.transparentStart();
4684
+ const crBounds = colorRamp.getBounds();
4685
+ if (crBounds.min !== 0 || crBounds.max !== 1) {
4686
+ colorRamp = colorRamp.scale(0, 1);
4687
+ }
4688
+ if (!colorRamp.hasTransparentStart()) {
4689
+ colorRamp = colorRamp.transparentStart();
4690
+ }
4691
+ const intensity = (_g = options.intensity) != null ? _g : [
4692
+ { zoom: 0, value: 0.01 },
4693
+ { zoom: 4, value: 0.2 },
4694
+ { zoom: 16, value: 1 }
4695
+ ];
4696
+ const property = (_h = options.property) != null ? _h : null;
4697
+ const propertyValueWeight = (_i = options.weight) != null ? _i : 1;
4698
+ let heatmapWeight = 1;
4699
+ if (property) {
4700
+ if (typeof propertyValueWeight === "number") {
4701
+ heatmapWeight = propertyValueWeight;
4702
+ if (typeof options.weight === "number") {
4703
+ console.warn(
4704
+ "The option `.property` is ignored when `.propertyValueWeights` is not of type `PropertyValueWeights`"
4705
+ );
4706
+ }
4707
+ } else if (Array.isArray(propertyValueWeight)) {
4708
+ heatmapWeight = rampedPropertyValueWeight(propertyValueWeight, property);
4709
+ } else {
4710
+ console.warn(
4711
+ "The option `.property` is ignored when `.propertyValueWeights` is not of type `PropertyValueWeights`"
4712
+ );
4713
+ }
4714
+ } else {
4715
+ if (typeof propertyValueWeight === "number") {
4716
+ heatmapWeight = propertyValueWeight;
4717
+ } else if (Array.isArray(propertyValueWeight)) {
4718
+ console.warn(
4719
+ "The options `.propertyValueWeights` can only be used when `.property` is provided."
4720
+ );
4721
+ }
4722
+ }
4723
+ const defaultRadiusZoomRamping = [
4724
+ { zoom: 0, value: 50 * 0.025 },
4725
+ { zoom: 2, value: 50 * 0.05 },
4726
+ { zoom: 4, value: 50 * 0.1 },
4727
+ { zoom: 8, value: 50 * 0.25 },
4728
+ { zoom: 16, value: 50 }
4729
+ ];
4730
+ const radius = (_j = options.radius) != null ? _j : zoomCompensation ? defaultRadiusZoomRamping : 10;
4731
+ let radiusHeatmap = 1;
4732
+ if (typeof radius === "number") {
4733
+ radiusHeatmap = radius;
4734
+ } else if (Array.isArray(radius) && "zoom" in radius[0]) {
4735
+ radiusHeatmap = rampedOptionsToLayerPaintSpec(radius);
4736
+ } else if (property && Array.isArray(radius) && "propertyValue" in radius[0]) {
4737
+ radiusHeatmap = radiusDrivenByPropertyHeatmap(
4738
+ radius,
4739
+ property,
4740
+ zoomCompensation
4741
+ );
4742
+ } else if (!property && Array.isArray(radius) && "propertyValue" in radius[0]) {
4743
+ radiusHeatmap = rampedOptionsToLayerPaintSpec(
4744
+ defaultRadiusZoomRamping
4745
+ );
4746
+ console.warn(
4747
+ "The option `.radius` can only be property-driven if the option `.property` is provided."
4748
+ );
4749
+ } else {
4750
+ radiusHeatmap = rampedOptionsToLayerPaintSpec(
4751
+ defaultRadiusZoomRamping
4752
+ );
4753
+ }
4754
+ const returnedInfo = {
4755
+ heatmapLayerId: layerId,
4756
+ heatmapSourceId: sourceId
4757
+ };
4758
+ if (options.data && !map.getSource(sourceId)) {
4759
+ let data = options.data;
4760
+ if (typeof data === "string" && isUUID(data)) {
4761
+ data = `https://api.maptiler.com/data/${data}/features.json?key=${config.apiKey}`;
4762
+ }
4763
+ map.addSource(sourceId, {
4764
+ type: "geojson",
4765
+ data
4766
+ });
4767
+ }
4768
+ map.addLayer({
4769
+ id: layerId,
4770
+ type: "heatmap",
4771
+ source: sourceId,
4772
+ minzoom,
4773
+ maxzoom,
4774
+ paint: {
4775
+ "heatmap-weight": heatmapWeight,
4776
+ "heatmap-intensity": typeof intensity === "number" ? intensity : rampedOptionsToLayerPaintSpec(
4777
+ intensity
4778
+ ),
4779
+ "heatmap-color": heatmapIntensityFromColorRamp(colorRamp),
4780
+ "heatmap-radius": radiusHeatmap,
4781
+ "heatmap-opacity": typeof opacity === "number" ? opacity : rampedOptionsToLayerPaintSpec(
4782
+ opacity
4783
+ )
4784
+ }
4785
+ });
4786
+ return returnedInfo;
4787
+ }
4788
+
4789
+ const helpers = {
4790
+ addPolyline,
4791
+ addPolygon,
4792
+ addPoint,
4793
+ addHeatmap
4794
+ };
4795
+
1720
4796
  const {
1721
4797
  // supported,
1722
4798
  setRTLTextPlugin,
@@ -1754,5 +4830,5 @@ maplibregl__default.ScaleControl;
1754
4830
  maplibregl__default.FullscreenControl;
1755
4831
  maplibregl__default.TerrainControl;
1756
4832
 
1757
- export { AJAXError, AttributionControl, CanvasSource, CanvasSourceMLGL, Evented, FullscreenControl, GeoJSONSource, GeoJSONSourceMLGL, GeolocateControl, GeolocationType, ImageSource, ImageSourceMLGL, Language, LngLat, LngLatBounds, LogoControl, Map, MapMLGL, MaptilerGeolocateControl, MaptilerLogoControl, MaptilerNavigationControl, MaptilerTerrainControl, Marker, MarkerMLGL, MercatorCoordinate, NavigationControl, Point, Popup, PopupMLGL, RasterDEMTileSource, RasterDEMTileSourceMLGL, RasterTileSource, RasterTileSourceMLGL, ScaleControl, SdkConfig, Style, StyleMLGL, TerrainControl, VectorTileSource, VectorTileSourceMLGL, VideoSource, VideoSourceMLGL, addProtocol, clearPrewarmedResources, config, getRTLTextPluginStatus, maxParallelImageRequests, prewarm, removeProtocol, setRTLTextPlugin, version, workerCount, workerUrl };
4833
+ export { AJAXError, AttributionControl, CanvasSource, CanvasSourceMLGL, ColorRamp, ColorRampCollection, Evented, FullscreenControl, GeoJSONSource, GeoJSONSourceMLGL, GeolocateControl, GeolocationType, ImageSource, ImageSourceMLGL, Language, LngLat, LngLatBounds, LogoControl, Map, MapMLGL, MaptilerGeolocateControl, MaptilerLogoControl, MaptilerNavigationControl, MaptilerTerrainControl, Marker, MarkerMLGL, MercatorCoordinate, NavigationControl, Point, Popup, PopupMLGL, RasterDEMTileSource, RasterDEMTileSourceMLGL, RasterTileSource, RasterTileSourceMLGL, ScaleControl, SdkConfig, Style, StyleMLGL, TerrainControl, VectorTileSource, VectorTileSourceMLGL, VideoSource, VideoSourceMLGL, addProtocol, clearPrewarmedResources, config, getRTLTextPluginStatus, gpx, gpxOrKml, hasChildNodeWithName, helpers, kml, maxParallelImageRequests, prewarm, removeProtocol, setRTLTextPlugin, str2xml, version, workerCount, workerUrl, xml2str };
1758
4834
  //# sourceMappingURL=maptiler-sdk.mjs.map