@maptiler/sdk 3.4.0-rc3 → 3.4.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.
Files changed (82) hide show
  1. package/.husky/pre-commit +2 -2
  2. package/README.md +133 -155
  3. package/dist/eslint.mjs +133 -0
  4. package/dist/maptiler-sdk.mjs +3788 -2749
  5. package/dist/maptiler-sdk.mjs.map +1 -1
  6. package/dist/src/Map.d.ts +22 -3
  7. package/dist/src/Telemetry.d.ts +1 -20
  8. package/dist/src/controls/Minimap.d.ts +1 -1
  9. package/dist/src/custom-layers/CubemapLayer/CubemapLayer.d.ts +216 -0
  10. package/dist/src/custom-layers/CubemapLayer/constants.d.ts +3 -0
  11. package/dist/src/custom-layers/CubemapLayer/index.d.ts +2 -0
  12. package/dist/src/custom-layers/CubemapLayer/loadCubemapTexture.d.ts +41 -0
  13. package/dist/src/custom-layers/CubemapLayer/types.d.ts +67 -0
  14. package/dist/src/custom-layers/RadialGradientLayer/RadialGradientLayer.d.ts +128 -0
  15. package/dist/src/custom-layers/RadialGradientLayer/index.d.ts +2 -0
  16. package/dist/src/custom-layers/RadialGradientLayer/types.d.ts +50 -0
  17. package/dist/src/custom-layers/extractCustomLayerStyle.d.ts +17 -0
  18. package/dist/src/custom-layers/index.d.ts +5 -0
  19. package/dist/src/helpers/index.d.ts +2 -0
  20. package/dist/src/index.d.ts +2 -1
  21. package/dist/src/utils/geo-utils.d.ts +6 -0
  22. package/dist/src/utils/index.d.ts +0 -3
  23. package/dist/src/utils/math-utils.d.ts +8 -0
  24. package/dist/src/utils/webgl-utils.d.ts +49 -0
  25. package/eslint.config.mjs +5 -5
  26. package/package.json +20 -17
  27. package/tsconfig.json +12 -7
  28. package/typedoc.json +2 -3
  29. package/dist/playwright.config.d.ts +0 -9
  30. package/dist/src/custom-layers/AnimatedRouteLayer.d.ts +0 -291
  31. package/dist/src/utils/MaptilerAnimation/AnimationManager.d.ts +0 -41
  32. package/dist/src/utils/MaptilerAnimation/MaptilerAnimation.d.ts +0 -238
  33. package/dist/src/utils/MaptilerAnimation/animation-helpers.d.ts +0 -182
  34. package/dist/src/utils/MaptilerAnimation/easing.d.ts +0 -3
  35. package/dist/src/utils/MaptilerAnimation/index.d.ts +0 -7
  36. package/dist/src/utils/MaptilerAnimation/types.d.ts +0 -57
  37. package/dist/src/utils/array.d.ts +0 -1
  38. package/dist/vite.config-e2e.d.ts +0 -2
  39. package/dist/vite.config-test.d.ts +0 -2
  40. package/dist/vite.config-umd.d.ts +0 -2
  41. package/dist/vitest-setup-tests.d.ts +0 -1
  42. package/e2e/global.d.ts +0 -12
  43. package/e2e/public/animated-route.geojson +0 -82
  44. package/e2e/public/animatedRouteLayer.html +0 -24
  45. package/e2e/public/mapLoad.html +0 -24
  46. package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-0-chromium-darwin.png +0 -0
  47. package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-1-chromium-darwin.png +0 -0
  48. package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-10-chromium-darwin.png +0 -0
  49. package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-11-chromium-darwin.png +0 -0
  50. package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-12-chromium-darwin.png +0 -0
  51. package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-13-chromium-darwin.png +0 -0
  52. package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-14-chromium-darwin.png +0 -0
  53. package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-15-chromium-darwin.png +0 -0
  54. package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-16-chromium-darwin.png +0 -0
  55. package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-17-chromium-darwin.png +0 -0
  56. package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-18-chromium-darwin.png +0 -0
  57. package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-19-chromium-darwin.png +0 -0
  58. package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-2-chromium-darwin.png +0 -0
  59. package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-3-chromium-darwin.png +0 -0
  60. package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-4-chromium-darwin.png +0 -0
  61. package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-5-chromium-darwin.png +0 -0
  62. package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-6-chromium-darwin.png +0 -0
  63. package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-7-chromium-darwin.png +0 -0
  64. package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-8-chromium-darwin.png +0 -0
  65. package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-9-chromium-darwin.png +0 -0
  66. package/e2e/snapshots/tests/map-load.test.ts-snapshots/mapLoad-chromium-darwin.png +0 -0
  67. package/e2e/tests/AnimatedRouteLayer.test.ts +0 -45
  68. package/e2e/tests/consts.ts +0 -0
  69. package/e2e/tests/expected-results/animatedRouteLayer-1.json +0 -202
  70. package/e2e/tests/helpers/fetchGeojson.ts +0 -21
  71. package/e2e/tests/helpers/getMapInstanceForFixture.ts +0 -86
  72. package/e2e/tests/map-load.test.ts +0 -14
  73. package/e2e/tests/mocks/maptiler-style.json +0 -27
  74. package/e2e/tests/mocks/tile.png +0 -0
  75. package/e2e/tsconfig.json +0 -10
  76. package/playwright.config.ts +0 -82
  77. package/tsconfig.tsbuildinfo +0 -1
  78. package/vite.config-dev.ts +0 -34
  79. package/vite.config-e2e.ts +0 -13
  80. package/vite.config-es.ts +0 -53
  81. package/vite.config-test.ts +0 -17
  82. package/vite.config-umd.ts +0 -35
