@maptiler/sdk 1.0.9 → 1.0.11

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
  }
@@ -196,6 +246,7 @@ function enableRTL() {
196
246
  defaults.rtlPluginURL,
197
247
  null,
198
248
  true
249
+ // Lazy load the plugin
199
250
  );
200
251
  }
201
252
  }
@@ -325,11 +376,17 @@ class MaptilerNavigationControl extends NavigationControl {
325
376
  }
326
377
  });
327
378
  }
379
+ /**
380
+ * Overloading: the button now stores its click callback so that we can later on delete it and replace it
381
+ */
328
382
  _createButton(className, fn) {
329
383
  const button = super._createButton(className, fn);
330
384
  button.clickFunction = fn;
331
385
  return button;
332
386
  }
387
+ /**
388
+ * Overloading: Limit how flat the compass icon can get
389
+ */
333
390
  _rotateCompassArrow() {
334
391
  const rotate = this.options.visualizePitch ? `scale(${Math.min(
335
392
  1.5,
@@ -371,6 +428,12 @@ class MaptilerGeolocateControl extends GeolocateControl {
371
428
  super(...arguments);
372
429
  this.lastUpdatedCenter = new LngLat$1(0, 0);
373
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
+ */
374
437
  _updateCamera(position) {
375
438
  const center = new LngLat$1(
376
439
  position.coords.longitude,
@@ -389,6 +452,7 @@ class MaptilerGeolocateControl extends GeolocateControl {
389
452
  }
390
453
  this._map.fitBounds(center.toBounds(radius), options, {
391
454
  geolocateSource: true
455
+ // tag this camera change so it won't cause the control to change to background state
392
456
  });
393
457
  let hasFittingBeenDisrupted = false;
394
458
  const flagFittingDisruption = () => {
@@ -572,7 +636,7 @@ const GeolocationType = {
572
636
  };
573
637
  class Map extends maplibregl__default.Map {
574
638
  constructor(options) {
575
- var _a, _b;
639
+ var _a, _b, _c;
576
640
  if (options.apiKey) {
577
641
  config.apiKey = options.apiKey;
578
642
  }
@@ -614,8 +678,11 @@ class Map extends maplibregl__default.Map {
614
678
  this.terrainExaggeration = 1;
615
679
  this.primaryLanguage = null;
616
680
  this.secondaryLanguage = null;
681
+ this.terrainGrowing = false;
682
+ this.terrainFlattening = false;
617
683
  this.primaryLanguage = (_a = options.language) != null ? _a : config.primaryLanguage;
618
684
  this.secondaryLanguage = config.secondaryLanguage;
685
+ this.terrainExaggeration = (_b = options.terrainExaggeration) != null ? _b : this.terrainExaggeration;
619
686
  this.once("styledata", () => __async(this, null, function* () {
620
687
  if (!options.geolocate) {
621
688
  return;
@@ -646,20 +713,35 @@ class Map extends maplibregl__default.Map {
646
713
  });
647
714
  if (locationResult.state === "granted") {
648
715
  navigator.geolocation.getCurrentPosition(
716
+ // success callback
649
717
  (data) => {
650
718
  if (ipLocatedCameraHash !== this.getCameraHash()) {
651
719
  return;
652
720
  }
653
- this.easeTo({
654
- center: [data.coords.longitude, data.coords.latitude],
655
- zoom: options.zoom || 12,
656
- duration: 2e3
657
- });
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
+ }
658
736
  },
737
+ // error callback
659
738
  null,
739
+ // options
660
740
  {
661
741
  maximumAge: 24 * 3600 * 1e3,
742
+ // a day in millisec
662
743
  timeout: 5e3,
744
+ // milliseconds
663
745
  enableHighAccuracy: false
664
746
  }
665
747
  );
@@ -720,6 +802,7 @@ class Map extends maplibregl__default.Map {
720
802
  if (options.geolocateControl !== false) {
721
803
  const position = options.geolocateControl === true || options.geolocateControl === void 0 ? "top-right" : options.geolocateControl;
722
804
  this.addControl(
805
+ // new maplibregl.GeolocateControl({
723
806
  new MaptilerGeolocateControl({
724
807
  positionOptions: {
725
808
  enableHighAccuracy: true,
@@ -745,21 +828,101 @@ class Map extends maplibregl__default.Map {
745
828
  this.addControl(new FullscreenControl({}), position);
746
829
  }
747
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);
748
855
  if (options.terrain) {
749
856
  this.enableTerrain(
750
- (_b = options.terrainExaggeration) != null ? _b : this.terrainExaggeration
857
+ (_c = options.terrainExaggeration) != null ? _c : this.terrainExaggeration
751
858
  );
752
859
  }
753
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
+ */
754
908
  setStyle(style, options) {
755
909
  return super.setStyle(styleToStyle(style), options);
756
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
+ */
757
916
  setLanguage(language = defaults.primaryLanguage) {
758
917
  if (language === Language.AUTO) {
759
918
  return this.setLanguage(getBrowserLanguage());
760
919
  }
761
920
  this.setPrimaryLanguage(language);
762
921
  }
922
+ /**
923
+ * Define the primary language of the map. Note that not all the languages shorthands provided are available.
924
+ * @param language
925
+ */
763
926
  setPrimaryLanguage(language = defaults.primaryLanguage) {
764
927
  if (!isLanguageSupported(language)) {
765
928
  return;
@@ -834,6 +997,11 @@ class Map extends maplibregl__default.Map {
834
997
  }
835
998
  });
836
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
+ */
837
1005
  setSecondaryLanguage(language = defaults.secondaryLanguage) {
838
1006
  if (!isLanguageSupported(language)) {
839
1007
  return;
@@ -898,38 +1066,111 @@ class Map extends maplibregl__default.Map {
898
1066
  }
899
1067
  });
900
1068
  }
1069
+ /**
1070
+ * Get the primary language
1071
+ * @returns
1072
+ */
901
1073
  getPrimaryLanguage() {
902
1074
  return this.primaryLanguage;
903
1075
  }
1076
+ /**
1077
+ * Get the secondary language
1078
+ * @returns
1079
+ */
904
1080
  getSecondaryLanguage() {
905
1081
  return this.secondaryLanguage;
906
1082
  }
1083
+ /**
1084
+ * Get the exaggeration factor applied to the terrain
1085
+ * @returns
1086
+ */
907
1087
  getTerrainExaggeration() {
908
1088
  return this.terrainExaggeration;
909
1089
  }
1090
+ /**
1091
+ * Know if terrian is enabled or not
1092
+ * @returns
1093
+ */
910
1094
  hasTerrain() {
911
1095
  return this.isTerrainEnabled;
912
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
+ */
913
1133
  enableTerrain(exaggeration = this.terrainExaggeration) {
914
1134
  if (exaggeration < 0) {
915
1135
  console.warn("Terrain exaggeration cannot be negative.");
916
1136
  return;
917
1137
  }
918
- 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
+ });
919
1158
  const addTerrain = () => {
920
1159
  this.isTerrainEnabled = true;
921
1160
  this.terrainExaggeration = exaggeration;
1161
+ this.on("data", dataEventTerrainGrow);
922
1162
  this.addSource(defaults.terrainSourceId, {
923
1163
  type: "raster-dem",
924
1164
  url: defaults.terrainSourceURL
925
1165
  });
926
1166
  this.setTerrain({
927
1167
  source: defaults.terrainSourceId,
928
- exaggeration
1168
+ exaggeration: 0
929
1169
  });
930
1170
  };
931
- if (terrainInfo) {
932
- this.setTerrain(__spreadProps(__spreadValues({}, terrainInfo), { exaggeration }));
1171
+ if (this.getTerrain()) {
1172
+ this.isTerrainEnabled = true;
1173
+ this.growTerrain(exaggeration);
933
1174
  return;
934
1175
  }
935
1176
  if (this.loaded() || this.isTerrainEnabled) {
@@ -943,16 +1184,68 @@ class Map extends maplibregl__default.Map {
943
1184
  });
944
1185
  }
945
1186
  }
1187
+ /**
1188
+ * Disable the 3D terrain visualization
1189
+ */
946
1190
  disableTerrain() {
1191
+ if (!this.terrain) {
1192
+ return;
1193
+ }
947
1194
  this.isTerrainEnabled = false;
948
- this.setTerrain(null);
949
- if (this.getSource(defaults.terrainSourceId)) {
950
- 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);
951
1242
  }
952
1243
  }
953
- setTerrainExaggeration(exaggeration) {
954
- this.enableTerrain(exaggeration);
955
- }
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
+ */
956
1249
  onStyleReady(cb) {
957
1250
  if (this.isStyleLoaded()) {
958
1251
  cb();
@@ -993,9 +1286,20 @@ class Map extends maplibregl__default.Map {
993
1286
  hashBin[4] = this.getBearing();
994
1287
  return Base64.fromUint8Array(new Uint8Array(hashBin.buffer));
995
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
+ */
996
1295
  getSdkConfig() {
997
1296
  return config;
998
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
+ */
999
1303
  getMaptilerSessionId() {
1000
1304
  return MAPTILER_SESSION_ID;
1001
1305
  }
@@ -1142,71 +1446,205 @@ class Point {
1142
1446
  this.y = Math.round(this.y);
1143
1447
  return this;
1144
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
+ */
1145
1454
  clone() {
1146
1455
  return new Point(this.x, this.y);
1147
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
+ */
1148
1463
  add(p) {
1149
1464
  return this.clone()._add(p);
1150
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
+ */
1151
1472
  sub(p) {
1152
1473
  return this.clone()._sub(p);
1153
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
+ */
1154
1481
  multByPoint(p) {
1155
1482
  return this.clone()._multByPoint(p);
1156
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
+ */
1157
1490
  divByPoint(p) {
1158
1491
  return this.clone()._divByPoint(p);
1159
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
+ */
1160
1499
  mult(k) {
1161
1500
  return this.clone()._mult(k);
1162
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
+ */
1163
1508
  div(k) {
1164
1509
  return this.clone()._div(k);
1165
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
+ */
1166
1517
  rotate(a) {
1167
1518
  return this.clone()._rotate(a);
1168
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
+ */
1169
1527
  rotateAround(a, p) {
1170
1528
  return this.clone()._rotateAround(a, p);
1171
1529
  }
1530
+ /**
1531
+ * Multiply this point by a 4x1 transformation matrix
1532
+ * @param {Array<Number>} m transformation matrix
1533
+ * @return {Point} output point
1534
+ */
1172
1535
  matMult(m) {
1173
1536
  return this.clone()._matMult(m);
1174
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
+ */
1175
1545
  unit() {
1176
1546
  return this.clone()._unit();
1177
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
+ */
1178
1554
  perp() {
1179
1555
  return this.clone()._perp();
1180
1556
  }
1557
+ /**
1558
+ * Return a version of this point with the x & y coordinates
1559
+ * rounded to integers.
1560
+ * @return {Point} rounded point
1561
+ */
1181
1562
  round() {
1182
1563
  return this.clone()._round();
1183
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
+ */
1184
1571
  mag() {
1185
1572
  return Math.sqrt(this.x * this.x + this.y * this.y);
1186
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
+ */
1187
1580
  equals(other) {
1188
1581
  return this.x === other.x && this.y === other.y;
1189
1582
  }
1583
+ /**
1584
+ * Calculate the distance from this point to another point
1585
+ * @param {Point} p the other point
1586
+ * @return {Number} distance
1587
+ */
1190
1588
  dist(p) {
1191
1589
  return Math.sqrt(this.distSqr(p));
1192
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
+ */
1193
1598
  distSqr(p) {
1194
1599
  const dx = p.x - this.x;
1195
1600
  const dy = p.y - this.y;
1196
1601
  return dx * dx + dy * dy;
1197
1602
  }
1603
+ /**
1604
+ * Get the angle from the 0, 0 coordinate to this point, in radians
1605
+ * coordinates.
1606
+ * @return {Number} angle
1607
+ */
1198
1608
  angle() {
1199
1609
  return Math.atan2(this.y, this.x);
1200
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
+ */
1201
1616
  angleTo(b) {
1202
1617
  return Math.atan2(this.y - b.y, this.x - b.x);
1203
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
+ */
1204
1624
  angleWith(b) {
1205
1625
  return this.angleWithSep(b.x, b.y);
1206
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
+ */
1207
1634
  angleWithSep(x, y) {
1208
1635
  return Math.atan2(this.x * y - this.y * x, this.x * x + this.y * y);
1209
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
+ */
1210
1648
  static convert(a) {
1211
1649
  if (a instanceof Point) {
1212
1650
  return a;
@@ -1232,7 +1670,6 @@ const {
1232
1670
  version,
1233
1671
  workerCount,
1234
1672
  maxParallelImageRequests,
1235
- clearStorage,
1236
1673
  workerUrl,
1237
1674
  addProtocol,
1238
1675
  removeProtocol
@@ -1256,5 +1693,5 @@ maplibregl__default.ScaleControl;
1256
1693
  maplibregl__default.FullscreenControl;
1257
1694
  maplibregl__default.TerrainControl;
1258
1695
 
1259
- 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, 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, 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, supported, version, workerCount, workerUrl };
1260
1697
  //# sourceMappingURL=maptiler-sdk.mjs.map