@maptiler/sdk 3.3.0-rc3 → 3.3.0

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/.husky/pre-commit CHANGED
@@ -1,3 +1,2 @@
1
1
  npx lint-staged;
2
- npx ts-typecheck;
3
2
  npm run test;
package/README.md CHANGED
@@ -40,30 +40,30 @@ In addition to the details and examples provided in this readme, check out the [
40
40
  **Recommended for:** advanced applications
41
41
 
42
42
  ```ts
43
- import * as maptilersdk from '@maptiler/sdk';
43
+ import { config, Map } from '@maptiler/sdk';
44
44
 
45
45
  // Add your MapTiler Cloud API key to the config
46
46
  // (Go to https://cloud.maptiler.com/account/keys/ to get one for free!)
47
- maptilersdk.config.apiKey = 'YOUR_API_KEY';
47
+ config.apiKey = 'YOUR_API_KEY';
48
48
 
49
49
  // Let's say you have a DIV ready to receive a map
50
50
  const mapContainer = document.getElementById('my-container-div');
51
51
 
52
52
  // Instantiate the map
53
- const map = new maptilersdk.Map({
53
+ const map = new Map({
54
54
  container: mapContainer,
55
55
  });
56
56
  ```
57
57
 
58
58
  Alternatively, the `apiKey` can be set as Map option instead of in the `config` object. Yet, this will still internally propagate to the `config` object:
59
59
  ```ts
60
- import * as maptilersdk from '@maptiler/sdk';
60
+ import { Map } from '@maptiler/sdk';
61
61
 
62
62
  // Let's say you have a DIV ready to receive a map
63
63
  const mapContainer = document.getElementById('my-container-div');
64
64
 
65
65
  // Instantiate the map
66
- const map = new maptilersdk.Map({
66
+ const map = new Map({
67
67
  container: mapContainer,
68
68
  apiKey: 'YOUR_API_KEY'
69
69
  });
@@ -155,6 +155,7 @@ The SDK hosted on our CDN is bundled as *[Universal Module Definition](https://g
155
155
  </script>
156
156
  </body>
157
157
  </html>
158
+
158
159
  ```
159
160
 
160
161
  Check out the minimalist code samples in the [demos](demos) directory.
@@ -540,125 +541,7 @@ map.on("terrainAnimationStop", (e) => {
540
541
  });
541
542
  });
542
543
  ```
543
- # Halo and Space Options
544
-
545
- The `halo` and `space` options allow for enhanced visual customization of the map, especially for globe projections.
546
-
547
- ## `halo` (Atmospheric Glow)
548
- The `halo` option adds a gradient-based atmospheric glow around the globe, simulating the visual effect of Earth's atmosphere when viewed from space.
549
-
550
- ### Usage:
551
- You can enable a simple halo by setting it to `true`:
552
- ```ts
553
- const map = new maptilersdk.Map({
554
- container: document.getElementById("map"),
555
- style: maptilersdk.MapStyle.OUTDOOR,
556
- halo: true,
557
- });
558
- ```
559
- For more customization, you can define a radial gradient with scale and stops:
560
- ```ts
561
544
 
