@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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maptiler/sdk",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
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",
@@ -20,52 +20,50 @@
20
20
  "sdk",
21
21
  "webmap",
22
22
  "cloud",
23
- "webGL"
23
+ "webGL",
24
+ "maplibre"
24
25
  ],
25
- "homepage": "https://www.maptiler.com/cloud/",
26
+ "homepage": "https://docs.maptiler.com/sdk-js/",
26
27
  "license": "BSD-3-Clause",
27
28
  "repository": {
28
29
  "type": "git",
29
30
  "url": "https://github.com/maptiler/maptiler-sdk-js.git"
30
31
  },
31
32
  "scripts": {
32
- "build": "rm -rf dist/* ; NODE_ENV=production rollup -c",
33
- "dev": "rm -rf dist/* ; NODE_ENV=development rollup -c -w",
33
+ "build": "rm -rf dist/* && NODE_ENV=production rollup -c",
34
+ "dev": "rm -rf dist/* && NODE_ENV=development rollup -c -w",
34
35
  "format": "prettier --write \"src/**/*.{js,ts,tsx}\"",
35
36
  "lint": "eslint --fix \"src/**/*.{js,ts}\"",
36
- "docmd": "rm -rf docsmd/*; typedoc --readme none --plugin typedoc-plugin-markdown --out docsmd src/index.ts; cp -r images docsmd/",
37
- "dochtml": "rm -rf docs/*; typedoc --plugin none --out docs; cp -r images docs/",
38
- "doc": "npm run docmd; npm run dochtml",
39
- "prepare": "npm run format; npm run lint; npm run build; npm run doc; cp -r demos docs/"
37
+ "doc": "rm -rf docs/* && typedoc --out docs && cp -r images docs/",
38
+ "prepare": "npm run format && npm run lint && npm run build && npm run doc && cp -r demos docs/"
40
39
  },
41
40
  "author": "MapTiler",
42
41
  "devDependencies": {
43
- "@rollup/plugin-commonjs": "^22.0.2",
44
- "@rollup/plugin-json": "^5.0.1",
45
- "@rollup/plugin-node-resolve": "^14.1.0",
46
- "@typescript-eslint/eslint-plugin": "^5.41.0",
47
- "@typescript-eslint/parser": "^5.41.0",
48
- "eslint": "^8.26.0",
49
- "prettier": "^2.7.1",
50
- "rollup": "^2.79.0",
51
- "rollup-plugin-copy-merge": "^0.3.5",
52
- "rollup-plugin-dts": "^4.2.2",
53
- "rollup-plugin-esbuild": "^4.10.1",
42
+ "@rollup/plugin-commonjs": "^24.1.0",
43
+ "@rollup/plugin-json": "^6.0.0",
44
+ "@rollup/plugin-node-resolve": "^15.0.2",
45
+ "@typescript-eslint/eslint-plugin": "^5.59.0",
46
+ "@typescript-eslint/parser": "^5.59.0",
47
+ "eslint": "^8.38.0",
48
+ "prettier": "^2.8.7",
49
+ "rollup": "^3.20.6",
50
+ "rollup-plugin-copy-merge": "^1.0.0",
51
+ "rollup-plugin-dts": "^5.3.0",
52
+ "rollup-plugin-esbuild": "^5.0.0",
54
53
  "rollup-plugin-node-globals": "^1.4.0",
55
54
  "rollup-plugin-shell": "^1.0.9",
56
55
  "rollup-plugin-string": "^3.0.0",
57
56
  "rollup-plugin-swc": "^0.2.1",
58
- "serve": "^14.0.1",
59
- "terser": "^5.15.0",
60
- "typedoc": "^0.23.21",
61
- "typedoc-plugin-markdown": "^3.13.6",
62
- "typescript": "^4.8.4"
57
+ "serve": "^14.2.0",
58
+ "terser": "^5.17.1",
59
+ "typedoc": "^0.24.4",
60
+ "typescript": "^5.0.4"
63
61
  },
64
62
  "dependencies": {
65
- "@maptiler/client": "^1.1.3",
63
+ "@maptiler/client": "^1.3.0",
66
64
  "events": "^3.3.0",
67
65
  "js-base64": "^3.7.4",
68
- "maplibre-gl": "^3.0.0-pre.3",
66
+ "maplibre-gl": "3.0.0-pre.4",
69
67
  "uuid": "^9.0.0"
70
68
  }
71
69
  }
package/readme.md CHANGED
@@ -389,6 +389,114 @@ Languages that are written right-to-left such as arabic and hebrew are fully sup
389
389
  <img src="images/screenshots/lang-hebrew.jpeg" width="48%"></img>
390
390
  </p>
