@maptiler/sdk 1.0.8 → 1.0.10

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.
@@ -7,9 +7,21 @@ import { config as config$1, MapStyle, mapStylePresetList, expandMapStyle, MapSt
7
7
  export { LanguageGeocoding, MapStyle, MapStyleVariant, ReferenceMapStyle, ServiceError, coordinates, data, geocoding, geolocation, staticMaps } from '@maptiler/client';
8
8
 
9
9
  const Language = {
10
+ /**
11
+ * AUTO mode uses the language of the browser
12
+ */
10
13
  AUTO: "auto",
14
+ /**
15
+ * Default fallback languages that uses latin charaters
16
+ */
11
17
  LATIN: "latin",
18
+ /**
19
+ * Default fallback languages that uses non-latin charaters
20
+ */
12
21
  NON_LATIN: "nonlatin",
22
+ /**
23
+ * Labels are in their local language, when available
24
+ */
13
25
  LOCAL: "",
14
26
  ALBANIAN: "sq",
15
27
  AMHARIC: "am",
@@ -100,30 +112,68 @@ function getBrowserLanguage() {
100
112
  class SdkConfig extends EventEmitter {
101
113
  constructor() {
102
114
  super();
115
+ /**
116
+ * The primary language. By default, the language of the web browser is used.
117
+ */
103
118
  this.primaryLanguage = Language.AUTO;
119
+ /**
120
+ * The secondary language, to overwrite the default language defined in the map style.
121
+ * This settings is highly dependant on the style compatibility and may not work in most cases.
122
+ */
104
123
  this.secondaryLanguage = null;
124
+ /**
125
+ * Setting on whether of not the SDK runs with a session logic.
126
+ * A "session" is started at the initialization of the SDK and finished when the browser
127
+ * page is being refreshed.
128
+ * When `session` is enabled (default: true), the extra URL param `mtsid` is added to queries
129
+ * on the MapTiler Cloud API. This allows MapTiler to enable "session based billing".
130
+ */
105
131
  this.session = true;
132
+ /**
133
+ * Unit to be used
134
+ */
106
135
  this._unit = "metric";
136
+ /**
137
+ * MapTiler Cloud API key
138
+ */
107
139
  this._apiKey = "";
108
140
  }
141
+ /**
142
+ * Set the unit system
143
+ */
109
144
  set unit(u) {
110
145
  this._unit = u;
111
146
  this.emit("unit", u);
112
147
  }
148
+ /**
149
+ * Get the unit system
150
+ */
113
151
  get unit() {
114
152
  return this._unit;
115
153
  }
154
+ /**
155
+ * Set the MapTiler Cloud API key
156
+ */
116
157
  set apiKey(k) {
117
158
  this._apiKey = k;
118
159
  config$1.apiKey = k;
119
160
  this.emit("apiKey", k);
120
161
  }
162
+ /**
163
+ * Get the MapTiler Cloud API key
164
+ */
121
165
  get apiKey() {
122
166
  return this._apiKey;
123
167
  }
168
+ /**
169
+ * Set a the custom fetch function to replace the default one
170
+ */
124
171
  set fetch(f) {
125
172
  config$1.fetch = f;
126
173
  }
174
+ /**
175
+ * Get the fetch fucntion
176
+ */
127
177
  get fetch() {
128
178
  return config$1.fetch;
129
179
  }
@@ -142,7 +192,13 @@ const defaults = {
142
192
  };
143
193
  Object.freeze(defaults);
144
194
 
145
- class MaptilerLogoControl extends maplibregl__default.LogoControl {
195
+ class LogoControl extends maplibregl__default.LogoControl {
196
+ onAdd(map) {
197
+ return super.onAdd(map);
198
+ }
199
+ }
200
+
201
+ class MaptilerLogoControl extends LogoControl {
146
202
  constructor(options = {}) {
147
203
  var _a, _b;
148
204
  super(options);
@@ -190,6 +246,7 @@ function enableRTL() {
190
246
  defaults.rtlPluginURL,
191
247
  null,
192
248
  true
249
+ // Lazy load the plugin
193
250
  );
194
251
  }
195
252
  }
@@ -287,7 +344,13 @@ class MaptilerTerrainControl {
287
344
  }
288
345
  }
289
346
 
290
- class MaptilerNavigationControl extends maplibregl__default.NavigationControl {
347
+ class NavigationControl extends maplibregl__default.NavigationControl {
348
+ onAdd(map) {
349
+ return super.onAdd(map);
350
+ }
351
+ }
352
+
353
+ class MaptilerNavigationControl extends NavigationControl {
291
354
  constructor() {
292
355
  super({
293
356
  showCompass: true,
@@ -313,11 +376,17 @@ class MaptilerNavigationControl extends maplibregl__default.NavigationControl {
313
376
  }
314
377
  });
315
378
  }
379
+ /**
380
+ * Overloading: the button now stores its click callback so that we can later on delete it and replace it
381
+ */
316
382
  _createButton(className, fn) {
317
383
  const button = super._createButton(className, fn);
318
384
  button.clickFunction = fn;
319
385
  return button;
320
386
  }
387
+ /**
388
+ * Overloading: Limit how flat the compass icon can get
389
+ */
321
390
  _rotateCompassArrow() {
322
391
  const rotate = this.options.visualizePitch ? `scale(${Math.min(
323
392
  1.5,
@@ -327,6 +396,12 @@ class MaptilerNavigationControl extends maplibregl__default.NavigationControl {
327
396
  }
328
397
  }
329
398
 
399
+ class GeolocateControl extends maplibregl__default.GeolocateControl {
400
+ onAdd(map) {
401
+ return super.onAdd(map);
402
+ }
403
+ }
404
+
330
405
  var __defProp$1 = Object.defineProperty;
331
406
  var __defProps$1 = Object.defineProperties;
332
407
  var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
@@ -346,14 +421,19 @@ var __spreadValues$1 = (a, b) => {
346
421
  return a;
347
422
  };
348
423
  var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
349
- const GeolocateControl$1 = maplibregl__default.GeolocateControl;
350
424
  const Marker$1 = maplibregl__default.Marker;
351
425
  const LngLat$1 = maplibregl__default.LngLat;
352
- class MaptilerGeolocateControl extends GeolocateControl$1 {
426
+ class MaptilerGeolocateControl extends GeolocateControl {
353
427
  constructor() {
354
428
  super(...arguments);
355
429
  this.lastUpdatedCenter = new LngLat$1(0, 0);
356
430
  }
431
+ /**
432
+ * Update the camera location to center on the current position
433
+ *
434
+ * @param {Position} position the Geolocation API Position
435
+ * @private
436
+ */
357
437
  _updateCamera(position) {
358
438
  const center = new LngLat$1(
359
439
  position.coords.longitude,
@@ -372,6 +452,7 @@ class MaptilerGeolocateControl extends GeolocateControl$1 {
372
452
  }
373
453
  this._map.fitBounds(center.toBounds(radius), options, {
374
454
  geolocateSource: true
455
+ // tag this camera change so it won't cause the control to change to background state
375
456
  });
376
457
  let hasFittingBeenDisrupted = false;
377
458
  const flagFittingDisruption = () => {
@@ -491,6 +572,24 @@ class MaptilerGeolocateControl extends GeolocateControl$1 {
491
572
  }
492
573
  }
493
574
 
575
+ class AttributionControl extends maplibregl__default.AttributionControl {
576
+ onAdd(map) {
577
+ return super.onAdd(map);
578
+ }
579
+ }
580
+
581
+ class ScaleControl extends maplibregl__default.ScaleControl {
582
+ onAdd(map) {
583
+ return super.onAdd(map);
584
+ }
585
+ }
586
+
587
+ class FullscreenControl extends maplibregl__default.FullscreenControl {
588
+ onAdd(map) {
589
+ return super.onAdd(map);
590
+ }
591
+ }
592
+
494
593
  var __defProp = Object.defineProperty;
495
594
  var __defProps = Object.defineProperties;
496
595
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
@@ -537,7 +636,7 @@ const GeolocationType = {
537
636
  };
538
637
  class Map extends maplibregl__default.Map {
539
638
  constructor(options) {
540
- var _a, _b;
639
+ var _a, _b, _c;
541
640
  if (options.apiKey) {
542
641
  config.apiKey = options.apiKey;
543
642
  }
@@ -575,16 +674,17 @@ class Map extends maplibregl__default.Map {
575
674
  };
576
675
  }
577
676
  }));
578
- this.languageShouldUpdate = false;
579
- this.isStyleInitialized = false;
580
677
  this.isTerrainEnabled = false;
581
678
  this.terrainExaggeration = 1;
582
679
  this.primaryLanguage = null;
583
680
  this.secondaryLanguage = null;
681
+ this.terrainGrowing = false;
682
+ this.terrainFlattening = false;
584
683
  this.primaryLanguage = (_a = options.language) != null ? _a : config.primaryLanguage;
585
684
  this.secondaryLanguage = config.secondaryLanguage;
685
+ this.terrainExaggeration = (_b = options.terrainExaggeration) != null ? _b : this.terrainExaggeration;
586
686
  this.once("styledata", () => __async(this, null, function* () {
587
- if (options.geolocate === false) {
687
+ if (!options.geolocate) {
588
688
  return;
589
689
  }
590
690
  if (options.center) {
@@ -613,20 +713,35 @@ class Map extends maplibregl__default.Map {
613
713
  });
614
714
  if (locationResult.state === "granted") {
615
715
  navigator.geolocation.getCurrentPosition(
716
+ // success callback
616
717
  (data) => {
617
718
  if (ipLocatedCameraHash !== this.getCameraHash()) {
618
719
  return;
619
720
  }
620
- this.easeTo({
621
- center: [data.coords.longitude, data.coords.latitude],
622
- zoom: options.zoom || 12,
623
- duration: 2e3
624
- });
721
+ if (this.terrain) {
722
+ this.easeTo({
723
+ center: [data.coords.longitude, data.coords.latitude],
724
+ zoom: options.zoom || 12,
725
+ duration: 2e3
726
+ });
727
+ } else {
728
+ this.once("terrain", () => {
729
+ this.easeTo({
730
+ center: [data.coords.longitude, data.coords.latitude],
731
+ zoom: options.zoom || 12,
732
+ duration: 2e3
733
+ });
734
+ });
735
+ }
625
736
  },
737
+ // error callback
626
738
  null,
739
+ // options
627
740
  {
628
741
  maximumAge: 24 * 3600 * 1e3,
742
+ // a day in millisec
629
743
  timeout: 5e3,
744
+ // milliseconds
630
745
  enableHighAccuracy: false
631
746
  }
632
747
  );
@@ -667,14 +782,14 @@ class Map extends maplibregl__default.Map {
667
782
  options.logoPosition
668
783
  );
669
784
  if (options.attributionControl === false) {
670
- this.addControl(new maplibregl__default.AttributionControl(options));
785
+ this.addControl(new AttributionControl(options));
671
786
  }
672
787
  } else if (options.maptilerLogo) {
673
788
  this.addControl(new MaptilerLogoControl(), options.logoPosition);
674
789
  }
675
790
  if (options.scaleControl) {
676
791
  const position = options.scaleControl === true || options.scaleControl === void 0 ? "bottom-right" : options.scaleControl;
677
- const scaleControl = new maplibregl__default.ScaleControl({ unit: config.unit });
792
+ const scaleControl = new ScaleControl({ unit: config.unit });
678
793
  this.addControl(scaleControl, position);
679
794
  config.on("unit", (unit) => {
680
795
  scaleControl.setUnit(unit);
@@ -687,6 +802,7 @@ class Map extends maplibregl__default.Map {
687
802
  if (options.geolocateControl !== false) {
688
803
  const position = options.geolocateControl === true || options.geolocateControl === void 0 ? "top-right" : options.geolocateControl;
689
804
  this.addControl(
805
+ // new maplibregl.GeolocateControl({
690
806
  new MaptilerGeolocateControl({
691
807
  positionOptions: {
692
808
  enableHighAccuracy: true,
@@ -709,24 +825,104 @@ class Map extends maplibregl__default.Map {
709
825
  }
710
826
  if (options.fullscreenControl) {
711
827
  const position = options.fullscreenControl === true || options.fullscreenControl === void 0 ? "top-right" : options.fullscreenControl;
712
- this.addControl(new maplibregl__default.FullscreenControl({}), position);
828
+ this.addControl(new FullscreenControl({}), position);
713
829
  }
714
830
  }));
831
+ let loadEventTriggered = false;
832
+ let terrainEventTriggered = false;
833
+ let terrainEventData = null;
834
+ this.once("load", (_) => {
835
+ loadEventTriggered = true;
836
+ if (terrainEventTriggered) {
837
+ this.fire("loadWithTerrain", terrainEventData);
838
+ }
839
+ });
840
+ const terrainCallback = (evt) => {
841
+ if (!evt.terrain)
842
+ return;
843
+ terrainEventTriggered = true;
844
+ terrainEventData = {
845
+ type: "loadWithTerrain",
846
+ target: this,
847
+ terrain: evt.terrain
848
+ };
849
+ this.off("terrain", terrainCallback);
850
+ if (loadEventTriggered) {
851
+ this.fire("loadWithTerrain", terrainEventData);
852
+ }
853
+ };
854
+ this.on("terrain", terrainCallback);
715
855
  if (options.terrain) {
716
856
  this.enableTerrain(
717
- (_b = options.terrainExaggeration) != null ? _b : this.terrainExaggeration
857
+ (_c = options.terrainExaggeration) != null ? _c : this.terrainExaggeration
718
858
  );
719
859
  }
720
860
  }
861
+ /**
862
+ * Awaits for _this_ Map instance to be "loaded" and returns a Promise to the Map.
863
+ * If _this_ Map instance is already loaded, the Promise is resolved directly,
864
+ * otherwise, it is resolved as a result of the "load" event.
865
+ * @returns
866
+ */
867
+ onLoadAsync() {
868
+ return __async(this, null, function* () {
869
+ return new Promise((resolve, reject) => {
870
+ if (this.loaded()) {
871
+ return resolve(this);
872
+ }
873
+ this.once("load", (_) => {
874
+ resolve(this);
875
+ });
876
+ });
877
+ });
878
+ }
879
+ /**
880
+ * Awaits for _this_ Map instance to be "loaded" as well as with terrain being non-null for the first time
881
+ * and returns a Promise to the Map.
882
+ * If _this_ Map instance is already loaded with terrain, the Promise is resolved directly,
883
+ * otherwise, it is resolved as a result of the "loadWithTerrain" event.
884
+ * @returns
885
+ */
886
+ onLoadWithTerrainAsync() {
887
+ return __async(this, null, function* () {
888
+ return new Promise((resolve, reject) => {
889
+ if (this.loaded() && this.terrain) {
890
+ return resolve(this);
891
+ }
892
+ this.once("loadWithTerrain", (_) => {
893
+ resolve(this);
894
+ });
895
+ });
896
+ });
897
+ }
898
+ /**
899
+ * Update the style of the map.
900
+ * Can be:
901
+ * - a full style URL (possibly with API key)
902
+ * - a shorthand with only the MapTIler style name (eg. `"streets-v2"`)
903
+ * - a longer form with the prefix `"maptiler://"` (eg. `"maptiler://streets-v2"`)
904
+ * @param style
905
+ * @param options
906
+ * @returns
907
+ */
721
908
  setStyle(style, options) {
722
909
  return super.setStyle(styleToStyle(style), options);
723
910
  }
911
+ /**
912
+ * Define the primary language of the map. Note that not all the languages shorthands provided are available.
913
+ * This function is a short for `.setPrimaryLanguage()`
914
+ * @param language
915
+ */
724
916
  setLanguage(language = defaults.primaryLanguage) {
725
917
  if (language === Language.AUTO) {
726
918
  return this.setLanguage(getBrowserLanguage());
727
919
  }
728
920
  this.setPrimaryLanguage(language);
729
921
  }
922
+ /**
923
+ * Define the primary language of the map. Note that not all the languages shorthands provided are available.
924
+ * @param language
925
+ */
730
926
  setPrimaryLanguage(language = defaults.primaryLanguage) {
731
927
  if (!isLanguageSupported(language)) {
732
928
  return;
@@ -801,6 +997,11 @@ class Map extends maplibregl__default.Map {
801
997
  }
802
998
  });
803
999
  }
1000
+ /**
1001
+ * Define the secondary language of the map. Note that this is not supported by all the map styles
1002
+ * Note that most styles do not allow a secondary language and this function only works if the style allows (no force adding)
1003
+ * @param language
1004
+ */
804
1005
  setSecondaryLanguage(language = defaults.secondaryLanguage) {
805
1006
  if (!isLanguageSupported(language)) {
806
1007
  return;
@@ -865,38 +1066,111 @@ class Map extends maplibregl__default.Map {
865
1066
  }
866
1067
  });
867
1068
  }
1069
+ /**
1070
+ * Get the primary language
1071
+ * @returns
1072
+ */
868
1073
  getPrimaryLanguage() {
869
1074
  return this.primaryLanguage;
870
1075
  }
1076
+ /**
1077
+ * Get the secondary language
1078
+ * @returns
1079
+ */
871
1080
  getSecondaryLanguage() {
872
1081
  return this.secondaryLanguage;
873
1082
  }
1083
+ /**
1084
+ * Get the exaggeration factor applied to the terrain
1085
+ * @returns
1086
+ */
874
1087
  getTerrainExaggeration() {
875
1088
  return this.terrainExaggeration;
876
1089
  }
1090
+ /**
1091
+ * Know if terrian is enabled or not
1092
+ * @returns
1093
+ */
877
1094
  hasTerrain() {
878
1095
  return this.isTerrainEnabled;
879
1096
  }
1097
+ growTerrain(exaggeration, durationMs = 1e3) {
1098
+ if (!this.terrain) {
1099
+ return;
1100
+ }
1101
+ const startTime = performance.now();
1102
+ const currentExaggeration = this.terrain.exaggeration;
1103
+ const deltaExaggeration = exaggeration - currentExaggeration;
1104
+ const updateExaggeration = () => {
1105
+ if (!this.terrain) {
1106
+ return;
1107
+ }
1108
+ if (this.terrainFlattening) {
1109
+ return;
1110
+ }
1111
+ const positionInLoop = (performance.now() - startTime) / durationMs;
1112
+ if (positionInLoop < 0.99) {
1113
+ const exaggerationFactor = 1 - Math.pow(1 - positionInLoop, 4);
1114
+ const newExaggeration = currentExaggeration + exaggerationFactor * deltaExaggeration;
1115
+ this.terrain.exaggeration = newExaggeration;
1116
+ requestAnimationFrame(updateExaggeration);
1117
+ } else {
1118
+ this.terrainGrowing = false;
1119
+ this.terrainFlattening = false;
1120
+ this.terrain.exaggeration = exaggeration;
1121
+ }
1122
+ this.triggerRepaint();
1123
+ };
1124
+ this.terrainGrowing = true;
1125
+ this.terrainFlattening = false;
1126
+ requestAnimationFrame(updateExaggeration);
1127
+ }
1128
+ /**
1129
+ * Enables the 3D terrain visualization
1130
+ * @param exaggeration
1131
+ * @returns
1132
+ */
880
1133
  enableTerrain(exaggeration = this.terrainExaggeration) {
881
1134
  if (exaggeration < 0) {
882
1135
  console.warn("Terrain exaggeration cannot be negative.");
883
1136
  return;
884
1137
  }
885
- const terrainInfo = this.getTerrain();
1138
+ const dataEventTerrainGrow = (evt) => __async(this, null, function* () {
1139
+ if (!this.terrain) {
1140
+ return;
1141
+ }
1142
+ if (evt.type !== "data" || evt.dataType !== "source" || !("source" in evt)) {
1143
+ return;
1144
+ }
1145
+ if (evt.sourceId !== "maptiler-terrain") {
1146
+ return;
1147
+ }
1148
+ const source = evt.source;
1149
+ if (source.type !== "raster-dem") {
1150
+ return;
1151
+ }
1152
+ if (!evt.isSourceLoaded) {
1153
+ return;
1154
+ }
1155
+ this.off("data", dataEventTerrainGrow);
1156
+ this.growTerrain(exaggeration);
1157
+ });
886
1158
  const addTerrain = () => {
887
1159
  this.isTerrainEnabled = true;
888
1160
  this.terrainExaggeration = exaggeration;
1161
+ this.on("data", dataEventTerrainGrow);
889
1162
  this.addSource(defaults.terrainSourceId, {
890
1163
  type: "raster-dem",
891
1164
  url: defaults.terrainSourceURL
892
1165
  });
893
1166
  this.setTerrain({
894
1167
  source: defaults.terrainSourceId,
895
- exaggeration
1168
+ exaggeration: 0
896
1169
  });
897
1170
  };
898
- if (terrainInfo) {
899
- this.setTerrain(__spreadProps(__spreadValues({}, terrainInfo), { exaggeration }));
1171
+ if (this.getTerrain()) {
1172
+ this.isTerrainEnabled = true;
1173
+ this.growTerrain(exaggeration);
900
1174
  return;
901
1175
  }
902
1176
  if (this.loaded() || this.isTerrainEnabled) {
@@ -910,16 +1184,68 @@ class Map extends maplibregl__default.Map {
910
1184
  });
911
1185
  }
912
1186
  }
1187
+ /**
1188
+ * Disable the 3D terrain visualization
1189
+ */
913
1190
  disableTerrain() {
1191
+ if (!this.terrain) {
1192
+ return;
1193
+ }
914
1194
  this.isTerrainEnabled = false;
915
- this.setTerrain(null);
916
- if (this.getSource(defaults.terrainSourceId)) {
917
- this.removeSource(defaults.terrainSourceId);
1195
+ const animationLoopDuration = 1 * 1e3;
1196
+ const startTime = performance.now();
1197
+ const currentExaggeration = this.terrain.exaggeration;
1198
+ const updateExaggeration = () => {
1199
+ if (!this.terrain) {
1200
+ return;
1201
+ }
1202
+ if (this.terrainGrowing) {
1203
+ return;
1204
+ }
1205
+ const positionInLoop = (performance.now() - startTime) / animationLoopDuration;
1206
+ if (positionInLoop < 0.99) {
1207
+ const exaggerationFactor = Math.pow(1 - positionInLoop, 4);
1208
+ const newExaggeration = currentExaggeration * exaggerationFactor;
1209
+ this.terrain.exaggeration = newExaggeration;
1210
+ requestAnimationFrame(updateExaggeration);
1211
+ } else {
1212
+ this.terrain.exaggeration = 0;
1213
+ this.terrainGrowing = false;
1214
+ this.terrainFlattening = false;
1215
+ this.setTerrain(null);
1216
+ if (this.getSource(defaults.terrainSourceId)) {
1217
+ this.removeSource(defaults.terrainSourceId);
1218
+ }
1219
+ }
1220
+ this.triggerRepaint();
1221
+ };
1222
+ this.terrainGrowing = false;
1223
+ this.terrainFlattening = true;
1224
+ requestAnimationFrame(updateExaggeration);
1225
+ }
1226
+ /**
1227
+ * Sets the 3D terrain exageration factor.
1228
+ * If the terrain was not enabled prior to the call of this method,
1229
+ * the method `.enableTerrain()` will be called.
1230
+ * If `animate` is `true`, the terrain transformation will be animated in the span of 1 second.
1231
+ * If `animate` is `false`, no animated transition to the newly defined exaggeration.
1232
+ * @param exaggeration
1233
+ * @param animate
1234
+ */
1235
+ setTerrainExaggeration(exaggeration, animate = true) {
1236
+ if (!animate && this.terrain) {
1237
+ this.terrainExaggeration = exaggeration;
1238
+ this.terrain.exaggeration = exaggeration;
1239
+ this.triggerRepaint();
1240
+ } else {
1241
+ this.enableTerrain(exaggeration);
918
1242
  }
919
1243
  }
920
- setTerrainExaggeration(exaggeration) {
921
- this.enableTerrain(exaggeration);
922
- }
1244
+ /**
1245
+ * Perform an action when the style is ready. It could be at the moment of calling this method
1246
+ * or later.
1247
+ * @param cb
1248
+ */
923
1249
  onStyleReady(cb) {
924
1250
  if (this.isStyleLoaded()) {
925
1251
  cb();
@@ -960,14 +1286,91 @@ class Map extends maplibregl__default.Map {
960
1286
  hashBin[4] = this.getBearing();
961
1287
  return Base64.fromUint8Array(new Uint8Array(hashBin.buffer));
962
1288
  }
1289
+ /**
1290
+ * Get the SDK config object.
1291
+ * This is convenient to dispatch the SDK configuration to externally built layers
1292
+ * that do not directly have access to the SDK configuration but do have access to a Map instance.
1293
+ * @returns
1294
+ */
963
1295
  getSdkConfig() {
964
1296
  return config;
965
1297
  }
1298
+ /**
1299
+ * Get the MapTiler session ID. Convenient to dispatch to externaly built component
1300
+ * that do not directly have access to the SDK configuration but do have access to a Map instance.
1301
+ * @returns
1302
+ */
966
1303
  getMaptilerSessionId() {
967
1304
  return MAPTILER_SESSION_ID;
968
1305
  }
969
1306
  }
970
1307
 
1308
+ class Marker extends maplibregl__default.Marker {
1309
+ addTo(map) {
1310
+ return super.addTo(map);
1311
+ }
1312
+ }
1313
+
1314
+ class Popup extends maplibregl__default.Popup {
1315
+ addTo(map) {
1316
+ return super.addTo(map);
1317
+ }
1318
+ }
1319
+
1320
+ class Style extends maplibregl__default.Style {
1321
+ constructor(map, options = {}) {
1322
+ super(map, options);
1323
+ }
1324
+ }
1325
+
1326
+ class CanvasSource extends maplibregl__default.CanvasSource {
1327
+ onAdd(map) {
1328
+ super.onAdd(map);
1329
+ }
1330
+ }
1331
+
1332
+ class GeoJSONSource extends maplibregl__default.GeoJSONSource {
1333
+ onAdd(map) {
1334
+ super.onAdd(map);
1335
+ }
1336
+ }
1337
+
1338
+ class ImageSource extends maplibregl__default.ImageSource {
1339
+ onAdd(map) {
1340
+ super.onAdd(map);
1341
+ }
1342
+ }
1343
+
1344
+ class RasterTileSource extends maplibregl__default.RasterTileSource {
1345
+ onAdd(map) {
1346
+ super.onAdd(map);
1347
+ }
1348
+ }
1349
+
1350
+ class RasterDEMTileSource extends maplibregl__default.RasterDEMTileSource {
1351
+ onAdd(map) {
1352
+ super.onAdd(map);
1353
+ }
1354
+ }
1355
+
1356
+ class VectorTileSource extends maplibregl__default.VectorTileSource {
1357
+ onAdd(map) {
1358
+ super.onAdd(map);
1359
+ }
1360
+ }
1361
+
1362
+ class VideoSource extends maplibregl__default.VideoSource {
1363
+ onAdd(map) {
1364
+ super.onAdd(map);
1365
+ }
1366
+ }
1367
+
1368
+ class TerrainControl extends maplibregl__default.TerrainControl {
1369
+ onAdd(map) {
1370
+ return super.onAdd(map);
1371
+ }
1372
+ }
1373
+
971
1374
  class Point {
972
1375
  constructor(x, y) {
973
1376
  this.x = x;
@@ -1043,71 +1446,205 @@ class Point {
1043
1446
  this.y = Math.round(this.y);
1044
1447
  return this;
1045
1448
  }
1449
+ /**
1450
+ * Clone this point, returning a new point that can be modified
1451
+ * without affecting the old one.
1452
+ * @return {Point} the clone
1453
+ */
1046
1454
  clone() {
1047
1455
  return new Point(this.x, this.y);
1048
1456
  }
1457
+ /**
1458
+ * Add this point's x & y coordinates to another point,
1459
+ * yielding a new point.
1460
+ * @param {Point} p the other point
1461
+ * @return {Point} output point
1462
+ */
1049
1463
  add(p) {
1050
1464
  return this.clone()._add(p);
1051
1465
  }
1466
+ /**
1467
+ * Subtract this point's x & y coordinates to from point,
1468
+ * yielding a new point.
1469
+ * @param {Point} p the other point
1470
+ * @return {Point} output point
1471
+ */
1052
1472
  sub(p) {
1053
1473
  return this.clone()._sub(p);
1054
1474
  }
1475
+ /**
1476
+ * Multiply this point's x & y coordinates by point,
1477
+ * yielding a new point.
1478
+ * @param {Point} p the other point
1479
+ * @return {Point} output point
1480
+ */
1055
1481
  multByPoint(p) {
1056
1482
  return this.clone()._multByPoint(p);
1057
1483
  }
1484
+ /**
1485
+ * Divide this point's x & y coordinates by point,
1486
+ * yielding a new point.
1487
+ * @param {Point} p the other point
1488
+ * @return {Point} output point
1489
+ */
1058
1490
  divByPoint(p) {
1059
1491
  return this.clone()._divByPoint(p);
1060
1492
  }
1493
+ /**
1494
+ * Multiply this point's x & y coordinates by a factor,
1495
+ * yielding a new point.
1496
+ * @param {Number} k factor
1497
+ * @return {Point} output point
1498
+ */
1061
1499
  mult(k) {
1062
1500
  return this.clone()._mult(k);
1063
1501
  }
1502
+ /**
1503
+ * Divide this point's x & y coordinates by a factor,
1504
+ * yielding a new point.
1505
+ * @param {Point} k factor
1506
+ * @return {Point} output point
1507
+ */
1064
1508
  div(k) {
1065
1509
  return this.clone()._div(k);
1066
1510
  }
1511
+ /**
1512
+ * Rotate this point around the 0, 0 origin by an angle a,
1513
+ * given in radians
1514
+ * @param {Number} a angle to rotate around, in radians
1515
+ * @return {Point} output point
1516
+ */
1067
1517
  rotate(a) {
1068
1518
  return this.clone()._rotate(a);
1069
1519
  }
1520
+ /**
1521
+ * Rotate this point around p point by an angle a,
1522
+ * given in radians
1523
+ * @param {Number} a angle to rotate around, in radians
1524
+ * @param {Point} p Point to rotate around
1525
+ * @return {Point} output point
1526
+ */
1070
1527
  rotateAround(a, p) {
1071
1528
  return this.clone()._rotateAround(a, p);
1072
1529
  }
1530
+ /**
1531
+ * Multiply this point by a 4x1 transformation matrix
1532
+ * @param {Array<Number>} m transformation matrix
1533
+ * @return {Point} output point
1534
+ */
1073
1535
  matMult(m) {
1074
1536
  return this.clone()._matMult(m);
1075
1537
  }
1538
+ /**
1539
+ * Calculate this point but as a unit vector from 0, 0, meaning
1540
+ * that the distance from the resulting point to the 0, 0
1541
+ * coordinate will be equal to 1 and the angle from the resulting
1542
+ * point to the 0, 0 coordinate will be the same as before.
1543
+ * @return {Point} unit vector point
1544
+ */
1076
1545
  unit() {
1077
1546
  return this.clone()._unit();
1078
1547
  }
1548
+ /**
1549
+ * Compute a perpendicular point, where the new y coordinate
1550
+ * is the old x coordinate and the new x coordinate is the old y
1551
+ * coordinate multiplied by -1
1552
+ * @return {Point} perpendicular point
1553
+ */
1079
1554
  perp() {
1080
1555
  return this.clone()._perp();
1081
1556
  }
1557
+ /**
1558
+ * Return a version of this point with the x & y coordinates
1559
+ * rounded to integers.
1560
+ * @return {Point} rounded point
1561
+ */
1082
1562
  round() {
1083
1563
  return this.clone()._round();
1084
1564
  }
1565
+ /**
1566
+ * Return the magnitude of this point: this is the Euclidean
1567
+ * distance from the 0, 0 coordinate to this point's x and y
1568
+ * coordinates.
1569
+ * @return {Number} magnitude
1570
+ */
1085
1571
  mag() {
1086
1572
  return Math.sqrt(this.x * this.x + this.y * this.y);
1087
1573
  }
1574
+ /**
1575
+ * Judge whether this point is equal to another point, returning
1576
+ * true or false.
1577
+ * @param {Point} other the other point
1578
+ * @return {boolean} whether the points are equal
1579
+ */
1088
1580
  equals(other) {
1089
1581
  return this.x === other.x && this.y === other.y;
1090
1582
  }
1583
+ /**
1584
+ * Calculate the distance from this point to another point
1585
+ * @param {Point} p the other point
1586
+ * @return {Number} distance
1587
+ */
1091
1588
  dist(p) {
1092
1589
  return Math.sqrt(this.distSqr(p));
1093
1590
  }
1591
+ /**
1592
+ * Calculate the distance from this point to another point,
1593
+ * without the square root step. Useful if you're comparing
1594
+ * relative distances.
1595
+ * @param {Point} p the other point
1596
+ * @return {Number} distance
1597
+ */
1094
1598
  distSqr(p) {
1095
1599
  const dx = p.x - this.x;
1096
1600
  const dy = p.y - this.y;
1097
1601
  return dx * dx + dy * dy;
1098
1602
  }
1603
+ /**
1604
+ * Get the angle from the 0, 0 coordinate to this point, in radians
1605
+ * coordinates.
1606
+ * @return {Number} angle
1607
+ */
1099
1608
  angle() {
1100
1609
  return Math.atan2(this.y, this.x);
1101
1610
  }
1611
+ /**
1612
+ * Get the angle from this point to another point, in radians
1613
+ * @param {Point} b the other point
1614
+ * @return {Number} angle
1615
+ */
1102
1616
  angleTo(b) {
1103
1617
  return Math.atan2(this.y - b.y, this.x - b.x);
1104
1618
  }
1619
+ /**
1620
+ * Get the angle between this point and another point, in radians
1621
+ * @param {Point} b the other point
1622
+ * @return {Number} angle
1623
+ */
1105
1624
  angleWith(b) {
1106
1625
  return this.angleWithSep(b.x, b.y);
1107
1626
  }
1627
+ /*
1628
+ * Find the angle of the two vectors, solving the formula for
1629
+ * the cross product a x b = |a||b|sin(θ) for θ.
1630
+ * @param {Number} x the x-coordinate
1631
+ * @param {Number} y the y-coordinate
1632
+ * @return {Number} the angle in radians
1633
+ */
1108
1634
  angleWithSep(x, y) {
1109
1635
  return Math.atan2(this.x * y - this.y * x, this.x * x + this.y * y);
1110
1636
  }
1637
+ /**
1638
+ * Construct a point from an array if necessary, otherwise if the input
1639
+ * is already a Point, or an unknown type, return it unchanged
1640
+ * @param {Array<number> | Point} a any kind of input value
1641
+ * @return {Point} constructed point, or passed-through value.
1642
+ * @example
1643
+ * // this
1644
+ * var point = Point.convert([0, 1]);
1645
+ * // is equivalent to
1646
+ * var point = new Point(0, 1);
1647
+ */
1111
1648
  static convert(a) {
1112
1649
  if (a instanceof Point) {
1113
1650
  return a;
@@ -1123,38 +1660,38 @@ const {
1123
1660
  supported,
1124
1661
  setRTLTextPlugin,
1125
1662
  getRTLTextPluginStatus,
1126
- NavigationControl,
1127
- GeolocateControl,
1128
- AttributionControl,
1129
- LogoControl,
1130
- ScaleControl,
1131
- FullscreenControl,
1132
- TerrainControl,
1133
- Popup,
1134
- Marker,
1135
- Style,
1136
1663
  LngLat,
1137
1664
  LngLatBounds,
1138
1665
  MercatorCoordinate,
1139
1666
  Evented,
1140
1667
  AJAXError,
1141
- CanvasSource,
1142
- GeoJSONSource,
1143
- ImageSource,
1144
- RasterDEMTileSource,
1145
- RasterTileSource,
1146
- VectorTileSource,
1147
- VideoSource,
1148
1668
  prewarm,
1149
1669
  clearPrewarmedResources,
1150
1670
  version,
1151
1671
  workerCount,
1152
1672
  maxParallelImageRequests,
1153
- clearStorage,
1154
1673
  workerUrl,
1155
1674
  addProtocol,
1156
1675
  removeProtocol
1157
1676
  } = maplibregl__default;
1677
+ const MapMLGL = maplibregl__default.Map;
1678
+ const MarkerMLGL = maplibregl__default.Marker;
1679
+ const PopupMLGL = maplibregl__default.Popup;
1680
+ const StyleMLGL = maplibregl__default.Style;
1681
+ const CanvasSourceMLGL = maplibregl__default.CanvasSource;
1682
+ const GeoJSONSourceMLGL = maplibregl__default.GeoJSONSource;
1683
+ const ImageSourceMLGL = maplibregl__default.ImageSource;
1684
+ const RasterTileSourceMLGL = maplibregl__default.RasterTileSource;
1685
+ const RasterDEMTileSourceMLGL = maplibregl__default.RasterDEMTileSource;
1686
+ const VectorTileSourceMLGL = maplibregl__default.VectorTileSource;
1687
+ const VideoSourceMLGL = maplibregl__default.VideoSource;
1688
+ maplibregl__default.NavigationControl;
1689
+ maplibregl__default.GeolocateControl;
1690
+ maplibregl__default.AttributionControl;
1691
+ maplibregl__default.LogoControl;
1692
+ maplibregl__default.ScaleControl;
1693
+ maplibregl__default.FullscreenControl;
1694
+ maplibregl__default.TerrainControl;
1158
1695
 
1159
- export { AJAXError, AttributionControl, CanvasSource, Evented, FullscreenControl, GeoJSONSource, GeolocateControl, GeolocationType, ImageSource, Language, LngLat, LngLatBounds, LogoControl, Map, MaptilerGeolocateControl, MaptilerLogoControl, MaptilerTerrainControl, Marker, MercatorCoordinate, NavigationControl, Point, Popup, RasterDEMTileSource, RasterTileSource, ScaleControl, SdkConfig, Style, TerrainControl, VectorTileSource, VideoSource, addProtocol, clearPrewarmedResources, clearStorage, config, getRTLTextPluginStatus, maxParallelImageRequests, prewarm, removeProtocol, setRTLTextPlugin, supported, version, workerCount, workerUrl };
1696
+ export { AJAXError, AttributionControl, CanvasSource, CanvasSourceMLGL, Evented, FullscreenControl, GeoJSONSource, GeoJSONSourceMLGL, GeolocateControl, GeolocationType, ImageSource, ImageSourceMLGL, Language, LngLat, LngLatBounds, LogoControl, Map, MapMLGL, MaptilerGeolocateControl, MaptilerLogoControl, 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, supported, version, workerCount, workerUrl };
1160
1697
  //# sourceMappingURL=maptiler-sdk.mjs.map