562
- const map = new maptilersdk.Map({
563
- container: document.getElementById("map"),
564
- style: maptilersdk.MapStyle.OUTDOOR,
565
- halo: {
566
- scale: 1.5, // Controls the halo size
567
- stops: [
568
- [0.2, "transparent"],
569
- [0.2, "red"],
570
- [0.4, "red"],
571
- [0.4, "transparent"],
572
- [0.6, "transparent"],
573
- [0.6, "red"],
574
- [0.8, "red"],
575
- [0.8, "transparent"],
576
- [1.0, "transparent"],
577
- ],
578
- },
579
- });
580
- ```
581
- You can also set the halo dynamically after the map loads:
582
- ```ts
583
- map.on("load", () => {
584
- map.setHalo({
585
- scale: 2,
586
- stops: [
587
- [0.0, "rgba(135,206,250,1)"],
588
- [0.5, "rgba(0,0,250,0.75)"],
589
- [0.75, "rgba(250,0,0,0.0)"],
590
- ],
591
- });
592
- });
593
- ```
594
- ## `space` (Background Environment)
595
-
596
- The space option allows customizing the background environment of the globe, simulating deep space or skybox effects.
597
- ### Usage
598
-
599
- You can enable a simple space background with a solid color:
600
- ```ts
601
- const map = new maptilersdk.Map({
602
- container: document.getElementById("map"),
603
- style: maptilersdk.MapStyle.OUTDOOR,
604
- space: {
605
- color: "#111122", // Dark space-like color
606
- },
607
- });
608
- ```
609
- Alternatively, you can provide a cubemap for a realistic skybox effect using one of the following methods:
610
-
611
- Predefined Presets:
612
- ```ts
613
- const map = new maptilersdk.Map({
614
- container: document.getElementById("map"),
615
- style: maptilersdk.MapStyle.OUTDOOR,
616
- space: {
617
- preset: "universe-dark",
618
- },
619
- });
620
- ```
621
- Cubemap Images (Custom Skybox):
622
- ```ts
623
- const map = new maptilersdk.Map({
624
- container: document.getElementById("map"),
625
- style: maptilersdk.MapStyle.OUTDOOR,
626
- space: {
627
- faces: {
628
- pX: '/path-to-image/pX.png',
629
- nX: '/path-to-image/nX.png',
630
- pY: '/path-to-image/pY.png',
631
- nY: '/path-to-image/nY.png',
632
- pZ: '/path-to-image/pZ.png',
633
- nZ: '/path-to-image/nZ.png',
634
- },
635
- },
636
- });
637
- ```
638
- Cubemap Path with image format, fetches all images from a path, this assumes all files are named px, nx, py, ny, pz, nz and suffixed with the appropriate extension specified in `format`.
639
- ```ts
640
- const map = new maptilersdk.Map({
641
- container: document.getElementById("map"),
642
- style: maptilersdk.MapStyle.OUTDOOR,
643
- space: {
644
- path: {
645
- baseUrl: "spacebox/transparent",
646
- format: "png", // Defaults to PNG
647
- },
648
- },
649
- });
650
- ```
651
- You can also set the space background dynamically:
652
- ```ts
653
- map.on("load", () => {
654
- map.setSpace({
655
- color: "red",
656
- path: {
657
- baseUrl: "spacebox/transparent",
658
- },
659
- });
660
- });
661
- ```
662
545
 
663
546
  # Easy language switching
664
547
  The language generally depends on the style but we made it possible to easily set and update from a built-in list of languages.
@@ -0,0 +1,133 @@
1
+ // @ts-nocheck
2
+
3
+ import tseslint from "typescript-eslint";
4
+ import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
5
+
6
+ export default tseslint.config(
7
+ // https://typescript-eslint.io/getting-started/typed-linting/
8
+ tseslint.configs.strictTypeChecked,
9
+ tseslint.configs.stylisticTypeChecked,
10
+ tseslint.configs.recommendedTypeChecked,
11
+ {
12
+ // forked from https://www.npmjs.com/package/eslint-plugin-restrict-imports
13
+ plugins: {
14
+ import: {
15
+ rules: {
16
+ "default-imports-only": {
17
+ meta: {
18
+ type: "suggestion",
19
+ docs: {},
20
+ schema: [
21
+ {
22
+ bannedImport: {
23
+ locations: ["filePaths"],
24
+ message: "string",
25
+ fixedLocation: "string",
26
+ },
27
+ },
28
+ ],
29
+ },
30
+ create: function (context) {
31
+ const filePath = context.getFilename();
32
+ const options = context.options[0] || {
33
+ "^/(.*)": {
34
+ locations: ["(.*)"],
35
+ },
36
+ };
37
+
38
+ return {
39
+ ImportDeclaration: (node) => {
40
+ Object.entries(options).forEach(([bannedImport, config]) => {
41
+ const importLocationRegex = new RegExp(bannedImport);
42
+
43
+ if (config.ignoreTypeImports && node.importKind === "type") return;
44
+
45
+ if (importLocationRegex.test(node.source.value)) {
46
+ config.locations.forEach((fp) => {
47
+ const bannedLocationRegex = new RegExp(fp);
48
+
49
+ if (bannedLocationRegex.test(filePath)) {
50
+ node.specifiers.forEach((specifier) => {
51
+ if (specifier.type !== "ImportDefaultSpecifier") {
52
+ context.report({
53
+ // @ts-expect-error `message` seems to work with this...
54
+ message: config.message ?? `Importing from '${bannedImport}' is banned in '${fp}'`,
55
+ node,
56
+ });
57
+ }
58
+ });
59
+ }
60
+ });
61
+ }
62
+ });
63
+ },
64
+ };
65
+ },
66
+ },
67
+ },
68
+ },
69
+ },
70
+ rules: {
71
+ "import/default-imports-only": [
72
+ "error",
73
+ {
74
+ "maplibre-gl$": {
75
+ locations: ["^(?!.*\.d\.ts$).*\.((ts|js))$"],
76
+ message: `Maplibre-gl uses CJS modules, only default imports are supported, named imports may fail on some setups.`,
77
+ ignoreTypeImports: true,
78
+ },
79
+ },
80
+ ],
81
+ },
82
+ },
83
+ {
84
+ languageOptions: {
85
+ parserOptions: {
86
+ projectService: true,
87
+ tsconfigRootDir: import.meta.dirname,
88
+ },
89
+ },
90
+ },
91
+ // https://github.com/prettier/eslint-plugin-prettier
92
+ eslintPluginPrettierRecommended,
93
+ //
94
+ {
95
+ rules: {
96
+ "@typescript-eslint/array-type": "off",
97
+ "@typescript-eslint/consistent-indexed-object-style": "warn",
98
+ "@typescript-eslint/consistent-type-definitions": "off",
99
+ "@typescript-eslint/no-base-to-string": "warn",
100
+ "@typescript-eslint/no-confusing-void-expression": "warn",
101
+ "@typescript-eslint/no-explicit-any": "warn",
102
+ "@typescript-eslint/no-empty-function": "warn", // this is to satisfy maplibre-gl custom layer interface
103
+ "@typescript-eslint/no-floating-promises": "warn",
104
+ "@typescript-eslint/no-inferrable-types": "off",
105
+ "@typescript-eslint/no-misused-promises": "warn",
106
+ "@typescript-eslint/no-unnecessary-boolean-literal-compare": "off",
107
+ "@typescript-eslint/no-unnecessary-condition": "warn",
108
+ "@typescript-eslint/no-unnecessary-type-arguments": "off",
109
+ "@typescript-eslint/no-unnecessary-type-assertion": "off",
110
+ "@typescript-eslint/no-unnecessary-type-parameters": "warn",
111
+ "@typescript-eslint/no-unused-vars": "warn",
112
+ "@typescript-eslint/no-unsafe-argument": "warn",
113
+ "@typescript-eslint/no-unsafe-assignment": "warn",
114
+ "@typescript-eslint/no-unsafe-call": "warn",
115
+ "@typescript-eslint/no-unsafe-enum-comparison": "off",
116
+ "@typescript-eslint/no-unsafe-member-access": "warn",
117
+ "@typescript-eslint/no-unsafe-return": "warn",
118
+ "@typescript-eslint/no-non-null-assertion": "warn",
119
+ "@typescript-eslint/non-nullable-type-assertion-style": "warn",
120
+ "@typescript-eslint/prefer-for-of": "off",
121
+ "@typescript-eslint/prefer-nullish-coalescing": "warn",
122
+ "@typescript-eslint/prefer-optional-chain": "off",
123
+ "@typescript-eslint/prefer-return-this-type": "off",
124
+ "@typescript-eslint/prefer-string-starts-ends-with": "warn",
125
+ "@typescript-eslint/restrict-plus-operands": "warn",
126
+ "@typescript-eslint/restrict-template-expressions": "warn",
127
+ "@typescript-eslint/related-getter-setter-pairs": "off",
128
+ "@typescript-eslint/unbound-method": "warn",
129
+ "@typescript-eslint/use-unknown-in-catch-callback-variable": "warn",
130
+ },
131
+ },
132
+ //
133
+ );