@maptiler/sdk 1.0.8 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,56 @@
1
1
  # Changelog
2
+ ## [v1.0.9](https://github.com/maptiler/maptiler-sdk-js/releases/tag/v1.0.9)
3
+ - FIX: if the geolocate option is missing from `Map` constructor, then it's considered `false`
4
+
5
+ - FIX: The instance types for the following MapLibre classes are now fully exported:
6
+ - `NavigationControl`
7
+ - `GeolocateControl`
8
+ - `AttributionControl`
9
+ - `LogoControl`
10
+ - `ScaleControl`
11
+ - `FullscreenControl`
12
+ - `TerrainControl`
13
+ - `Popup`
14
+ - `Marker`
15
+ - `Style`
16
+ - `LngLat`
17
+ - `LngLatBounds`
18
+ - `MercatorCoordinate`
19
+ - `Evented`
20
+ - `AJAXError`
21
+ - `CanvasSource`
22
+ - `GeoJSONSource`
23
+ - `ImageSource`
24
+ - `RasterDEMTileSource`
25
+ - `RasterTileSource`
26
+ - `VectorTileSource`
27
+ - `VideoSource`
28
+ - `MapMLGL`
29
+
30
+ - FIX: The following class have been extended to provide greater compatibility with SDK,s MapL
31
+ - `Popup`
32
+ - `Marker`
33
+ - `Style`
34
+ - `CanvasSource`
35
+ - `GeoJSONSource`
36
+ - `ImageSource`
37
+ - `RasterDEMTileSource`
38
+ - `RasterTileSource`
39
+ - `VectorTileSource`
40
+ - `VideoSource`
41
+ - `NavigationControl`
42
+ - `GeolocateControl`
43
+ - `AttributionControl`
44
+ - `LogoControl`
45
+ - `ScaleControl`
46
+ - `FullscreenControl`
47
+ - `TerrainControl`
48
+
49
+ - ADD: new styles:
50
+ - `MapStyle.STREETS.NIGHT`
51
+ - `MapStyle.WINTER.DARK`
52
+ - `MapStyle.OUTDOOR.DARK`
53
+
2
54
  ## [v1.0.8](https://github.com/maptiler/maptiler-sdk-js/releases/tag/v1.0.8)
3
55
  - FIX: Since v1.0.7, the `Map` primary language (when custom) was no longer persistant on style update.
4
56
 
@@ -1156,6 +1156,30 @@
1156
1156
  400: "Query too long / Invalid parameters",
1157
1157
  403: "Key is missing, invalid or restricted"
1158
1158
  };