@@ -0,0 +1,49 @@
1
+ export type WebGLContext = WebGLRenderingContext | WebGL2RenderingContext;
2
+ /**
3
+ * Load a shader from a source string
4
+ */
5
+ export declare function loadShader({ gl, type, source }: {
6
+ gl: WebGLContext;
7
+ type: GLenum;
8
+ source: string;
9
+ }): WebGLShader;
10
+ /**
11
+ * Create a set of shaders (vertex and fragment) and link them into a program
12
+ *
13
+ * @param gl WebGL context
14
+ * @param vertexShaderSource Vertex shader source code
15
+ * @param fragmentShaderSource Fragment shader source code
16
+ *
17
+ * @returns WebGL program
18
+ */
19
+ export declare function createShadersSetProgram({ gl, vertexShaderSource, fragmentShaderSource }: {
20
+ gl: WebGLContext;
21
+ vertexShaderSource: string;
22
+ fragmentShaderSource: string;
23
+ }): WebGLProgram;
24
+ /**
25
+ * null-free version of getUniformLocation
26
+ */
27
+ export declare function getUniformLocation(gl: WebGLRenderingContext | WebGL2RenderingContext, program: WebGLProgram, name: string): WebGLUniformLocation;
28
+ export type Object3D<Attribute extends string, Uniform extends string> = {
29
+ shaderProgram: WebGLProgram;
30
+ programInfo: {
31
+ attributesLocations: Record<Attribute, number>;
32
+ uniformsLocations: Record<Uniform, WebGLUniformLocation>;
33
+ };
34
+ positionBuffer: WebGLBuffer;
35
+ indexBuffer?: WebGLBuffer;
36
+ indexBufferLength?: number;
37
+ };
38
+ export declare function createObject3D<Attribute extends string, Uniform extends string>({ gl, vertexShaderSource, fragmentShaderSource, attributesKeys, uniformsKeys, vertices, indices, }: {
39
+ gl: WebGLContext;
40
+ vertexShaderSource: string;
41
+ fragmentShaderSource: string;
42
+ attributesKeys: readonly Attribute[];
43
+ uniformsKeys: readonly Uniform[];
44
+ vertices: Array<number>;
45
+ indices?: Array<number>;
46
+ }): Object3D<Attribute, Uniform>;
47
+ export type Vec4 = [number, number, number, number];
48
+ export declare function parseColorStringToVec4(color?: string): Vec4;
49
+ export declare function degreesToRadians(degrees: number): number;
package/eslint.config.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // @ts-check
1
+ // @ts-nocheck
2
2
 