391
391
 
392
+ # Custom Events and Map Lifecycle
393
+ ## Events
394
+ Since the SDK is fully compatible with MapLibre, [all these events](https://maplibre.org/maplibre-gl-js-docs/api/map/#map-events) are available, yet we have added one more: `loadWithTerrain`.
395
+
396
+ The `loadWithTerrain` event is triggered only *once* in a `Map` instance lifecycle, when both the `load` event and the `terrain` event **with non-null terrain** are fired.
397
+
398
+ **Why a new event?**
399
+ When a map is instanciated with the option `terrain: true`, then MapTiler terrain is directly added to it and some animation functions such as `.flyTo()` or `.easeTo()` if started straight after the map initialization will actually need to wait a few milliseconds that the terrain is properly initialized before running.
400
+ Relying on the `load` event to run an animation with a map with terrain may fail in some cases for this reason, and this is why waiting for `loadWithTerrain` is safer in this particular situation.
401
+
402
+ ## Lifecycle Methods
403
+ The events `load` and `loadWithTerrain` are both called *at most once* and require a callback function to add more elements such as markers, layers, popups and data sources. Even though MapTiler SDK fully supports this logic, we have also included a *promise* logic to provide a more linear and less nested way to wait for a Map instance to be ready. Let's compare the two ways:
404
+
405
+ - Classic: with a callback on the `load` event:
406
+ ```ts
407
+ function init() {
408
+
409
+ const map = new Map({
410
+ container,
411
+ center: [2.34804, 48.85439], // Paris, France
412
+ zoom: 14,
413
+ });
414
+
415
+ // We wait for the event.
416
+ // Once triggered, the callback is ranin it's own scope.
417
+ map.on("load", (evt) => {
418
+ // Adding a data source
419
+ map.addSource('my-gps-track-source', {
420
+ type: "geojson",
421
+ data: "https://example.com/some-gps-track.geojson",
422
+ });
423
+ })
424
+ }
425
+ ```
426
+
427
+ - Modern: with a promise returned by the method `.onLoadAsync()`, used in an `async` function:
428
+ ```ts
429
+ async function init() {
430
+
431
+ const map = new Map({
432
+ container,
433
+ center: [2.34804, 48.85439], // Paris, France
434
+ zoom: 14,
435
+ });
436
+
437
+ // We wait for the promise to resolve.
438
+ // Once triggered, the rest of the init function runs
439
+ await map.onLoadAsync();
440
+
441
+ // Adding a data source
442
+ map.addSource('my-gps-track-source', {
443
+ type: "geojson",
444
+ data: "https://example.com/some-gps-track.geojson",
445
+ });
446
+ }
447
+ ```
448
+
449
+ We deployed exactely the same logic for the `loadWithTerrain` event. Let's see how they two ways compares.
450
+ - Classic: with a callback on the `loadWithTerrain` event:
451
+ ```ts
452
+ function init() {
453
+
454
+ const map = new Map({
455
+ container,
456
+ center: [2.34804, 48.85439], // Paris, France
457
+ zoom: 14,
458
+ terrain: true,
459
+ });
460
+
461
+ // We wait for the event.
462
+ // Once triggered, the callback is ran in its own scope.
463
+ map.on("loadWithTerrain", (evt) => {
464
+ // make an animation
465
+ map.flyTo({
466
+ center: [-0.09956, 51.50509], // London, UK
467
+ zoom: 12.5,
468
+ })
469
+ })
470
+ }
471
+ ```
472
+
473
+ - Modern: with a promise returned by the method `.onLoadWithTerrainAsync()`, used in an `async` function:
474
+ ```ts
475
+ async function init() {
476
+
477
+ const map = new Map({
478
+ container,
479
+ center: [2.34804, 48.85439], // Paris, France
480
+ zoom: 14,
481
+ terrain: true,
482
+ });
483
+
484
+ // We wait for the promise to resolve.
485
+ // Once triggered, the rest of the init function runs
486
+ await map.onLoadWithTerrainAsync();
487
+
488
+ // make an animation
489
+ map.flyTo({
490
+ center: [-0.09956, 51.50509], // London, UK
491
+ zoom: 12.5,
492
+ })
493
+ }
494
+ ```
495
+
496
+ We believe that the *promise* approach is better because it does not nest scopes and will allow for a linear non-nested stream of execution. It also corresponds to more modern development standards.
497
+
498
+ > 📣 *__Note:__* Generally speaking, *promises* are not a go to replacement for all event+callback and are suitable only for events that are called only once in the lifecycle of a Map instance. This is the reason why we have decided to provide a *promise* equivalent only for the `load` and `loadWithTerrain` events.
499
+
392
500
  # Easy access to MapTiler Cloud API
393
501
  Our map SDK is not only about maps! We also provide plenty of wrapper to our API calls!
394
502
 
@@ -509,9 +617,12 @@ In the following static map functions, the `option` object features a `style` pr
509
617
  - `MapStyle.STREETS`, reference style for navigation and city exploration
510
618
  - `MapStyle.STREETS.DARK` (variant)
511
619
  - `MapStyle.STREETS.LIGHT` (variant)
620
+ - `MapStyle.STREETS.NIGHT` (variant)
512
621
  - `MapStyle.STREETS.PASTEL` (variant)
513
622
  - `MapStyle.OUTDOOR` reference style for adventure
623
+ - `MapStyle.OUTDOOR.DARK` (variant)
514
624
  - `MapStyle.WINTER` reference style for winter adventure
625
+ - `MapStyle.WINTER.DARK` (variant)
515
626
  - `MapStyle.SATELLITE` reference style satellite and airborne imagery (no variants)
516
627
  - `MapStyle.HYBRID` reference style satellite and airborne imagery with labels (no variants)
517
628
  - `MapStyle.BASIC` reference style for minimalist design and general purpose
@@ -0,0 +1,13 @@
1
+ /**
2
+ * This is an extension of MapLibre AttributionControl to make it fully type compatible with the SDK
3
+ */
4
+
5
+ import maplibregl from "maplibre-gl";
6
+ import type { Map as MapMLGL } from "maplibre-gl";
7
+ import { Map } from "./Map";
8
+
9
+ export class AttributionControl extends maplibregl.AttributionControl {
10
+ onAdd(map: Map | MapMLGL) {
11
+ return super.onAdd(map as MapMLGL);
12
+ }
13
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * This is an extension of MapLibre CanvasSource to make it fully type compatible with the SDK
3
+ */
4
+
5
+ import maplibregl from "maplibre-gl";
6
+ import type { Map as MapMLGL } from "maplibre-gl";
7
+ import { Map } from "./Map";
8
+
9
+ export class CanvasSource extends maplibregl.CanvasSource {
10
+ onAdd(map: Map | MapMLGL) {
11
+ super.onAdd(map as MapMLGL);
12
+ }
13
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * This is an extension of MapLibre FullscreenControl to make it fully type compatible with the SDK
3
+ */
4
+
5
+ import maplibregl from "maplibre-gl";
6
+ import type { Map as MapMLGL } from "maplibre-gl";
7
+ import { Map } from "./Map";
8
+
9
+ export class FullscreenControl extends maplibregl.FullscreenControl {
10
+ onAdd(map: Map | MapMLGL) {
11
+ return super.onAdd(map as MapMLGL);
12
+ }
13
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * This is an extension of MapLibre GeoJSONSource to make it fully type compatible with the SDK
3
+ */
4
+
5
+ import maplibregl from "maplibre-gl";
6
+ import type { Map as MapMLGL } from "maplibre-gl";
7
+ import { Map } from "./Map";
8
+
9
+ export class GeoJSONSource extends maplibregl.GeoJSONSource {
10
+ onAdd(map: Map | MapMLGL) {
11
+ super.onAdd(map as MapMLGL);
12
+ }
13
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * This is an extension of MapLibre GeolocateControl to make it fully type compatible with the SDK
3
+ */
4
+
5
+ import maplibregl from "maplibre-gl";
6
+ import type { Map as MapMLGL } from "maplibre-gl";
7
+ import { Map } from "./Map";
8
+
9
+ export class GeolocateControl extends maplibregl.GeolocateControl {
10
+ onAdd(map: Map | MapMLGL) {
11
+ return super.onAdd(map as MapMLGL);
12
+ }
13
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * This is an extension of MapLibre ImageSource to make it fully type compatible with the SDK
3
+ */
4
+
5
+ import maplibregl from "maplibre-gl";
6
+ import type { Map as MapMLGL } from "maplibre-gl";
7
+ import { Map } from "./Map";
8
+
9
+ export class ImageSource extends maplibregl.ImageSource {
10
+ onAdd(map: Map | MapMLGL) {
11
+ super.onAdd(map as MapMLGL);
12
+ }
13
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * This is an extension of MapLibre LogoControl to make it fully type compatible with the SDK
3
+ */
4
+
5
+ import maplibregl from "maplibre-gl";
6
+ import type { Map as MapMLGL } from "maplibre-gl";
7
+ import { Map } from "./Map";
8
+
9
+ export class LogoControl extends maplibregl.LogoControl {
10
+ onAdd(map: Map | MapMLGL) {
11
+ return super.onAdd(map as MapMLGL);
12
+ }
13
+ }