1159
+ function addLanguageGeocodingOptions(searchParams, options) {
1160
+ if (options.language == void 0) {
1161
+ return;
1162
+ }
1163
+ const languages = Array.from(
1164
+ new Set(
1165
+ (Array.isArray(options.language) ? options.language : [options.language]).map(
1166
+ (lang) => lang === LanguageGeocoding.AUTO ? getAutoLanguageGeocoding() : lang
1167
+ )
1168
+ )
1169
+ ).join(",");
1170
+ searchParams.set("language", languages);
1171
+ }
1172
+ function addCommonForwardAndReverseGeocodingOptions(searchParams, options) {
1173
+ var _a;
1174
+ searchParams.set("key", (_a = options.apiKey) != null ? _a : config$1.apiKey);
1175
+ if (options.limit != void 0) {
1176
+ searchParams.set("limit", String(options.limit));
1177
+ }
1178
+ if (options.types != void 0) {
1179
+ searchParams.set("types", options.types.join(","));
1180
+ }
1181
+ addLanguageGeocodingOptions(searchParams, options);
1182
+ }
1159
1183
  function forward(_0) {
1160
1184
  return __async$3(this, arguments, function* (query, options = {}) {
1161
1185
  var _a;
@@ -1166,30 +1190,27 @@
1166
1190
  `geocoding/${encodeURIComponent(query)}.json`,
1167
1191
  defaults$1.maptilerApiURL
1168
1192
  );
1169
- endpoint.searchParams.set("key", (_a = options.apiKey) != null ? _a : config$1.apiKey);
1170
- if ("bbox" in options) {
1171
- endpoint.searchParams.set("bbox", options.bbox.join(","));
1172
- }
1173
- if ("proximity" in options) {
1174
- endpoint.searchParams.set("proximity", options.proximity.join(","));
1175
- }
1176
- if ("language" in options) {
1177
- const languages = Array.from(
1178
- new Set(
1179
- (Array.isArray(options.language) ? options.language : [options.language]).map(
1180
- (lang) => lang === LanguageGeocoding.AUTO ? getAutoLanguageGeocoding() : lang
1181
- )
1182
- )
1183
- ).join(",");
1184
- endpoint.searchParams.set("language", languages);
1193
+ const { searchParams } = endpoint;
1194
+ addCommonForwardAndReverseGeocodingOptions(searchParams, options);
1195
+ if (options.bbox != void 0) {
1196
+ searchParams.set("bbox", options.bbox.join(","));
1197
+ }
1198
+ if (options.proximity != void 0) {
1199
+ searchParams.set("proximity", options.proximity.join(","));
1200
+ }
1201
+ if (options.country != void 0) {
1202
+ searchParams.set("country", options.country.join(","));
1203
+ }
1204
+ if (options.fuzzyMatch != void 0) {
1205
+ searchParams.set("fuzzyMatch", options.fuzzyMatch ? "true" : "false");
1206
+ }
1207
+ if (options.autocomplete != void 0) {
1208
+ searchParams.set("autocomplete", options.autocomplete ? "true" : "false");
1185
1209
  }
1186
1210
  const urlWithParams = endpoint.toString();
1187
1211
  const res = yield callFetch(urlWithParams);
1188
1212
  if (!res.ok) {
1189
- throw new ServiceError(
1190
- res,
1191
- res.status in customMessages$3 ? customMessages$3[res.status] : ""
1192
- );
1213
+ throw new ServiceError(res, (_a = customMessages$3[res.status]) != null ? _a : "");
1193
1214
  }
1194
1215
  const obj = yield res.json();
1195
1216
  return obj;
@@ -1205,24 +1226,25 @@
1205
1226
  `geocoding/${position[0]},${position[1]}.json`,
1206
1227
  defaults$1.maptilerApiURL
1207
1228
  );
1208
- endpoint.searchParams.set("key", (_a = options.apiKey) != null ? _a : config$1.apiKey);
1209
- if ("language" in options) {
1210
- const languages = Array.from(
1211
- new Set(
1212
- (Array.isArray(options.language) ? options.language : [options.language]).map(
1213
- (lang) => lang === LanguageGeocoding.AUTO ? getAutoLanguageGeocoding() : lang
1214
- )
1215
- )
1216
- ).join(",");
1217
- endpoint.searchParams.set("language", languages);
1229
+ addCommonForwardAndReverseGeocodingOptions(endpoint.searchParams, options);
1230
+ const urlWithParams = endpoint.toString();
1231
+ const res = yield callFetch(urlWithParams);
1232
+ if (!res.ok) {
1233
+ throw new ServiceError(res, (_a = customMessages$3[res.status]) != null ? _a : "");
1218
1234
  }
1235
+ const obj = yield res.json();
1236
+ return obj;
1237
+ });
1238
+ }
1239
+ function byId(_0) {
1240
+ return __async$3(this, arguments, function* (id, options = {}) {
1241
+ var _a;
1242
+ const endpoint = new URL(`geocoding/${id}.json`, defaults$1.maptilerApiURL);
1243
+ addLanguageGeocodingOptions(endpoint.searchParams, options);
1219
1244
  const urlWithParams = endpoint.toString();
1220
1245
  const res = yield callFetch(urlWithParams);
1221
1246
  if (!res.ok) {
1222
- throw new ServiceError(
1223
- res,
1224
- res.status in customMessages$3 ? customMessages$3[res.status] : ""
1225
- );
1247
+ throw new ServiceError(res, (_a = customMessages$3[res.status]) != null ? _a : "");
1226
1248
  }
1227
1249
  const obj = yield res.json();
1228
1250
  return obj;
@@ -1231,6 +1253,7 @@
1231
1253
  const geocoding = {
1232
1254
  forward,
1233
1255
  reverse,
1256
+ byId,
1234
1257
  language: LanguageGeocoding
1235
1258
  };
1236
1259
 
@@ -1618,6 +1641,13 @@
1618
1641
  description: "",
1619
1642
  imageURL: ""
1620
1643
  },
1644
+ {
1645
+ id: "streets-v2-night",
1646
+ name: "Night",
1647
+ variantType: "NIGHT",
1648
+ description: "",
1649
+ imageURL: ""
1650
+ },
1621
1651
  {
1622
1652
  id: "streets-v2-pastel",
1623
1653
  name: "Pastel",
@@ -1638,6 +1668,13 @@
1638
1668
  variantType: "DEFAULT",
1639
1669
  description: "",
1640
1670
  imageURL: ""
1671
+ },
1672
+ {
1673
+ id: "outdoor-v2-dark",
1674
+ name: "Dark",
1675
+ variantType: "DARK",
1676
+ description: "",
1677
+ imageURL: ""
1641
1678
  }
1642
1679
  ]
1643
1680
  },