3
3
  import tseslint from "typescript-eslint";
4
4
  import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
@@ -50,6 +50,7 @@ export default tseslint.config(
50
50
  node.specifiers.forEach((specifier) => {
51
51
  if (specifier.type !== "ImportDefaultSpecifier") {
52
52
  context.report({
53
+ // @ts-expect-error `message` seems to work with this...
53
54
  message: config.message ?? `Importing from '${bannedImport}' is banned in '${fp}'`,
54
55
  node,
55
56
  });
@@ -103,10 +104,10 @@ export default tseslint.config(
103
104
  "@typescript-eslint/no-inferrable-types": "off",
104
105
  "@typescript-eslint/no-misused-promises": "warn",
105
106
  "@typescript-eslint/no-unnecessary-boolean-literal-compare": "off",
106
- "@typescript-eslint/no-unnecessary-condition": "off", // we have the potential for a lot of user input that is not validated
107
+ "@typescript-eslint/no-unnecessary-condition": "warn",
107
108
  "@typescript-eslint/no-unnecessary-type-arguments": "off",
108
109
  "@typescript-eslint/no-unnecessary-type-assertion": "off",
109
- "@typescript-eslint/no-unnecessary-type-parameters": "warn",
110
+ "@typescript-eslint/no-unnecessary-type-parameters": "off", // as we are a lib, types serve as documentation
110
111
  "@typescript-eslint/no-unused-vars": "warn",
111
112
  "@typescript-eslint/no-unsafe-argument": "warn",
112
113
  "@typescript-eslint/no-unsafe-assignment": "warn",
@@ -115,7 +116,7 @@ export default tseslint.config(
115
116
  "@typescript-eslint/no-unsafe-member-access": "warn",
116
117
  "@typescript-eslint/no-unsafe-return": "warn",
117
118
  "@typescript-eslint/no-non-null-assertion": "warn",
118
- "@typescript-eslint/non-nullable-type-assertion-style": "off",
119
+ "@typescript-eslint/non-nullable-type-assertion-style": "warn",
119
120
  "@typescript-eslint/prefer-for-of": "off",
120
121
  "@typescript-eslint/prefer-nullish-coalescing": "warn",
121
122
  "@typescript-eslint/prefer-optional-chain": "off",
@@ -124,7 +125,6 @@ export default tseslint.config(
124
125
  "@typescript-eslint/restrict-plus-operands": "warn",
125
126
  "@typescript-eslint/restrict-template-expressions": "warn",
126
127
  "@typescript-eslint/related-getter-setter-pairs": "off",
127
- "@typescript-restrict-template-expressions": "off",
128
128
  "@typescript-eslint/unbound-method": "warn",
129
129
  "@typescript-eslint/use-unknown-in-catch-callback-variable": "warn",
130
130
  },
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@maptiler/sdk",
3
- "version": "3.4.0-rc3",
3
+ "version": "3.4.0",
4
4
  "description": "The Javascript & TypeScript map SDK tailored for MapTiler Cloud",
5
5
  "author": "MapTiler",
6
6
  "module": "dist/maptiler-sdk.mjs",
7
7
  "types": "dist/maptiler-sdk.d.ts",
8
8
  "style": "dist/maptiler-sdk.css",
9
9
  "type": "module",
10
+ "main": "dist/maptiler-sdk.mjs",
10
11
  "exports": {
11
12
  ".": {
12
13
  "import": "./dist/maptiler-sdk.mjs",
@@ -36,32 +37,33 @@
36
37
  },
37
38
  "scripts": {
38
39
  "prepare": "husky",
39
- "docs:md": "rm -rf docs/* && typedoc --plugin typedoc-plugin-markdown --out docs --readme none",
40
- "docs:html": "rm -rf docs-html/* && typedoc --out docs-html",
40
+ "doc": "rm -rf docs/* && typedoc --out docs && cp -r images docs/",
41
41
  "ncu": "npx npm-check-updates",
42
- "lint": "eslint src",
43
- "lint:fix": "eslint src --fix",
42
+ "lint": "tsc --noEmit && eslint src",
43
+ "lint:fix": "tsc --noEmit && eslint src --fix",
44
44
  "test:watch": "vitest watch -c vite.config-test.ts --dom",
45
45
  "test": "vitest run -c vite.config-test.ts --dom",
46
46
  "install:clean": "rm -rf build/ dist/ node_modules/ && npm ci",
47
- "dev": "concurrently \"vite -c vite.config-dev.ts\" \"npm run dev-umd\"",
47
+ "dev": "npm run build-css && vite -c vite.config-dev.ts",
48
48
  "dev-umd": "npm run build-css && tsc && NODE_ENV=development vite build -w -c vite.config-umd.ts",
49
49
  "build-css": "mkdir -p dist build && node scripts/replace-path-with-content.js src/style/style_template.css dist/tmp_maptiler-sdk.css && cat node_modules/maplibre-gl/dist/maplibre-gl.css dist/tmp_maptiler-sdk.css > dist/maptiler-sdk.css && rm dist/tmp_maptiler-sdk.css && cp dist/maptiler-sdk.css build/maptiler-sdk.css",
50
- "build-umd": "tsc -b && NODE_ENV=production vite build -c vite.config-umd.ts",
51
- "build-es": "tsc -b && NODE_ENV=production vite build -c vite.config-es.ts",
50
+ "build-umd": "tsc && NODE_ENV=production vite build -c vite.config-umd.ts",
51
+ "build-es": "tsc && NODE_ENV=production vite build -c vite.config-es.ts",
52
52
  "build": "npm run build-es; npm run build-umd; npm run build-css",
53
- "make": "npm run install:clean && npm run build",
54
- "e2e:serve": "tsc --project ./e2e && NODE_ENV=development vite -c vite.config-e2e.ts",
55
- "e2e:local": "npx playwright test --config=playwright.config.ts --ui",
56
- "e2e:watch": "concurrently \"npm run e2e:serve\" \"npm run e2e:local\""
53
+ "make": "npm run install:clean && npm run build"
57
54
  },
58
55
  "lint-staged": {
59
56
  "*.ts": "npm run lint:fix"
60
57
  },
58
+ "ts-typecheck": {
59
+ "*.ts": "npm tsc --noEmit"
60
+ },
61
61
  "devDependencies": {
62
62
  "@canvas/image-data": "^1.0.0",
63
63
  "@eslint/js": "^9.21.0",
64
- "@playwright/test": "^1.52.0",
64
+ "@types/color-convert": "^2.0.4",
65
+ "@types/color-name": "^2.0.0",
66
+ "@types/stats.js": "^0.17.4",
65
67
  "@types/uuid": "^10.0.0",
66
68
  "@types/xmldom": "^0.1.31",
67
69
  "@vitest/web-worker": "^3.0.9",
@@ -72,11 +74,11 @@
72
74
  "eslint-plugin-prettier": "^5.2.3",
73
75
  "happy-dom": "^17.4.4",
74
76
  "husky": "^8.0.0",
77
+ "jiti": "^2.4.2",
75
78
  "lint-staged": "^15.4.3",
76
- "playwright": "^1.52.0",
77
79
  "prettier": "3.5.2",
78
- "typedoc": "^0.28.3",
79
- "typedoc-plugin-markdown": "^4.6.3",
80
+ "stats.js": "^0.17.0",
81
+ "typedoc": "^0.27.6",
80
82
  "typescript": "^5.7.3",
81
83
  "typescript-eslint": "^8.25.0",
82
84
  "vite": "^6.0.7",
@@ -87,8 +89,9 @@
87
89
  "@maplibre/maplibre-gl-style-spec": "^23.0.0",
88
90
  "@maptiler/client": "^2.3.2",
89
91
  "events": "^3.3.0",
92
+ "gl-matrix": "^3.4.3",
90
93
  "js-base64": "^3.7.7",
91
- "maplibre-gl": "^5.3.1",
94
+ "maplibre-gl": "^5.5.0",
92
95
  "uuid": "^11.0.5"
93
96
  }
94
97
  }
package/tsconfig.json CHANGED
@@ -23,15 +23,20 @@
23
23
  "declaration": true,
24
24
  "allowSyntheticDefaultImports": true,
25
25
  "allowJs": true,
26
- "noEmitOnError": true,
27
26
  },
27
+ "exclude": [
28
+ "vite.config-*.ts",
29
+ "vitest-setup-tests.ts",
30
+ "dist"
31
+ ],
28
32
  "include": [
33
+ "vite.config-dev.ts",
34
+ "vite.config-es.ts",
35
+ "vite.config-umd.ts",
36
+ "vite.config-test.ts",
37
+ "vitest-setup-tests.ts",
29
38
  "src",
30
- "test",
31
- "./vite.config-test.ts",
32
- "./vite.config-e2e.ts",
33
- "./vite.config-umd.ts",
34
- "./playwright.config.ts",
35
- "./vitest-setup-tests.ts"
39
+ "demos",
40
+ "test"
36
41
  ],
37
42
  }
package/typedoc.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
- "entryPoints": [
3
- "./src/index.ts",
4
- ],
2
+ "entryPoints": ["./src/index.ts"],
5
3
  "name": "MapTiler SDK",
4
+ "out": "docs",
6
5
  "excludePrivate": true,
7
6
  "excludeProtected": true,
8
7
  "excludeExternals": true,
@@ -1,9 +0,0 @@
1
- /**
2
- * Read environment variables from file.
3
- * https://github.com/motdotla/dotenv
4
- */
5
- /**
6
- * See https://playwright.dev/docs/test-configuration.
7
- */
8
- declare const _default: import('@playwright/test').PlaywrightTestConfig<{}, {}>;
9
- export default _default;
@@ -1,291 +0,0 @@
1
- import { AnimationEvent, AnimationEventTypes, EasingFunctionName, Keyframe } from '../utils/MaptilerAnimation/types';
2
- import { default as MaptilerAnimation, MaptilerAnimationOptions } from '../utils/MaptilerAnimation/MaptilerAnimation';
3
- import { CustomLayerInterface, Map } from '../index';
4
- export type SourceData = {
5
- id: string;
6
- featureSetIndex: number;
7
- layerID: string;
8
- };
9
- /**
10
- * Options for configuring the animated stroke effect for routes.
11
- * When an object is provided, it defines colors for active and inactive parts of the route.
12
- * When `false`, the animated stroke effect is disabled.
13
- *
14
- * @typedef {Object|boolean} AnimatedStrokeOptions
15
- * @property {[number, number, number, number]} activeColor - The color of the path that has been progressed, in RGBA format.
16
- * @property {[number, number, number, number]} inactiveColor - The base color of the path, in RGBA format.
17
- */
18
- export type AnimatedStrokeOptions = {
19
- activeColor: [number, number, number, number];
20
- inactiveColor: [number, number, number, number];
21
- } | false;
22
- /**
23
- * Options for configuring the animated camera movement
24
- * along the route.
25
- *
26
- * @typedef {Object|boolean} AnimatedCameraOptions
27
- * @property {boolean} [follow] - Whether the camera should follow the animation.
28
- * @property {Object|boolean} [pathSmoothing] - Whether the camera path should be smoothed.
29
- * @property {number} [pathSmoothing.resolution] - The resolution of the smoothing, higher resolution means more fidelity to the path.
30
- * @property {number} [pathSmoothing.epsilon] - How much to simplify the path beforehand.
31
- * @property {false} [pathSmoothing] - Whether the camera path should be smoothed.
32
- */
33
- export type AnimatedCameraOptions = {
34
- /** Whether the camera should follow the animation */
35
- follow?: boolean;
36
- /** Whether the camera path should be smoothed */
37
- pathSmoothing?: {
38
- /** the resolution of the smoothing, higher resolution means more fidelity to the path */
39
- resolution: number;
40
- /** How mich to simplify the path beforehand */
41
- epsilon: number;
42
- } | false;
43
- } | false;
44
- /**
45
- * Configuration options for the AnimatedRouteLayer.
46
- * This type supports either providing keyframes directly OR source data for the animation.
47
- *
48
- * @typedef AnimatedRouteLayerOptions
49
- * @property {number} [duration] - The duration of the animation in milliseconds
50
- * @property {number} [iterations] - The number of animation iterations to perform
51
- * @property {number} [delay] - The delay in milliseconds before starting the animation
52
- * @property {EasingFunctionName} [easing] - The default easing function to use if not provided in the GeoJSON
53
- * @property {AnimatedCameraOptions} [cameraAnimation] - Options for camera animation
54
- * @property {AnimatedStrokeOptions} [pathStrokeAnimation] - Options for stroke animation, only applicable for LineString geometries
55
- * @property {boolean} [autoplay] - Whether the animation should start playing automatically
56
- * @property {boolean} [manualUpdate] - Whether the animation should update automatically or require manual frameAdvance calls
57
- * @property {Keyframe[]} [keyframes] - The keyframes for the animation (mutually exclusive with source)
58
- * @property {SourceData} [source] - The source data for the animation (mutually exclusive with keyframes)
59
- */
60
- export type AnimatedRouteLayerOptions = {
61
- /** The Duration in ms */
62
- duration?: number;
63
- /** The number of iterations */
64
- iterations?: number;
65
- /** The delay in ms before playing */
66
- delay?: number;
67
- /** The default easing to use if not provided in teh GeoJSON */
68
- easing?: EasingFunctionName;
69
- /** The camera animation options */
70
- cameraAnimation?: AnimatedCameraOptions;
71
- /** The stroke animation options, only viable for LineString geometries */
72
- pathStrokeAnimation?: AnimatedStrokeOptions;
73
- /** Whether the animation should autoplay */
74
- autoplay?: boolean;
75
- /** Whether the animation should auto matically animated or whether the frameAdvance method should be called */
76
- manualUpdate?: boolean;
77
- } & ({
78
- /** The keyframes for the the animation OR */
79
- keyframes: Keyframe[];
80
- source?: never;
81
- } | {
82
- /** The source data */
83
- source: SourceData;
84
- keyframes?: never;
85
- });
86
- /**
87
- * A callback function that gets executed for each animation frame. This is simply a utility type.
88
- * @param {AnimationEvent} event - The animation event data provided during animation frame updates.
89
- */
90
- export type FrameCallback = (event: AnimationEvent) => void;
91
- export declare const ANIM_LAYER_PREFIX = "animated-route-layer";
92
- /**
93
- * This layer allows you to create animated paths on a map by providing keyframes or a GeoJSON source
94
- * with route data. The animation can control both the visual appearance of the path (using color transitions)
95
- * and optionally animate the camera to follow along the route path.
96
- * @class AnimatedRouteLayer
97
- *
98
- * @example
99
- * ```typescript
100
- * // Create an animated route layer using a GeoJSON source
101
- * const animatedRoute = new AnimatedRouteLayer({
102
- * source: {
103
- * id: 'route-source',
104
- * layerID: 'route-layer',
105
- * featureSetIndex: 0
106
- * },
107
- * duration: 5000,
108
- * pathStrokeAnimation: {
109
- * activeColor: [0, 255, 0, 1],
110
- * inactiveColor: [100, 100, 100, 0.5]
111
- * },
112
- * autoplay: true
113
- * });
114
- *
115
- * // Add the layer to the map
116
- * map.addLayer(animatedRoute);
117
- *
118
- * // Control playback
119
- * animatedRoute.play();
120
- * animatedRoute.pause();
121
- * ```
122
- *
123
- * @remarks
124
- * The animation can be configured using either explicit keyframes or a GeoJSON source.
125
- * When using a GeoJSON source, the feature can include special properties that control
126
- * animation behavior:
127
- * - `@duration`: Animation duration in milliseconds
128
- * - `@iterations`: Number of times to repeat the animation
129
- * - `@delay`: Delay before starting animation in milliseconds
130
- * - `@autoplay`: Whether to start the animation automatically
131
- *
132
- * Only one AnimatedRouteLayer can be active at a time on a map.
133
- */
134
- /**
135
- * Creates an animated route layer for MapTiler maps.
136
- *
137
- * The `AnimatedRouteLayer` allows you to animate paths on a map with visual effects and optional camera following.
138
- * You can define animations either through explicit keyframes or by referencing GeoJSON data with animation metadata.
139
- *
140
- * Features:
141
- * - Animate route paths with color transitions (active/inactive segments)
142
- * - Optional camera following along the route
143
- * - Control animation playback (play, pause)
144
- * - Configure animation properties (duration, iterations, delay, easing)
145
- * - Support for manual or automatic animation updates
146
- * - Event system for animation state changes
147
- *
148
- * @example
149
- * ```typescript
150
- * // Create an animated route from GeoJSON source
151
- * const animatedRoute = new AnimatedRouteLayer({
152
- * source: {
153
- * id: 'route-source',
154
- * layerID: 'route-layer',
155
- * featureSetIndex: 0
156
- * },
157
- * duration: 5000,
158
- * iterations: 1,
159
- * autoplay: true,
160
- * cameraAnimation: {
161
- * follow: true,
162
- * pathSmoothing: { resolution: 20, epsilon: 5 }
163
- * },
164
- * pathStrokeAnimation: {
165
- * activeColor: [255, 0, 0, 1],
166
- * inactiveColor: [0, 0, 255, 1]
167
- * }
168
- * });
169
- *
170
- * // Add the layer to the map
171
- * map.addLayer(animatedRoute);
172
- *
173
- * // Control playback
174
- * animatedRoute.pause();
175
- * animatedRoute.play();
176
- *
177
- * // Listen for animation events
178
- * animatedRoute.addEventListener(AnimationEventTypes.Finish, () => {
179
- * console.log('Animation completed');
180
- * });
181
- * ```
182
- *
183
- * @implements {CustomLayerInterface}
184
- */
185
- export declare class AnimatedRouteLayer implements CustomLayerInterface {
186
- /** Unique ID for the layer */
187
- readonly id: string;
188
- readonly type = "custom";
189
- /** The MaptilerAnimation instance that handles the animation */
190
- animationInstance: MaptilerAnimation;
191
- /**
192
- * Keyframes for the animation
193
- * If keyframes are provided, they will be used for the animation
194
- * If a source is provided, the keyframes will be parsed from the GeoJSON feature
195
- */
196
- private keyframes;
197
- /**
198
- * Source data for the animation
199
- * If a source is provided, it will be used to get the keyframes
200
- * If keyframes are provided, this will be ignored
201
- */
202
- private source;
203
- /** The duration of the animation in ms */
204
- private duration;
205
- /** The number of interations */
206
- private iterations;
207
- /** The delay before the animation starts in ms */
208
- private delay;
209
- /** The default easing function for the animation */
210
- private easing?;
211
- /** The map instance */
212
- private map;
213
- /** The camera animation options */
214
- private cameraMaptilerAnimationOptions?;
215
- /**
216
- * The path stroke animation options
217
- * This controls the color of the path during the animation
218
- */
219
- private pathStrokeAnimation?;
220
- /** Whether the animation will autoplay */
221
- private autoplay;
222
- /** Whether the animation will be managed manually */
223
- private manualUpdate;
224
- private enquedEventHandlers;
225
- private enquedCommands;
226
- constructor({ keyframes, source, duration, iterations, easing, delay, cameraAnimation, pathStrokeAnimation, autoplay, manualUpdate, }: AnimatedRouteLayerOptions);
227
- /**
228
- * This method is called when the layer is added to the map.
229
- * It initializes the animation instance and sets up event listeners.
230
- *
231
- * @param {Map} map - The map instance
232
- */
233
- onAdd(map: Map): Promise<void>;
234
- /**
235
- * This method is used to manually advance the animation
236
- *
237
- * @returns {AnimatedRouteLayer} - The current instance of AnimatedRouteLayer
238
- */
239
- frameAdvance(): this;
240
- /**
241
- * Adds an event listener to the animation instance.
242
- *
243
- * @param {AnimationEventTypes} type - The type of event to listen for
244
- * @param {FrameCallback} callback - The callback function to execute when the event occurs
245
- */
246
- addEventListener(type: AnimationEventTypes, callback: FrameCallback): AnimatedRouteLayer;
247
- /**
248
- * Removes an event listener from the animation instance.
249
- *
250
- * @param {AnimationEventTypes} type - The type of event to remove
251
- * @param {FrameCallback} callback - The callback function to remove
252
- */
253
- removeEventListener(type: AnimationEventTypes, callback: FrameCallback): AnimatedRouteLayer;
254
- updateManual(): void;
255
- /**
256
- * Updates the layer's properties based on the animation event.
257
- * @private
258
- * @param {AnimationEvent} event - The animation event
259
- */
260
- private update;
261
- /**
262
- * Plays the animation.
263
- *
264
- * @returns {AnimatedRouteLayer} - The current instance of AnimatedRouteLayer
265
- */
266
- play(): AnimatedRouteLayer;
267
- /**
268
- * Stops the animation.
269
- *
270
- * @returns {AnimatedRouteLayer} - The current instance of AnimatedRouteLayer
271
- */
272
- pause(): AnimatedRouteLayer;
273
- /**
274
- * Gets the source GeoJSON data from the map instance, parses it, and returns the animation options.
275
- *
276
- * @returns {Promise<MaptilerAnimationOptions>} - The MaptilerAnimation constructor options
277
- */
278
- getMaptilerAnimationOptions(): Promise<MaptilerAnimationOptions & {
279
- autoplay: boolean;
280
- }>;
281
- /**
282
- * This method is called when the layer is removed from the map.
283
- * It destroys the animation instance.
284
- */
285
- onRemove(): void;
286
- /**
287
- * This method is called to render the layer.
288
- * It is a no-op for this layer.
289
- */
290
- render(): void;
291
- }
@@ -1,41 +0,0 @@
1
- import { default as MaptilerAnimation } from './MaptilerAnimation';
2
- /**
3
- * Manager for handling animation lifecycle and updates.
4
- *
5
- * The AnimationManager provides a centralized system for registering and
6
- * coordinating multiple animations. To avoid individual calls to request animation frame
7
- * for each animation, it maintains an animation loop
8
- *
9
- * This is not a class as it never needs to be instantiated,
10
- * it's just a singeton object.
11
- *
12
- * It's not called directly but used within the MaptilerAnimation class.
13
- */
14
- declare const AnimationManager: {
15
- animations: MaptilerAnimation[];
16
- running: boolean;
17
- /**
18
- * Adds an animation to the manager. If this is the first animation added,
19
- * it starts the animation loop.
20
- *
21
- * @param {MaptilerAnimation} animation - The animation to add.
22
- */
23
- add(animation: MaptilerAnimation): void;
24
- /**
25
- * Removes an animation from the manager. If there are no more animations,
26
- * it stops the animation loop.
27
- *
28
- * @param {MaptilerAnimation} animation - The animation to remove.
29
- */
30
- remove(animation: MaptilerAnimation): void;
31
- /**
32
- * Stops the animation loop.
33
- */
34
- stop(): void;
35
- /**
36
- * Starts the animation loop. This function is called recursively using
37
- * requestAnimationFrame to ensure smooth updates.
38
- */
39
- start(): void;
40
- };
41
- export default AnimationManager;