@maptiler/sdk 3.0.0-rc.3 → 3.0.0-rc.5

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/dist/src/Map.d.ts CHANGED
@@ -3,6 +3,7 @@ import { ReferenceMapStyle, MapStyleVariant } from '@maptiler/client';
3
3
  import { SdkConfig } from './config';
4
4
  import { LanguageInfo } from './language';
5
5
  import { MinimapOptionsInput } from './Minimap';
6
+ import { Telemetry } from './Telemetry';
6
7
 
7
8
  export type LoadWithTerrainEvent = {
8
9
  type: "loadWithTerrain";
@@ -130,6 +131,7 @@ export type MapOptions = Omit<MapOptionsML, "style" | "maplibreLogo"> & {
130
131
  * The Map class can be instanciated to display a map in a `<div>`
131
132
  */
132
133
  export declare class Map extends maplibregl.Map {
134
+ readonly telemetry: Telemetry;
133
135
  private isTerrainEnabled;
134
136
  private terrainExaggeration;
135
137
  private primaryLanguage;
@@ -145,6 +147,7 @@ export declare class Map extends maplibregl.Map {
145
147
  private curentProjection;
146
148
  private originalLabelStyle;
147
149
  private isStyleLocalized;
150
+ private languageIsUpdated;
148
151
  constructor(options: MapOptions);
149
152
  /**
150
153
  * Set the duration (millisec) of the terrain animation for growing or flattening.
@@ -378,11 +381,18 @@ export declare class Map extends maplibregl.Map {
378
381
  */
379
382
  isGlobeProjection(): boolean;
380
383
  /**
381
- * Uses the globe projection. Animated by default, it can be disabled
384
+ * Activate the globe projection.
382
385
  */
383
- enableGlobeProjection(animate?: boolean): void;
386
+ enableGlobeProjection(): void;
384
387
  /**
385
- * Uses the Mercator projection. Animated by default, it can be disabled
388
+ * Activate the mercator projection.
386
389
  */
387
- enableMercatorProjection(animate?: boolean): void;
390
+ enableMercatorProjection(): void;
391
+ /**
392
+ * Returns `true` is the language was ever updated, meaning changed
393
+ * from what is delivered in the style.
394
+ * Returns `false` if language in use is the language from the style
395
+ * and has never been changed.
396
+ */
397
+ isLanguageUpdated(): boolean;
388
398
  }
@@ -18,4 +18,5 @@ export declare class MaptilerGeolocateControl extends GeolocateControl {
18
18
  _finishSetupUI: (supported: boolean) => void;
19
19
  _updateCircleRadius(): void;
20
20
  _onZoom: () => void;
21
+ _setErrorState(): void;
21
22
  }
@@ -0,0 +1,22 @@
1
+ import { Map as MapSDK } from './Map';
2
+
3
+ /**
4
+ * A Telemetry instance sends some usage and merics to a dedicated endpoint at MapTiler Cloud.
5
+ */
6
+ export declare class Telemetry {
7
+ private map;
8
+ private registeredModules;
9
+ /**
10
+ *
11
+ * @param map : a Map instance
12
+ * @param delay : a delay in milliseconds after which the payload is sent to MapTiler cloud (cannot be less than 1000ms)
13
+ */
14
+ constructor(map: MapSDK, delay?: number);
15
+ /**
16
+ * Register a module to the telemetry system of the SDK.
17
+ * The arguments `name` and `version` likely come from the package.json
18
+ * of each module.
19
+ */
20
+ registerModule(name: string, version: string): void;
21
+ private preparePayload;
22
+ }
@@ -31,6 +31,24 @@ declare class SdkConfig extends EventEmitter {
31
31
  * Works only for requests to the MapTiler Cloud API when sessions are enabled.
32
32
  */
33
33
  caching: boolean;
34
+ /**
35
+ * Telemetry is enabled by default but can be opted-out by setting this value to `false`.
36
+ * The telemetry is very valuable to the team at MapTiler because it shares information
37
+ * about where to add the extra effort. It also helps spotting some incompatibility issues
38
+ * that may arise between the SDK and a specific version of a module.
39
+ *
40
+ * It consists in sending metrics about usage of the following features:
41
+ * - SDK version [string]
42
+ * - API key [string]
43
+ * - MapTiler sesion ID (if opted-in) [string]
44
+ * - if tile caching is enabled [boolean]
45
+ * - if language specified at initialization [boolean]
46
+ * - if terrain is activated at initialization [boolean]
47
+ * - if globe projection is activated at initialization [boolean]
48
+ *
49
+ * In addition, each official module will be add added to a list, alongside its version number.
50
+ */
51
+ telemetry: boolean;
34
52
  /**
35
53
  * Unit to be used
36
54
  */
@@ -5,6 +5,7 @@ declare const defaults: {
5
5
  maptilerLogoURL: string;
6
6
  maptilerURL: string;
7
7
  maptilerApiHost: string;
8
+ telemetryURL: string;
8
9
  rtlPluginURL: string;
9
10
  primaryLanguage: import('@maptiler/client').LanguageInfo;
10
11
  secondaryLanguage: import('@maptiler/client').LanguageInfo;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maptiler/sdk",
3
- "version": "3.0.0-rc.3",
3
+ "version": "3.0.0-rc.5",
4
4
  "description": "The Javascript & TypeScript map SDK tailored for MapTiler Cloud",
5
5
  "module": "dist/maptiler-sdk.mjs",
6
6
  "types": "dist/maptiler-sdk.d.ts",
@@ -65,7 +65,7 @@
65
65
  "@maptiler/client": "^2.2.0",
66
66
  "events": "^3.3.0",
67
67
  "js-base64": "^3.7.4",
68
- "maplibre-gl": "^5.0.0-pre.9",
68
+ "maplibre-gl": "^5.0.0-pre.10",
69
69
  "uuid": "^9.0.0"
70
70
  }
71
71
  }
package/readme.md CHANGED
@@ -136,7 +136,7 @@ The SDK hosted on our CDN is bundled as *[Universal Module Definition](https://g
136
136
  <body>
137
137
  <div id="map-container"></div>
138
138
 
139
- <script src ="dist/maptiler-sdk.umd.js"></script>
139
+ <script src ="dist/maptiler-sdk.umd.min.js"></script>
140
140
 
141
141
  <script>
142
142
  // Add your MapTiler Cloud API key to the config
@@ -1103,7 +1103,40 @@ Turning off *zoom compensation* allows for more accurate adjustments to the visu
1103
1103
 
1104
1104
  All the other options are documented on [our reference page](https://docs.maptiler.com/sdk-js/api/helpers/#heatmap) and more examples are available [here](https://docs.maptiler.com/sdk-js/examples/?q=heatmap+helper).
1105
1105
 
1106
- # Other helper
1106
+ # Other helpers
1107
+ ## Convert GPX and KML to GeoJSON
1108
+ In the [Polyline helper section](#polyline-layer-helper) above, we have seen that one can feed the helper directly with a path to a GPX or KML file, that is then converted under the hood client-side into a GeoJSON `FeatureCollection` object. This conversion feature is also exposed and can be used as such:
1109
+
1110
+ ```ts
1111
+ import { gpx } from "@maptiler/sdk";
1112
+
1113
+ // ... assuming inside an async function
1114
+
1115
+ // Fetching the GPX file as a string:
1116
+ const gpxFilePath = "some_gps_trace.gpx";
1117
+ const gpxResponse = await fetch(gpxFilePath);
1118
+ const gpxStr = await res.text();
1119
+
1120
+ // Converting the GPX payload into a GeoJSON FeatureCollection:
1121
+ const features = maptilersdk.gpx(gpxStr);
1122
+ ```
1123
+
1124
+ And for KML files:
1125
+ ```ts
1126
+ import { kml } from "@maptiler/sdk";
1127
+
1128
+ // ... assuming inside an async function
1129
+
1130
+ // Fetching the KML file as a string:
1131
+ const kmlFilePath = "some_gps_trace.kml";
1132
+ const kmlResponse = await fetch(kmlFilePath);
1133
+ const kmlStr = await res.text();
1134
+
1135
+ // Converting the KML payload into a GeoJSON FeatureCollection:
1136
+ const features = maptilersdk.gpx(kmlStr);
1137
+ ```
1138
+
1139
+
1107
1140
  ## Take Screenshots, programmatically
1108
1141
  There are two different ways to create screenshot, corresponding to two very different usecases. Note that screenshots will not contain *DOM elements* such as `Marker` and `Popup`, since those are not part of the rendering context.
1109
1142
 
@@ -2,26 +2,20 @@ import { resolve } from 'path';
2
2
  import { defineConfig } from 'vite';
3
3
 
4
4
  const isProduction = process.env.NODE_ENV === "production";
5
- const bundleFilename = isProduction ? "maptiler-sdk.umd.min.js" : "maptiler-sdk.umd.js"
6
-
7
- const plugins = [];
8
-
9
5
 
10
6
  export default defineConfig({
11
7
  mode: isProduction ? "production" : "development",
12
8
  build: {
13
9
  outDir: "build",
14
- minify: isProduction,
10
+ minify: true,
15
11
  emptyOutDir: isProduction,
16
12
  sourcemap: true,
17
13
  lib: {
18
- // Could also be a dictionary or array of multiple entry points
19
14
  entry: resolve(__dirname, 'src/index.ts'),
20
15
  name: 'maptilersdk',
21
- // the proper extensions will be added
22
- fileName: (format, entryName) => bundleFilename,
16
+ fileName: (format, entryName) => "maptiler-sdk.umd.min.js",
23
17
  formats: ['umd'],
24
18
  }
25
19
  },
26
- plugins,
27
- })
20
+ plugins: [],
21
+ });