@@ -1648,10 +1685,17 @@
1648
1685
  variants: [
1649
1686
  {
1650
1687
  id: "winter-v2",
1651
- name: "Winter",
1688
+ name: "Default",
1652
1689
  variantType: "DEFAULT",
1653
1690
  description: "",
1654
1691
  imageURL: ""
1692
+ },
1693
+ {
1694
+ id: "winter-v2-dark",
1695
+ name: "Dark",
1696
+ variantType: "DARK",
1697
+ description: "",
1698
+ imageURL: ""
1655
1699
  }
1656
1700
  ]
1657
1701
  },
@@ -1772,6 +1816,13 @@
1772
1816
  description: "",
1773
1817
  imageURL: ""
1774
1818
  },
1819
+ {
1820
+ id: "topo-v2-dark",
1821
+ name: "Dark",
1822
+ variantType: "DARK",
1823
+ description: "",
1824
+ imageURL: ""
1825
+ },
1775
1826
  {
1776
1827
  id: "topo-v2-shiny",
1777
1828
  name: "Shiny",
@@ -2248,7 +2299,13 @@
2248
2299
  };
2249
2300
  Object.freeze(defaults);
2250
2301
 
2251
- class MaptilerLogoControl extends maplibregl.LogoControl {
2302
+ class LogoControl extends maplibregl.LogoControl {
2303
+ onAdd(map) {
2304
+ return super.onAdd(map);
2305
+ }
2306
+ }
2307
+
2308
+ class MaptilerLogoControl extends LogoControl {
2252
2309
  constructor(options = {}) {
2253
2310
  var _a, _b;
2254
2311
  super(options);
@@ -2393,7 +2450,13 @@
2393
2450
  }
2394
2451
  }
2395
2452
 
2396
- class MaptilerNavigationControl extends maplibregl.NavigationControl {
2453
+ class NavigationControl extends maplibregl.NavigationControl {
2454
+ onAdd(map) {
2455
+ return super.onAdd(map);
2456
+ }
2457
+ }
2458
+
2459
+ class MaptilerNavigationControl extends NavigationControl {
2397
2460
  constructor() {
2398
2461
  super({
2399
2462
  showCompass: true,
@@ -2433,6 +2496,12 @@
2433
2496
  }
2434
2497
  }
2435
2498
 
2499
+ class GeolocateControl extends maplibregl.GeolocateControl {
2500
+ onAdd(map) {
2501
+ return super.onAdd(map);
2502
+ }
2503
+ }
2504
+
2436
2505
  var __defProp$1 = Object.defineProperty;
2437
2506
  var __defProps$1 = Object.defineProperties;
2438
2507
  var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
@@ -2452,10 +2521,9 @@
2452
2521
  return a;
2453
2522
  };
2454
2523
  var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
2455
- const GeolocateControl$1 = maplibregl.GeolocateControl;
2456
2524
  const Marker$1 = maplibregl.Marker;
2457
2525
  const LngLat$1 = maplibregl.LngLat;
2458
- class MaptilerGeolocateControl extends GeolocateControl$1 {
2526
+ class MaptilerGeolocateControl extends GeolocateControl {
2459
2527
  constructor() {
2460
2528
  super(...arguments);
2461
2529
  this.lastUpdatedCenter = new LngLat$1(0, 0);
@@ -2597,6 +2665,24 @@
2597
2665
  }
2598
2666
  }
2599
2667
 
2668
+ class AttributionControl extends maplibregl.AttributionControl {
2669
+ onAdd(map) {
2670
+ return super.onAdd(map);
2671
+ }
2672
+ }
2673
+
2674
+ class ScaleControl extends maplibregl.ScaleControl {
2675
+ onAdd(map) {
2676
+ return super.onAdd(map);
2677
+ }
2678
+ }
2679
+
2680
+ class FullscreenControl extends maplibregl.FullscreenControl {
2681
+ onAdd(map) {
2682
+ return super.onAdd(map);
2683
+ }
2684
+ }
2685
+
2600
2686
  var __defProp = Object.defineProperty;
2601
2687
  var __defProps = Object.defineProperties;
2602
2688
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
@@ -2681,8 +2767,6 @@
2681
2767
  };
2682
2768
  }
2683
2769
  }));
