@maptiler/sdk 5.0.0-rc.4 → 5.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/README.md CHANGED
@@ -121,6 +121,15 @@ From CDN and using the UMD bundle, in the `<head></head>` section of your HTML f
121
121
  <link href="https://cdn.maptiler.com/maptiler-sdk-js/<VERSION>/maptiler-sdk.css" rel="stylesheet" />
122
122
  ```
123
123
 
124
+ Or from CDN and using the ES module bundle, importing the SDK from a module script:
125
+
126
+ ```html
127
+ <link href="https://cdn.maptiler.com/maptiler-sdk-js/<VERSION>/maptiler-sdk.css" rel="stylesheet" />
128
+ <script type="module">
129
+ import { config, Map } from "https://cdn.maptiler.com/maptiler-sdk-js/<VERSION>/maptiler-sdk.min.mjs";
130
+ </script>
131
+ ```
132
+
124
133
  <br>
125
134
 
126
135
  ## 🚀 Basic Usage
@@ -189,7 +198,7 @@ With the legacy `"moduleResolution": "Node"` (or `"Node10"`), the main `@maptile
189
198
 
190
199
  ### With CDN
191
200
 
192
- The SDK hosted on our CDN is bundled as _[Universal Module Definition](https://github.com/umdjs/umd)_ (UMD) to make it standalone and contain all its dependencies. The CDN also serves the style sheet (CSS).
201
+ The SDK hosted on our CDN is bundled both as _[Universal Module Definition](https://github.com/umdjs/umd)_ (UMD), `maptiler-sdk.umd.min.js`, and as an ES module, `maptiler-sdk.min.mjs`. Both are standalone and contain all their dependencies. The CDN also serves the style sheet (CSS).
193
202
 
194
203
  **Recommended for:** simple map integration example and demos
195
204
 
@@ -236,13 +245,29 @@ The SDK hosted on our CDN is bundled as _[Universal Module Definition](https://g
236
245
  </html>
237
246
  ```
238
247
 
248
+ With the ES module bundle, the SDK is imported from a module script instead of being exposed as the `maptilersdk` global:
249
+
250
+ ```html
251
+ <script type="module">
252
+ import { config, Map, MapStyle } from "https://cdn.maptiler.com/maptiler-sdk-js/<VERSION>/maptiler-sdk.min.mjs";
253
+
254
+ config.apiKey = "YOUR_API_KEY";
255
+
256
+ const map = new Map({
257
+ container: "map-container",
258
+ style: MapStyle.STREETS_DARK,
259
+ hash: true,
260
+ });
261
+ </script>
262
+ ```
263
+
239
264
  Check out the minimalist code samples in the [demos](demos) directory.
240
265
 
241
266
  #### Map worker files and Content Security Policy (CSP)
242
267
 
243
- Since MapLibre GL JS v6, the map loads its background worker as two separate files, `maplibre-gl-worker.mjs` and `maplibre-gl-shared.mjs`. The UMD bundle looks for them in the same folder as `maptiler-sdk.umd.min.js`. Our CDN serves them there, so when using the CDN without a CSP, there is nothing to set up.
268
+ Since MapLibre GL JS v6, the map loads its background worker as two separate files, `maplibre-gl-worker.mjs` and `maplibre-gl-shared.mjs`. The UMD and ES module bundles look for them in the same folder as `maptiler-sdk.umd.min.js` and `maptiler-sdk.min.mjs`. Our CDN serves them there, so when using the CDN without a CSP, there is nothing to set up.
244
269
 
245
- If you **self-host the UMD bundle**, copy both `.mjs` files next to `maptiler-sdk.umd.min.js`. They must be served with a JavaScript content type (e.g. `text/javascript`).
270
+ If you **self-host the UMD or ES module bundle**, copy both `.mjs` files next to `maptiler-sdk.umd.min.js` or `maptiler-sdk.min.mjs`. They must be served with a JavaScript content type (e.g. `text/javascript`).
246
271
 
247
272
  If your site uses a **Content Security Policy**, the worker needs to be allowed:
248
273
 
@@ -260,6 +285,8 @@ If your site uses a **Content Security Policy**, the worker needs to be allowed:
260
285
  </script>
261
286
  ```
262
287
 
288
+ With the ES module bundle, import `setWorkerUrl` from it and call it the same way.
289
+
263
290
  `setWorkerUrl` is also needed if the UMD bundle is not loaded with a regular `<script src="...">` tag (e.g. concatenated into another file or loaded with AMD/RequireJS), since the worker location is then no longer known.
264
291
 
265
292
  <br>
@@ -274,6 +301,110 @@ Check out more than 200 [examples and tutorials](https://docs.maptiler.com/sdk-j
274
301
 
275
302
  <br>
276
303
 
304
+ ## 🗂️ In-repo demos
305
+
306
+ Runnable demos of the SDK features, kept in `demos/`. They're separate from the docs examples linked above.
307
+
308
+ ### Run the demos
309
+
310
+ 1. Create a `.env.local` file at the root of the repo (git ignores it) with your MapTiler API key: `VITE_MAPTILER_API_KEY=YOUR_KEY`.
311
+ 2. Run `npm run dev`.
312
+ 3. Open the printed URL. It lists every demo.
313
+
314
+ Instead of `.env.local`, you can add `?key=YOUR_KEY` to a demo URL once, and the browser stores the key for all demos. If several keys are set, the demos use the first of: the key in `.env.local`, the key stored in the browser, the `key` URL parameter.
315
+
316
+ ### Kinds of demos
317
+
318
+ - **Examples** (`demos/examples/<topic>/<name>/`): short, single-use code with minimal dependencies, e.g. "put a marker on the page and style it".
319
+ - **Showcases** (`demos/showcases/<name>/`): more involved, with more comments and inline docs, closer to a guide. May use external dependencies, e.g. a UI library.
320
+ - **Playgrounds** (`demos/playgrounds/<name>/`): for comparing feature versions, testing or developing features, and recording code "gotchas". May use external dependencies and lots of UI code. Internal: listed on the `npm run dev` page, but not in the list below.
321
+
322
+ ### Add or change a demo
323
+
324
+ Each demo is a folder with an `index.html`, a `main.ts` and a `meta.json`:
325
+
326
+ ```json
327
+ {
328
+ "title": "Styled marker",
329
+ "description": "Puts a marker on the map and sets its shape and colors.",
330
+ "type": "example",
331
+ "topics": ["markers"],
332
+ "createdWith": "5.0.0-rc.4",
333
+ "lastCheckedWith": "5.0.0-rc.4",
334
+ "lastCheckedOn": "2026-10-30"
335
+ }
336
+ ```
337
+
338
+ - `type` is `example`, `showcase` or `playground`, matching the folder. An example's first topic matches its `<topic>` folder. Playgrounds stay out of the index below, and their `topics` can be empty.
339
+ - `createdWith` is the SDK version the demo was created with.
340
+ - `lastCheckedWith` and `lastCheckedOn` record the last time someone ran the demo and saw it working. They stay `null` until then.
341
+
342
+ Values likely to change go in variables right after the imports of `main.ts`, with the same names in every demo, so they can be updated with grep or a script, e.g. `MAP_STYLE`.
343
+
344
+ Build any controls a demo needs (buttons, dropdowns, sliders, readouts) with [lil-gui](https://lil-gui.georgealways.com), using `createGui()` from `demos/shared/gui.ts`, rather than hand-written HTML. The exception is UI that is the subject of the demo, such as the custom map controls of the controls examples.
345
+
346
+ Run `npm run demos:index` after adding or changing a demo. It validates the metadata and regenerates the index below. CI fails if the index is out of date.
347
+
348
+ ### Topics
349
+
350
+ Use only these labels in `topics`. Add a label here before using it.
351
+
352
+ <!-- demo-topics:start -->
353
+ - `3d`
354
+ - `animation`
355
+ - `color-ramps`
356
+ - `controls`
357
+ - `errors`
358
+ - `events`
359
+ - `getting-started`
360
+ - `halo`
361
+ - `image-viewer`
362
+ - `language`
363
+ - `markers`
364
+ - `performance`
365
+ - `requests`
366
+ - `routes`
367
+ - `sky`
368
+ - `space`
369
+ - `styles`
370
+ <!-- demo-topics:end -->
371
+
372
+ ### Index
373
+
374
+ <!-- demos-index:start -->
375
+ #### Examples
376
+
377
+ | Demo | Description | Topics | Created with | Last checked |
378
+ | --- | --- | --- | --- | --- |
379
+ | [Available color ramps](./demos/examples/color-ramps/available-ramps) | Displays every built-in color ramp, plus rescaled and resampled variants. | `color-ramps` | 3.2.4 | Not yet |
380
+ | [Custom controls: declarative](./demos/examples/controls/declarative) | Builds custom map controls from HTML attributes. | `controls` | 3.5.1-rc1 | Not yet |
381
+ | [Custom controls: programmatic](./demos/examples/controls/programmatic) | Builds custom map controls from code. | `controls` | 3.8.0-rc.9 | Not yet |
382
+ | [Handling WebGL errors](./demos/examples/errors/handling-webgl-errors) | Reacts to a lost WebGL context and shows a warning. | `errors` | 3.2.4 | Not yet |
383
+ | [Ready event](./demos/examples/events/ready-event) | Uses the `ready` event to know when the map can be changed safely. | `events` | 3.2.4 | Not yet |
384
+ | [Simple map](./demos/examples/getting-started/simple) | A map with the Streets v2 style. | `getting-started` | 5.0.0-rc.4 | Not yet |
385
+ | [Image viewer](./demos/examples/image-viewer/image-viewer) | Displays a tiled, non-georeferenced image with markers. | `image-viewer` `markers` | 3.8.0-rc.9 | Not yet |
386
+ | [Language changes](./demos/examples/language/language-changes) | Switches the map language at runtime. | `language` | 3.5.1-rc1 | Not yet |
387
+ | [Marker altitude](./demos/examples/markers/altitude) | Raises two draggable markers to 1,300 m above sea level over the terrain, with ground lines (experimental). | `markers` | 5.0.0-beta.m-r.1 | Not yet |
388
+ | [Styled marker](./demos/examples/markers/styled-marker) | Puts a marker on the map and sets its shape and colors. | `markers` | 5.0.0-rc.4 | Not yet |
389
+ | [Marker UI states](./demos/examples/markers/ui-states) | Markers that change their look on hover, focus, press and drag. | `markers` | 5.0.0-beta.m-r.1 | Not yet |
390
+ | [Tile preloading: bounds](./demos/examples/performance/tile-preloading-bounds) | Preloads the tiles of a region with `experimental_preloadTilesForBounds`, then jumps there. Toggle preloading off to compare. | `performance` | 4.1.0 | Not yet |
391
+ | [Tile preloading: flyTo](./demos/examples/performance/tile-preloading-flyto) | Preloads the tiles along a `flyTo` path with `experimental_preload` before the flight starts. Toggle preloading off to compare. | `performance` | 4.1.0 | Not yet |
392
+ | [Transform request](./demos/examples/requests/transform-request) | Changes outgoing map requests with `transformRequest`. | `requests` | 3.2.4 | Not yet |
393
+ | [Sky: day](./demos/examples/sky/day) | Configures the sky on a daytime outdoor style. | `sky` | 3.2.4 | Not yet |
394
+ | [Sky: night](./demos/examples/sky/night) | Configures the sky on a dark outdoor style. | `sky` | 3.2.4 | Not yet |
395
+ | [Space & halo: simple](./demos/examples/space/orbiting-globe) | A globe turning against a starry space background, with the default halo. | `space` `halo` | 5.0.0-rc.4 | Not yet |
396
+
397
+ #### Showcases
398
+
399
+ | Demo | Description | Topics | Created with | Last checked |
400
+ | --- | --- | --- | --- | --- |
401
+ | [Animated route around Madeira](./demos/showcases/animated-routes) | Animates the camera along a Madeira route with `AnimatedRouteLayer`, with stops and photos. | `animation` `routes` | 3.11.0 | Not yet |
402
+ | [Marker animation in the Sahara](./demos/showcases/marker-animation) | Drives two rally car markers around the Erg Chebbi dunes with a single `MaptilerAnimation`, with playback controls. | `animation` `markers` | 5.0.0-rc.4 | Not yet |
403
+ | [Space & halo: transitions](./demos/showcases/spacebox-and-halo) | Switches between every space preset, custom cubemap images, space colors and halo gradients on a globe. | `space` `halo` | 3.5.1-rc1 | Not yet |
404
+ <!-- demos-index:end -->
405
+
406
+ <br>
407
+
277
408
  ## 📘 API Reference
278
409
 
279
410
  In addition to the details and examples provided in this readme, check out the [complete API documentation](https://docs.maptiler.com/sdk-js/api/)
@@ -998,7 +1129,7 @@ map.on("load", () => {
998
1129
 
999
1130
  Note: if `space.color` or `space.<faces | path | preset>` are not explicitly set in the call to `setSpace`, then the previous value will remain for this field.
1000
1131
 
1001
- Further code examples can be found in `~/demos/`
1132
+ See [`demos/examples/space/orbiting-globe`](./demos/examples/space/orbiting-globe) for a simple example, and [`demos/showcases/spacebox-and-halo`](./demos/showcases/spacebox-and-halo) for every preset and option.
1002
1133
 
1003
1134
  ### `ImageViewer`
1004
1135
 
@@ -1565,6 +1696,8 @@ marker.setGroundLine(true); // dashed line from the marker down to the ground
1565
1696
 
1566
1697
  Style the ground line with your own CSS on the `maptiler-marker-groundline` class, or add a class of your own with `setGroundLine(true, { className: "my-line" })`.
1567
1698
 
1699
+ See [`demos/examples/markers/altitude`](./demos/examples/markers/altitude) for an example.
1700
+
1568
1701
  #### The MapLibre marker
1569
1702
 
1570
1703
  Compared with the MapLibre marker:
@@ -1580,14 +1713,13 @@ import { MarkerMLGL } from "@maptiler/sdk";
1580
1713
  new MarkerMLGL({ color: "#f00" }).setLngLat([8.54, 47.37]).addTo(map);
1581
1714
  ```
1582
1715
 
1583
- See `demos/16-maptiler-markers.html` to `demos/20-marker-altitude.html` for examples.
1716
+ See [`demos/examples/markers/styled-marker`](./demos/examples/markers/styled-marker) for an example, and `demos/playgrounds/markers*` for every option.
1584
1717
 
1585
1718
  ### Camera routes and animations
1586
1719
 
1587
1720
  The SDK comes with several classes to help with animations, particularly route animations.
1588
1721
 
1589
- See `demos/11-animated-routes.html` for examples.
1590
- See `demos/12-maptiler-animation.html` for examples.
1722
+ See [`demos/showcases/animated-routes`](./demos/showcases/animated-routes) and [`demos/showcases/marker-animation`](./demos/showcases/marker-animation) for examples.
1591
1723
 
1592
1724
  #### 🧩 `MaptilerAnimation`
1593
1725
 
@@ -1734,7 +1866,7 @@ animatedRoute.play();
1734
1866
  animatedRoute.pause();
1735
1867
  ```
1736
1868
 
1737
- For a full example of how to use this, look at [the example](./demos/11-animated-routes.html)
1869
+ For a full example of how to use this, look at [the showcase](./demos/showcases/animated-routes)
1738
1870
 
1739
1871
  ### Vector Layer Helpers
1740
1872
 
@@ -11829,7 +11829,7 @@ class En {
11829
11829
  ne(this, ge, t), ne(this, Pe, xe("div", "maplibregl-ctrl maplibregl-ctrl-group"));
11830
11830
  for (const [e, n] of Object.entries(L(this, oe).containerStyle))
11831
11831
  L(this, Pe).style.setProperty(e, n);
11832
- return L(this, oe).container = L(this, Pe), L(this, oe).zoom = t.getZoom() + L(this, oe).zoomAdjust, this.map = new Cl(L(this, oe)), this.map.once("style.load", () => {
11832
+ return L(this, oe).container = L(this, Pe), L(this, oe).zoom = t.getZoom() + L(this, oe).zoomAdjust, this.map = new Cl({ ...L(this, oe), space: !1, halo: !1 }), this.map.once("style.load", () => {
11833
11833
  this.map.resize();
11834
11834
  }), this.map.once("load", () => {
11835
11835
  ie(this, K, yl).call(this, L(this, oe).parentRect), ne(this, Zt, ie(this, K, gl).call(this));
@@ -13195,7 +13195,7 @@ function kh() {
13195
13195
  );
13196
13196
  }
13197
13197
  function Th() {
13198
- return "https://cdn.maptiler.com/maptiler-sdk-js/v5.0.0-rc.4/maplibre-gl-worker.mjs";
13198
+ return "https://cdn.maptiler.com/maptiler-sdk-js/v5.0.0-rc.5/maplibre-gl-worker.mjs";
13199
13199
  }
13200
13200
  function bl() {
13201
13201
  au() || ou(Ih(Th()));
@@ -13664,15 +13664,15 @@ let Cl = class Sl extends su {
13664
13664
  if (this.halo && this.getLayer(this.halo.id) || e.halo === !1) return;
13665
13665
  const a = i;
13666
13666
  if (e.halo && e.halo !== !0) {
13667
- this.halo = new fr(e.halo), this.removeLayer(this.halo.id), this.addLayer(this.halo, n);
13667
+ this.halo = new fr(e.halo), this.getLayer(this.halo.id) && this.removeLayer(this.halo.id), this.addLayer(this.halo, n);
13668
13668
  return;
13669
13669
  }
13670
13670
  if (a) {
13671
- this.halo = new fr(a), this.removeLayer(this.halo.id), this.addLayer(this.halo, n);
13671
+ this.halo = new fr(a), this.getLayer(this.halo.id) && this.removeLayer(this.halo.id), this.addLayer(this.halo, n);
13672
13672
  return;
13673
13673
  }
13674
13674
  if (this.options.halo === !0) {
13675
- this.halo = new fr(!0), this.removeLayer(this.halo.id), this.addLayer(this.halo, n);
13675
+ this.halo = new fr(!0), this.getLayer(this.halo.id) && this.removeLayer(this.halo.id), this.addLayer(this.halo, n);
13676
13676
  return;
13677
13677
  }
13678
13678
  }
@@ -17807,7 +17807,7 @@ class Im {
17807
17807
  }
17808
17808
  }
17809
17809
  function ql() {
17810
- return "5.0.0-rc.4";
17810
+ return "5.0.0-rc.5";
17811
17811
  }
17812
17812
  export {
17813
17813
  _m as AJAXError,