2684
- this.languageShouldUpdate = false;
2685
- this.isStyleInitialized = false;
2686
2770
  this.isTerrainEnabled = false;
2687
2771
  this.terrainExaggeration = 1;
2688
2772
  this.primaryLanguage = null;
@@ -2690,7 +2774,7 @@
2690
2774
  this.primaryLanguage = (_a = options.language) != null ? _a : config.primaryLanguage;
2691
2775
  this.secondaryLanguage = config.secondaryLanguage;
2692
2776
  this.once("styledata", () => __async(this, null, function* () {
2693
- if (options.geolocate === false) {
2777
+ if (!options.geolocate) {
2694
2778
  return;
2695
2779
  }
2696
2780
  if (options.center) {
@@ -2773,14 +2857,14 @@
2773
2857
  options.logoPosition
2774
2858
  );
2775
2859
  if (options.attributionControl === false) {
2776
- this.addControl(new maplibregl.AttributionControl(options));
2860
+ this.addControl(new AttributionControl(options));
2777
2861
  }
2778
2862
  } else if (options.maptilerLogo) {
2779
2863
  this.addControl(new MaptilerLogoControl(), options.logoPosition);
2780
2864
  }
2781
2865
  if (options.scaleControl) {
2782
2866
  const position = options.scaleControl === true || options.scaleControl === void 0 ? "bottom-right" : options.scaleControl;
2783
- const scaleControl = new maplibregl.ScaleControl({ unit: config.unit });
2867
+ const scaleControl = new ScaleControl({ unit: config.unit });
2784
2868
  this.addControl(scaleControl, position);
2785
2869
  config.on("unit", (unit) => {
2786
2870
  scaleControl.setUnit(unit);
@@ -2815,7 +2899,7 @@
2815
2899
  }
2816
2900
  if (options.fullscreenControl) {
2817
2901
  const position = options.fullscreenControl === true || options.fullscreenControl === void 0 ? "top-right" : options.fullscreenControl;
2818
- this.addControl(new maplibregl.FullscreenControl({}), position);
2902
+ this.addControl(new FullscreenControl({}), position);
2819
2903
  }
2820
2904
  }));
2821
2905
  if (options.terrain) {
@@ -3074,6 +3158,72 @@
3074
3158
  }
3075
3159
  }
3076
3160
 
3161
+ class Marker extends maplibregl.Marker {
3162
+ addTo(map) {
3163
+ return super.addTo(map);
3164
+ }
3165
+ }
3166
+
3167
+ class Popup extends maplibregl.Popup {
3168
+ addTo(map) {
3169
+ return super.addTo(map);
3170
+ }
3171
+ }
3172
+
3173
+ class Style extends maplibregl.Style {
3174
+ constructor(map, options = {}) {
3175
+ super(map, options);
3176
+ }
3177
+ }
3178
+
3179
+ class CanvasSource extends maplibregl.CanvasSource {
3180
+ onAdd(map) {
3181
+ super.onAdd(map);
3182
+ }
3183
+ }
3184
+
3185
+ class GeoJSONSource extends maplibregl.GeoJSONSource {
3186
+ onAdd(map) {
3187
+ super.onAdd(map);
3188
+ }
3189
+ }
3190
+
3191
+ class ImageSource extends maplibregl.ImageSource {
3192
+ onAdd(map) {
3193
+ super.onAdd(map);
3194
+ }
3195
+ }
3196
+
3197
+ class RasterTileSource extends maplibregl.RasterTileSource {
3198
+ onAdd(map) {
3199
+ super.onAdd(map);
3200
+ }
3201
+ }
3202
+
3203
+ class RasterDEMTileSource extends maplibregl.RasterDEMTileSource {
3204
+ onAdd(map) {
3205
+ super.onAdd(map);
3206
+ }
3207
+ }
3208
+
3209
+ class VectorTileSource extends maplibregl.VectorTileSource {
3210
+ onAdd(map) {
3211
+ super.onAdd(map);
3212
+ }
3213
+ }
3214
+
3215
+ class VideoSource extends maplibregl.VideoSource {
3216
+ onAdd(map) {
3217
+ super.onAdd(map);
3218
+ }
3219
+ }
3220
+
3221
+ class TerrainControl extends maplibregl.TerrainControl {
3222
+ onAdd(map) {
3223
+ return super.onAdd(map);
3224
+ }
3225
+ }
3226
+
3077
3227
  class Point {
3078
3228
  constructor(x, y) {
3079
3229
  this.x = x;
@@ -3229,28 +3379,11 @@
3229
3379
  supported,
3230
3380
  setRTLTextPlugin,
3231
3381
  getRTLTextPluginStatus,
3232
- NavigationControl,
3233
- GeolocateControl,
3234
- AttributionControl,
3235
- LogoControl,
3236
- ScaleControl,
3237
- FullscreenControl,
3238
- TerrainControl,
3239
- Popup,
3240
- Marker,
3241
- Style,
3242
3382
  LngLat,
3243
3383
  LngLatBounds,
3244
3384
  MercatorCoordinate,
3245
3385
  Evented,
3246
3386
  AJAXError,
3247
- CanvasSource,
3248
- GeoJSONSource,
3249
- ImageSource,
3250
- RasterDEMTileSource,
3251
- RasterTileSource,
3252
- VectorTileSource,
3253
- VideoSource,
3254
3387
  prewarm,
3255
3388
  clearPrewarmedResources,
3256
3389
  version,
@@ -3261,42 +3394,71 @@
3261
3394
  addProtocol,
3262
3395
  removeProtocol
3263
3396
  } = maplibregl;
3397
+ const MapMLGL = maplibregl.Map;
3398
+ const MarkerMLGL = maplibregl.Marker;
3399
+ const PopupMLGL = maplibregl.Popup;
3400
+ const StyleMLGL = maplibregl.Style;
3401
+ const CanvasSourceMLGL = maplibregl.CanvasSource;
3402
+ const GeoJSONSourceMLGL = maplibregl.GeoJSONSource;
3403
+ const ImageSourceMLGL = maplibregl.ImageSource;
3404
+ const RasterTileSourceMLGL = maplibregl.RasterTileSource;
3405
+ const RasterDEMTileSourceMLGL = maplibregl.RasterDEMTileSource;
3406
+ const VectorTileSourceMLGL = maplibregl.VectorTileSource;
3407
+ const VideoSourceMLGL = maplibregl.VideoSource;
3408
+ maplibregl.NavigationControl;
3409
+ maplibregl.GeolocateControl;
3410
+ maplibregl.AttributionControl;
3411
+ maplibregl.LogoControl;
3412
+ maplibregl.ScaleControl;
3413
+ maplibregl.FullscreenControl;
3414
+ maplibregl.TerrainControl;
3264
3415
 
3265
3416
  exports.AJAXError = AJAXError;
3266
3417
  exports.AttributionControl = AttributionControl;
3267
3418
  exports.CanvasSource = CanvasSource;
3419
+ exports.CanvasSourceMLGL = CanvasSourceMLGL;
3268
3420
  exports.Evented = Evented;
3269
3421
  exports.FullscreenControl = FullscreenControl;
3270
3422
  exports.GeoJSONSource = GeoJSONSource;
3423
+ exports.GeoJSONSourceMLGL = GeoJSONSourceMLGL;
3271
3424
  exports.GeolocateControl = GeolocateControl;
3272
3425
  exports.GeolocationType = GeolocationType;
3273
3426
  exports.ImageSource = ImageSource;
3427
+ exports.ImageSourceMLGL = ImageSourceMLGL;
3274
3428
  exports.Language = Language;
3275
3429
  exports.LanguageGeocoding = LanguageGeocoding;
3276
3430
  exports.LngLat = LngLat;
3277
3431
  exports.LngLatBounds = LngLatBounds;
3278
3432
  exports.LogoControl = LogoControl;
3279
3433
  exports.Map = Map$1;
3434
+ exports.MapMLGL = MapMLGL;
3280
3435
  exports.MapStyle = MapStyle;
3281
3436
  exports.MapStyleVariant = MapStyleVariant;
3282
3437
  exports.MaptilerGeolocateControl = MaptilerGeolocateControl;
3283
3438
  exports.MaptilerLogoControl = MaptilerLogoControl;
3284
3439
  exports.MaptilerTerrainControl = MaptilerTerrainControl;
3285
3440
  exports.Marker = Marker;
3441
+ exports.MarkerMLGL = MarkerMLGL;
3286
3442
  exports.MercatorCoordinate = MercatorCoordinate;
3287
3443
  exports.NavigationControl = NavigationControl;
3288
3444
  exports.Point = Point;
3289
3445
  exports.Popup = Popup;
3446
+ exports.PopupMLGL = PopupMLGL;
3290
3447
  exports.RasterDEMTileSource = RasterDEMTileSource;
3448
+ exports.RasterDEMTileSourceMLGL = RasterDEMTileSourceMLGL;
3291
3449
  exports.RasterTileSource = RasterTileSource;
3450
+ exports.RasterTileSourceMLGL = RasterTileSourceMLGL;
3292
3451
  exports.ReferenceMapStyle = ReferenceMapStyle;
3293
3452
  exports.ScaleControl = ScaleControl;
3294
3453
  exports.SdkConfig = SdkConfig;
3295
3454
  exports.ServiceError = ServiceError;
3296
3455
  exports.Style = Style;
3456
+ exports.StyleMLGL = StyleMLGL;
3297
3457
  exports.TerrainControl = TerrainControl;
3298
3458
  exports.VectorTileSource = VectorTileSource;
3459
+ exports.VectorTileSourceMLGL = VectorTileSourceMLGL;
3299
3460
  exports.VideoSource = VideoSource;
3461
+ exports.VideoSourceMLGL = VideoSourceMLGL;
3300
3462
  exports.addProtocol = addProtocol;
3301
3463
  exports.clearPrewarmedResources = clearPrewarmedResources;
3302
3464
  exports.clearStorage = clearStorage;
package/demos/simple.html CHANGED
@@ -36,15 +36,16 @@
36
36
  <script src ="maptiler-sdk.umd.js"></script>
37
37
 
38
38
  <script>
39
- // maptilersdk.config.apiKey = "ZFEK2gQSwT4Jcimbtcy7";
39
+ maptilersdk.config.apiKey = "YOUR_API_KEY";
40
40
 
41
41
  const map = new maptilersdk.Map({
42
42
  container: document.getElementById("map-container"),
43
+ style: maptilersdk.MapStyle.OUTDOOR.DARK,
43
44
  hash: true,
44
- maxPitch: 85,
45
45
  scaleControl: true,
46
46
  fullscreenControl: true,
47
47
  terrainControl: true,
48
+ geolocate: true,
48
49
  })
49
50
 
50
51
  const styleDropDown = document.getElementById("mapstyles-picker")