@maptiler/sdk 3.10.2 → 3.11.0-rc.1
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 +233 -66
- package/dist/eslint.mjs +8 -0
- package/dist/maptiler-sdk.mjs +3512 -2464
- package/dist/maptiler-sdk.mjs.map +1 -1
- package/dist/src/ImageViewer/ImageViewer.d.ts +2 -2
- package/dist/src/Map.d.ts +42 -2
- package/dist/src/MaptilerAnimation/AnimationManager.d.ts +41 -0
- package/dist/src/MaptilerAnimation/MaptilerAnimation.d.ts +238 -0
- package/dist/src/MaptilerAnimation/animation-helpers.d.ts +183 -0
- package/dist/src/MaptilerAnimation/easing.d.ts +3 -0
- package/dist/src/MaptilerAnimation/index.d.ts +7 -0
- package/dist/src/MaptilerAnimation/types.d.ts +26 -0
- package/dist/src/custom-layers/AnimatedRouteLayer/AnimatedRouteLayer.d.ts +293 -0
- package/dist/src/custom-layers/AnimatedRouteLayer/index.d.ts +1 -0
- package/dist/src/custom-layers/CubemapLayer/CubemapLayer.d.ts +1 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/utils/array.d.ts +1 -0
- package/dist/src/utils/json.d.ts +1 -0
- package/dist/src/utils/string.d.ts +1 -0
- package/e2e/global.d.ts +14 -1
- package/e2e/public/animated-route.geojson +82 -0
- package/e2e/public/animatedRouteLayer.html +24 -0
- package/e2e/public/haloSpace.html +25 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-0-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-1-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-10-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-11-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-12-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-13-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-14-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-15-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-16-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-17-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-18-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-19-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-2-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-3-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-4-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-5-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-6-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-7-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-8-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/AnimatedRouteLayer.test.ts-snapshots/animated-route-9-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/halo-halo-catalogue-style-halo-constructor-override-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/halo-halo-json-style-config-halo-constructor-override-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/halo-halo-json-style-config-halo-rendered-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/halo-halo-json-style-config-halo-rendered-chromium.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/halo-halo-json-style-config-halo-true-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/halo-halo-no-style-config-halo-true-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/halo-halo-remote-style-config-halo-constructor-override-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/halo-halo-remote-style-config-halo-false-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/halo-halo-remote-style-config-halo-true-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/halo-halo-style-config-halo-json-default-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/halo-halo-style-config-halo-json-default-chromium.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/halo-halo-style-config-halo-json-false-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/halo-halo-style-config-halo-json-false-chromium.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/halo-halo-style-config-halo-json-valid-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/halo-halo-style-config-halo-json-valid-chromium.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/halo-halo-style-config-halo-remote-valid-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/space-space-catalogue-style-config-space-true-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/space-space-catalogue-style-config-space-undefined-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/space-space-json-style-config-space-true-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/space-space-json-style-config-space-true-chromium.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/space-space-json-style-config-space-true-default-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/space-space-json-style-config-space-true-default-chromium.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/space-space-style-config-constructor-undefined-with-json-style-config-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/space-space-style-config-space-constructor-with-catalogue-style-config-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/space-space-style-config-space-constructor-with-json-space-config-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/space-space-style-config-space-constructor-with-json-space-config-chromium.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/space-space-style-config-space-false-with-json-style-config-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/space-space-style-config-space-false-with-json-style-config-chromium.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/space-space-style-config-space-false-with-style-config-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/haloSpace.test.ts-snapshots/space-space-style-config-space-true-no-style-config-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/map-load.test.ts-snapshots/halo-halo-json-style-config-halo-rendered-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/map-load.test.ts-snapshots/halo-halo-json-style-config-halo-true-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/map-load.test.ts-snapshots/halo-halo-style-config-halo-json-default-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/map-load.test.ts-snapshots/halo-halo-style-config-halo-json-false-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/map-load.test.ts-snapshots/halo-halo-style-config-halo-json-valid-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/map-load.test.ts-snapshots/space-space-json-style-config-space-true-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/map-load.test.ts-snapshots/space-space-json-style-config-space-true-chromium.png +0 -0
- package/e2e/snapshots/tests/map-load.test.ts-snapshots/space-space-json-style-config-space-true-default-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/map-load.test.ts-snapshots/space-space-style-config-space-constructor-with-json-space-config-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/map-load.test.ts-snapshots/space-space-style-config-space-false-with-json-style-config-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/rtlTextPlugin.test.ts-snapshots/halo-halo-json-style-config-halo-rendered-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/rtlTextPlugin.test.ts-snapshots/halo-halo-json-style-config-halo-true-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/rtlTextPlugin.test.ts-snapshots/halo-halo-style-config-halo-json-default-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/rtlTextPlugin.test.ts-snapshots/halo-halo-style-config-halo-json-false-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/rtlTextPlugin.test.ts-snapshots/halo-halo-style-config-halo-json-valid-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/rtlTextPlugin.test.ts-snapshots/space-space-json-style-config-space-true-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/rtlTextPlugin.test.ts-snapshots/space-space-json-style-config-space-true-default-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/rtlTextPlugin.test.ts-snapshots/space-space-style-config-space-constructor-with-json-space-config-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/rtlTextPlugin.test.ts-snapshots/space-space-style-config-space-false-with-json-style-config-chromium-linux.png +0 -0
- package/e2e/tests/AnimatedRouteLayer.test.ts +45 -0
- package/e2e/tests/consts.ts +0 -0
- package/e2e/tests/expected-results/animatedRouteLayer-1.json +202 -0
- package/e2e/tests/haloSpace.test.ts +809 -0
- package/e2e/tests/helpers/fetchGeojson.ts +21 -0
- package/e2e/tests/helpers/getMapInstanceForFixture.ts +87 -0
- package/e2e/tests/helpers/injectGlobalVariables.ts +13 -0
- package/e2e/tests/helpers/loadFixtureAndGetMapHandle.ts +46 -36
- package/e2e/tests/mocks/maptiler-style-space-halo-invalid.json +38 -0
- package/e2e/tests/mocks/maptiler-style-space-halo.json +41 -0
- package/e2e/tests/mocks/maptiler-style.json +1 -0
- package/e2e/tests/rtlTextPlugin.test.ts +3 -12
- package/e2e/tsconfig.json +1 -1
- package/eslint.config.mjs +8 -0
- package/package.json +11 -4
- package/playwright.config.ts +7 -2
- package/tsconfig.json +1 -1
- package/vitest-setup-tests.ts +16 -0
- package/e2e/snapshots/tests/rtlTextPlugin.test.ts-snapshots/rtlTextPlugin-active-chromium-linux.png +0 -0
- package/e2e/snapshots/tests/rtlTextPlugin.test.ts-snapshots/rtlTextPlugin-disabled-chromium-linux.png +0 -0
|
@@ -4,7 +4,7 @@ import { Map } from '../Map';
|
|
|
4
4
|
import { ImageViewerFitImageToBoundsControl } from '../controls/ImageViewerFitImageToBoundsControl';
|
|
5
5
|
import { lngLatToPxInternalSymbolKey, pxToLngLatInternalSymbolKey } from './symbols';
|
|
6
6
|
declare const Evented: typeof MaplibreGL.Evented;
|
|
7
|
-
export type
|
|
7
|
+
export type AllowedConstructorOptions = "container" | "apiKey" | "maxZoom" | "minZoom" | "zoom" | "bearing";
|
|
8
8
|
export type ImageViewerFlyToOptions = Omit<FlyToOptions, "pitch"> & {
|
|
9
9
|
center: [number, number];
|
|
10
10
|
};
|
|
@@ -14,7 +14,7 @@ export type ImageViewerJumpToOptions = Omit<JumpToOptions, "pitch"> & {
|
|
|
14
14
|
export type ImageViewerEaseToOptions = Omit<EaseToOptions, "pitch"> & {
|
|
15
15
|
center: [number, number];
|
|
16
16
|
};
|
|
17
|
-
export type ImageViewerConstructorOptions = Pick<MapOptions,
|
|
17
|
+
export type ImageViewerConstructorOptions = Pick<MapOptions, AllowedConstructorOptions> & {
|
|
18
18
|
/**
|
|
19
19
|
* The UUID of the image.
|
|
20
20
|
*/
|
package/dist/src/Map.d.ts
CHANGED
|
@@ -154,6 +154,22 @@ export type MapOptions = Omit<MapOptionsML, "style" | "maplibreLogo"> & {
|
|
|
154
154
|
*/
|
|
155
155
|
rtlTextPlugin?: boolean | string;
|
|
156
156
|
};
|
|
157
|
+
/**
|
|
158
|
+
* Options to provide to the {@link Map.setProjection} method
|
|
159
|
+
*/
|
|
160
|
+
export interface ProjectionChangeOptions {
|
|
161
|
+
/**
|
|
162
|
+
* Whether the new projection should be persisted for any future style changes.
|
|
163
|
+
*
|
|
164
|
+
* If `true`, the new projection is persisted and is applied after all future style changes.
|
|
165
|
+
* If `false` or not specified, the new projection will be used only until the next style change, when it will get replaced with the first applicable value from this list:
|
|
166
|
+
* - a previously persisted projection
|
|
167
|
+
* - a projection specified in {@link Map} constructor options ({@link MapOptions})
|
|
168
|
+
* - a projection specified in `projection` property of the style itself
|
|
169
|
+
* - the Mercator projection
|
|
170
|
+
*/
|
|
171
|
+
persist?: boolean;
|
|
172
|
+
}
|
|
157
173
|
/**
|
|
158
174
|
* The Map class can be instanciated to display a map in a `<div>`
|
|
159
175
|
*/
|
|
@@ -467,14 +483,38 @@ export declare class Map extends maplibregl.Map {
|
|
|
467
483
|
*/
|
|
468
484
|
isGlobeProjection(): boolean;
|
|
469
485
|
/**
|
|
470
|
-
* Activate the globe projection.
|
|
486
|
+
* Activate the globe projection and persist this change during future style changes.
|
|
487
|
+
* @deprecated Will be removed in v4.0.0. Use `map.setProjection("globe", { persist: true })` instead.
|
|
471
488
|
*/
|
|
472
489
|
enableGlobeProjection(): void;
|
|
473
490
|
/**
|
|
474
|
-
* Activate the mercator projection.
|
|
491
|
+
* Activate the mercator projection and persist this change during future style changes.
|
|
492
|
+
* @deprecated Will be removed in v4.0.0. Use `map.setProjection("mercator", { persist: true })` instead.
|
|
475
493
|
*/
|
|
476
494
|
enableMercatorProjection(): void;
|
|
495
|
+
/**
|
|
496
|
+
* Sets the projection to one of {@linkcode ProjectionTypes}.
|
|
497
|
+
* @param projection - the projection type to set
|
|
498
|
+
* @param options - configure behaviour of the projection change
|
|
499
|
+
*/
|
|
500
|
+
setProjection(projection: NonNullable<ProjectionTypes>, options?: ProjectionChangeOptions): this;
|
|
501
|
+
/**
|
|
502
|
+
* Sets the projection to one of {@linkcode ProjectionTypes}.
|
|
503
|
+
* @param projection - the projection type to set, wrapped in {@link ProjectionSpecification}
|
|
504
|
+
* @param options - configure behaviour of the projection change
|
|
505
|
+
*/
|
|
506
|
+
setProjection(projection: {
|
|
507
|
+
type: NonNullable<ProjectionTypes>;
|
|
508
|
+
}, options?: ProjectionChangeOptions): this;
|
|
509
|
+
/**
|
|
510
|
+
* Sets the projection to a {@linkcode ProjectionSpecification}.
|
|
511
|
+
* @param projection - the projection specification to set
|
|
512
|
+
*/
|
|
477
513
|
setProjection(projection: maplibregl.ProjectionSpecification): this;
|
|
514
|
+
/**
|
|
515
|
+
* Forget the persisted projection - from both constructor option and result of any `map.setProjection(..., { persist: true })` calls.
|
|
516
|
+
*/
|
|
517
|
+
forgetPersistedProjection(): this;
|
|
478
518
|
/**
|
|
479
519
|
* Returns `true` is the language was ever updated, meaning changed
|
|
480
520
|
* from what is delivered in the style.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { MaptilerAnimation } from './index';
|
|
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;
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { AnimationEventCallback, AnimationEventTypes, EasingFunctionName, Keyframe } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for creating an animation.
|
|
4
|
+
*
|
|
5
|
+
* @interface MaptilerAnimationOptions
|
|
6
|
+
* @property {Keyframe[]} keyframes - The keyframes that define the animation states at various points in time.
|
|
7
|
+
* @property {number} duration - The total duration of the animation in milliseconds.
|
|
8
|
+
* @property {number} iterations - The number of times the animation should repeat. Use 0 for no repeat, or Infinity for an infinite loop.
|
|
9
|
+
* @property {delay} [delay] - Optional. The delay before the animation starts, in milliseconds. Defaults to 0 if not specified.
|
|
10
|
+
* @property {boolean} [manualMode] - Optional. If true, the animation will not be automatically managed by the animation manager
|
|
11
|
+
* and must be updated manually by calling update(). Defaults to false if not specified.
|
|
12
|
+
*/
|
|
13
|
+
export interface MaptilerAnimationOptions {
|
|
14
|
+
keyframes: Keyframe[];
|
|
15
|
+
duration: number;
|
|
16
|
+
iterations: number;
|
|
17
|
+
manualMode?: boolean;
|
|
18
|
+
delay?: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A keyframe in the animation sequence where null or undefined values
|
|
22
|
+
* are interpolated to fill in the gaps between keyframes.
|
|
23
|
+
*
|
|
24
|
+
* @extends Keyframe
|
|
25
|
+
* @property {Record<string, number>} props - The properties to be animated at this keyframe.
|
|
26
|
+
* @property {EasingFunctionName} easing - The easing function to use for this keyframe.
|
|
27
|
+
* @property {string} id - A unique identifier for this keyframe.
|
|
28
|
+
*/
|
|
29
|
+
export type InterpolatedKeyFrame = Keyframe & {
|
|
30
|
+
props: Record<string, number>;
|
|
31
|
+
easing: EasingFunctionName;
|
|
32
|
+
id: string;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Animation controller for keyframe-based animation sequences.
|
|
36
|
+
*
|
|
37
|
+
* MaptilerAnimation handles interpolation between keyframes, timing control,
|
|
38
|
+
* and event dispatching during animation playback.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const animation = new MaptilerAnimation({
|
|
43
|
+
* keyframes: [
|
|
44
|
+
* { delta: 0, props: { x: 0, y: 0 } },
|
|
45
|
+
* { delta: 0.5, props: { x: 50, y: 20 } },
|
|
46
|
+
* { delta: 1, props: { x: 100, y: 0 } }
|
|
47
|
+
* ],
|
|
48
|
+
* duration: 1000, // milliseconds
|
|
49
|
+
* iterations: 2
|
|
50
|
+
* });
|
|
51
|
+
*
|
|
52
|
+
* animation.addEventListener("timeupdate", (event) => {
|
|
53
|
+
* // Use interpolated property values to update something
|
|
54
|
+
* console.log(event.props);
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* animation.play();
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @remarks
|
|
61
|
+
* The animation supports various playback controls (play, pause, stop, reset),
|
|
62
|
+
* time manipulation, and an event system for tracking animation progress.
|
|
63
|
+
* Properties missing in keyframes will be automatically interpolated.
|
|
64
|
+
*
|
|
65
|
+
* Animation events include play, pause, stop, timeupdate, iteration, and more.
|
|
66
|
+
*
|
|
67
|
+
* When not using manualMode, animations are automatically added to the AnimationManager.
|
|
68
|
+
*/
|
|
69
|
+
export default class MaptilerAnimation {
|
|
70
|
+
private playing;
|
|
71
|
+
/**
|
|
72
|
+
* Indicates if the animation is currently playing
|
|
73
|
+
* @returns {boolean} - true if the animation is playing, false otherwise
|
|
74
|
+
*/
|
|
75
|
+
get isPlaying(): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* The number of times to repeat the animation
|
|
78
|
+
* 0 is no repeat, Infinity is infinite repeat
|
|
79
|
+
*/
|
|
80
|
+
private iterations;
|
|
81
|
+
private currentIteration;
|
|
82
|
+
/** An array of keyframes animations to interpolate between */
|
|
83
|
+
private keyframes;
|
|
84
|
+
/** The current keyframe id */
|
|
85
|
+
private currentKeyframe?;
|
|
86
|
+
/**The duration of the animation in milliseconds (when playbackRate === 1) */
|
|
87
|
+
readonly duration: number;
|
|
88
|
+
/**
|
|
89
|
+
* The duration of the animation affected by the playback rate
|
|
90
|
+
* if playback rate is 2, the effective duration is double
|
|
91
|
+
*/
|
|
92
|
+
private effectiveDuration;
|
|
93
|
+
/** the rate at which the animation is playing */
|
|
94
|
+
private playbackRate;
|
|
95
|
+
/** the current time in milliseconds */
|
|
96
|
+
private currentTime;
|
|
97
|
+
/** 0 start of the animation, 1 end of the animation */
|
|
98
|
+
private currentDelta;
|
|
99
|
+
/** The time at which the animation started */
|
|
100
|
+
private animationStartTime;
|
|
101
|
+
/** The time at which the last frame was rendered */
|
|
102
|
+
private lastFrameAt;
|
|
103
|
+
/** The delay before the animation starts */
|
|
104
|
+
private delay;
|
|
105
|
+
/** The timeout ID for the delay before the animation starts */
|
|
106
|
+
private delayTimeoutID?;
|
|
107
|
+
/** The listeners added for each event */
|
|
108
|
+
private listeners;
|
|
109
|
+
/** The props from the previous frame */
|
|
110
|
+
private previousProps;
|
|
111
|
+
constructor({ keyframes, duration, iterations, manualMode, delay }: MaptilerAnimationOptions);
|
|
112
|
+
/**
|
|
113
|
+
* Starts or resumes the animation
|
|
114
|
+
* @returns This animation instance for method chaining
|
|
115
|
+
* @event "play"
|
|
116
|
+
*/
|
|
117
|
+
play(): this;
|
|
118
|
+
/**
|
|
119
|
+
* Pauses the animation
|
|
120
|
+
* @returns This animation instance for method chaining
|
|
121
|
+
* @event "pause"
|
|
122
|
+
*/
|
|
123
|
+
pause(): this;
|
|
124
|
+
/**
|
|
125
|
+
* Stops the animation and resets to initial state
|
|
126
|
+
* @returns This animation instance for method chaining
|
|
127
|
+
* @event "stop"
|
|
128
|
+
*/
|
|
129
|
+
stop(silent?: boolean): this;
|
|
130
|
+
/**
|
|
131
|
+
* Resets the animation to its initial state without stopping
|
|
132
|
+
* @returns This animation instance for method chaining
|
|
133
|
+
* @event "reset"
|
|
134
|
+
*/
|
|
135
|
+
reset(manual?: boolean): this;
|
|
136
|
+
/**
|
|
137
|
+
* Updates the animation state if playing, this is used by the AnimationManager
|
|
138
|
+
* to update all animations in the loop
|
|
139
|
+
* @returns This animation instance for method chaining
|
|
140
|
+
*/
|
|
141
|
+
updateInternal(): this;
|
|
142
|
+
/**
|
|
143
|
+
* Updates the animation state, interpolating between keyframes
|
|
144
|
+
* and emitting events as necessary
|
|
145
|
+
* @event "timeupdate"
|
|
146
|
+
* @event "keyframe"
|
|
147
|
+
* @event "iteration"
|
|
148
|
+
* @event "animationend"
|
|
149
|
+
* @returns This animation instance for method chaining
|
|
150
|
+
*/
|
|
151
|
+
update(manual?: boolean, ignoreIteration?: boolean): this;
|
|
152
|
+
/**
|
|
153
|
+
* Gets the current and next keyframes at a specific time
|
|
154
|
+
* @param time - The time position to query
|
|
155
|
+
* @returns Object containing current and next keyframes, which may be null
|
|
156
|
+
*/
|
|
157
|
+
getCurrentAndNextKeyFramesAtTime(time: number): {
|
|
158
|
+
current: InterpolatedKeyFrame | null;
|
|
159
|
+
next: InterpolatedKeyFrame | null;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Gets the current and next keyframes at a specific delta value
|
|
163
|
+
* @param delta - The delta value to query
|
|
164
|
+
* @returns Object containing current and next keyframes, which may be null
|
|
165
|
+
*/
|
|
166
|
+
getCurrentAndNextKeyFramesAtDelta(delta: number): {
|
|
167
|
+
current: InterpolatedKeyFrame | null;
|
|
168
|
+
next: InterpolatedKeyFrame | null;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Gets the current time position of the animation
|
|
172
|
+
* @returns The current time in milliseconds
|
|
173
|
+
*/
|
|
174
|
+
getCurrentTime(): number;
|
|
175
|
+
/**
|
|
176
|
+
* Sets the current time position of the animation
|
|
177
|
+
* @param time - The time to set in milliseconds
|
|
178
|
+
* @returns This animation instance for method chaining
|
|
179
|
+
* @throws Error if time is greater than the duration
|
|
180
|
+
* @event "scrub"
|
|
181
|
+
*/
|
|
182
|
+
setCurrentTime(time: number): this;
|
|
183
|
+
/**
|
|
184
|
+
* Gets the current delta value of the animation
|
|
185
|
+
* @returns The current delta value (normalized progress between 0 and 1)
|
|
186
|
+
*/
|
|
187
|
+
getCurrentDelta(): number;
|
|
188
|
+
/**
|
|
189
|
+
* Sets the current delta value of the animation
|
|
190
|
+
* @param delta - The delta value to set (normalized progress between 0 and 1)
|
|
191
|
+
* @returns This animation instance for method chaining
|
|
192
|
+
* @throws Error if delta is greater than 1
|
|
193
|
+
* @event "scrub"
|
|
194
|
+
*/
|
|
195
|
+
setCurrentDelta(delta: number): this;
|
|
196
|
+
/**
|
|
197
|
+
* Sets the playback rate of the animation
|
|
198
|
+
* @param rate - The playback rate (1.0 is normal speed)
|
|
199
|
+
* @returns This animation instance for method chaining
|
|
200
|
+
* @event "playbackratechange"
|
|
201
|
+
*/
|
|
202
|
+
setPlaybackRate(rate: number): this;
|
|
203
|
+
/**
|
|
204
|
+
* Gets the current playback rate
|
|
205
|
+
* @returns The current playback rate
|
|
206
|
+
*/
|
|
207
|
+
getPlaybackRate(): number;
|
|
208
|
+
/**
|
|
209
|
+
* Adds an event listener to the animation
|
|
210
|
+
* @param type - The type of event to listen for
|
|
211
|
+
* @param callback - The callback function to execute when the event occurs
|
|
212
|
+
* @returns This animation instance for method chaining
|
|
213
|
+
*/
|
|
214
|
+
addEventListener(type: AnimationEventTypes, callback: AnimationEventCallback): this;
|
|
215
|
+
/**
|
|
216
|
+
* Removes an event listener from the animation
|
|
217
|
+
* @param type - The type of event to remove
|
|
218
|
+
* @param callback - The callback function to remove
|
|
219
|
+
* @returns This animation instance for method chaining
|
|
220
|
+
*/
|
|
221
|
+
removeEventListener(type: AnimationEventTypes, callback: AnimationEventCallback): this;
|
|
222
|
+
/**
|
|
223
|
+
* Emits an event to all listeners of a specific type
|
|
224
|
+
* @param event - The type of event to emit
|
|
225
|
+
* @param keyframe - The keyframe that triggered the event
|
|
226
|
+
* @param props - The interpolated properties at the current delta
|
|
227
|
+
*/
|
|
228
|
+
emitEvent(event: AnimationEventTypes, keyframe?: Keyframe | null, nextKeyframe?: Keyframe | null, props?: Record<string, number>, previousProps?: Record<string, number>): void;
|
|
229
|
+
/**
|
|
230
|
+
* Creates a clone of this animation
|
|
231
|
+
* @returns A new animation instance with the same properties as this one
|
|
232
|
+
*/
|
|
233
|
+
clone(): MaptilerAnimation;
|
|
234
|
+
/**
|
|
235
|
+
* Destroys the animation instance, removing all event listeners and stopping playback
|
|
236
|
+
*/
|
|
237
|
+
destroy(): void;
|
|
238
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { Feature, LineString, MultiLineString, MultiPoint, Polygon } from 'geojson';
|
|
2
|
+
import { EasingFunctionName, Keyframe, NumericArrayWithNull } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Performs simple linear interpolation between two numbers.
|
|
5
|
+
*
|
|
6
|
+
* @param a - The start value
|
|
7
|
+
* @param b - The end value
|
|
8
|
+
* @param alpha - The interpolation factor (typically between 0 and 1):
|
|
9
|
+
* 0 returns a, 1 returns b, and values in between return a proportional mix
|
|
10
|
+
* @returns The interpolated value between a and b
|
|
11
|
+
*/
|
|
12
|
+
export declare function lerp(a: number, b: number, alpha: number): number;
|
|
13
|
+
/**
|
|
14
|
+
* Interpolates an array of numbers, replacing null values with interpolated values.
|
|
15
|
+
*
|
|
16
|
+
* `null` is treated as an empty value where an interpolation is needed.
|
|
17
|
+
*
|
|
18
|
+
* @param {NumericArrayWithNull} numericArray - The array of numbers to interpolate, which may contain null values
|
|
19
|
+
* @returns A new array with null values replaced by interpolated values
|
|
20
|
+
*/
|
|
21
|
+
export declare function lerpArrayValues(numericArray: NumericArrayWithNull): number[];
|
|
22
|
+
/**
|
|
23
|
+
* Looks ahead in an array for the next entry that is not null.
|
|
24
|
+
*
|
|
25
|
+
* @param arr - The array to search through
|
|
26
|
+
* @param currentIndex - The index to start searching from
|
|
27
|
+
* @returns [index, value] A tuple containing the index of the next entry and its value, or null if not found
|
|
28
|
+
*/
|
|
29
|
+
export declare function findNextEntryAndIndexWithValue(arr: NumericArrayWithNull, currentIndex: number): (number | null)[];
|
|
30
|
+
/**
|
|
31
|
+
* Looks back in an array for the previous entry that is not null.
|
|
32
|
+
*
|
|
33
|
+
* @param arr - The array to search through
|
|
34
|
+
* @param currentIndex - The index to start searching from
|
|
35
|
+
* @returns [index, value] A tuple containing the index of the previous entry and its value, or null if not found
|
|
36
|
+
*/
|
|
37
|
+
export declare function findPreviousEntryAndIndexWithValue(arr: NumericArrayWithNull, currentIndex: number): (number | null)[];
|
|
38
|
+
/**
|
|
39
|
+
* Options for parsing GeoJSON data into animation keyframes.
|
|
40
|
+
*
|
|
41
|
+
* @interface ParseGeoJSONToKeyframesOptions
|
|
42
|
+
* @property {EasingFunctionName} [defaultEasing] - The default easing function to apply to the animation.
|
|
43
|
+
* @property {Object|false} [pathSmoothing] - Configuration for path smoothing, or false to disable smoothing.
|
|
44
|
+
* @property {number} [pathSmoothing.resolution] - The resolution used for path smoothing, higher values produce more detailed paths.
|
|
45
|
+
* @property {number} [pathSmoothing.epsilon] - Optional tolerance parameter for path simplification.
|
|
46
|
+
*/
|
|
47
|
+
export interface ParseGeoJSONToKeyframesOptions {
|
|
48
|
+
ignoreFields?: string[];
|
|
49
|
+
defaultEasing?: EasingFunctionName;
|
|
50
|
+
pathSmoothing?: {
|
|
51
|
+
resolution: number;
|
|
52
|
+
epsilon?: number;
|
|
53
|
+
} | false;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Represents geometry types that can be animated using keyframes.
|
|
57
|
+
*
|
|
58
|
+
* This type includes geometries like MultiPoint, LineString, MultiLineString, and Polygon
|
|
59
|
+
* which can be interpolated or transformed over time in animations.
|
|
60
|
+
*/
|
|
61
|
+
export type KeyframeableGeometry = MultiPoint | LineString | MultiLineString | Polygon;
|
|
62
|
+
/**
|
|
63
|
+
* Represents a GeoJSON Feature that can be animated with keyframes.
|
|
64
|
+
* Extends the standard GeoJSON Feature with animation-specific properties.
|
|
65
|
+
*
|
|
66
|
+
* @typedef {Object} KeyframeableGeoJSONFeature
|
|
67
|
+
* @extends {Feature<KeyframeableGeometry>}
|
|
68
|
+
* @property {Object} properties - Contains both standard GeoJSON properties (as number arrays) and animation controls
|
|
69
|
+
* @property {EasingFunctionName[]} [properties.@easing] - Easing functions to apply to property animations
|
|
70
|
+
* @property {number[]} [properties.@delta] - Delta values for animation calculations
|
|
71
|
+
* @property {number} [properties.@duration] - Duration of the animation in milliseconds
|
|
72
|
+
* @property {number} [properties.@delay] - Delay before animation starts in milliseconds
|
|
73
|
+
* @property {number} [properties.@iterations] - Number of times the animation should repeat
|
|
74
|
+
* @property {boolean} [properties.@autoplay] - Whether the animation should start automatically
|
|
75
|
+
*/
|
|
76
|
+
export type KeyframeableGeoJSONFeature = Feature<KeyframeableGeometry> & {
|
|
77
|
+
properties: Record<string, number[] | boolean | number | EasingFunctionName[]> & {
|
|
78
|
+
"@easing"?: EasingFunctionName[];
|
|
79
|
+
"@delta"?: number[];
|
|
80
|
+
"@duration"?: number;
|
|
81
|
+
"@delay"?: number;
|
|
82
|
+
"@iterations"?: number;
|
|
83
|
+
"@autoplay"?: boolean;
|
|
84
|
+
altitude?: (number | null)[];
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Converts a GeoJSON feature into an array of animation keyframes.
|
|
89
|
+
*
|
|
90
|
+
* Parses a GeoJSON feature with reserved properties to create animation keyframes.
|
|
91
|
+
* It extracts coordinates from the geometry and uses properties prefixed with '@' as animation
|
|
92
|
+
* control parameters (easing functions, delta values). Non-reserved properties are preserved
|
|
93
|
+
* and passed to the keyframe objects as props that will be interpolated
|
|
94
|
+
*
|
|
95
|
+
* @param {KeyframeableGeoJSONFeature} feature - The GeoJSON feature to convert to keyframes
|
|
96
|
+
* @param {ParseGeoJSONToKeyframesOptions} options - Configuration options
|
|
97
|
+
*
|
|
98
|
+
* @returns Array of keyframe objects that can be used for animation
|
|
99
|
+
*
|
|
100
|
+
* @throws {Error} When no geometry is found in the feature
|
|
101
|
+
* @throws {Error} When the geometry type is not supported
|
|
102
|
+
*/
|
|
103
|
+
export declare function parseGeoJSONFeatureToKeyframes(feature: KeyframeableGeoJSONFeature, options?: ParseGeoJSONToKeyframesOptions): Keyframe[];
|
|
104
|
+
/**
|
|
105
|
+
*
|
|
106
|
+
* "Stretches" an array of numbers to a new length, filling in null values for the new indices.
|
|
107
|
+
*
|
|
108
|
+
* @param source the array to stretch
|
|
109
|
+
* @param targetLength the length to stretch to
|
|
110
|
+
* @returns {number[]} the stretched array with null values
|
|
111
|
+
*/
|
|
112
|
+
export declare function stretchNumericalArray(source: number[], targetLength: number): (number | null)[];
|
|
113
|
+
/**
|
|
114
|
+
* Generates an array of keyframes from coordinates, deltas, easings, and other properties provided by the geoJSON feature.
|
|
115
|
+
* Assumes that the coordinates are in the format [longitude, latitude, altitude?]. If altitude is not provided, it defaults to 0.
|
|
116
|
+
*
|
|
117
|
+
* @param coordinates - Array of coordinate points, where each point is an array of [longitude, latitude, altitude?]
|
|
118
|
+
* @param deltas - Array of time deltas between keyframes
|
|
119
|
+
* @param easings - Array of easing function names to apply to each keyframe transition
|
|
120
|
+
* @param properties - Optional additional properties as key-value pairs, where each value is an array
|
|
121
|
+
* of numbers corresponding to each keyframe
|
|
122
|
+
*
|
|
123
|
+
* @returns An array of Keyframe objects, each containing coordinate props, delta, and easing information
|
|
124
|
+
*
|
|
125
|
+
* @throws Error if the arrays for coordinates, deltas, easings, and any property values don't have matching lengths
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* const keyframes = getKeyframes(
|
|
129
|
+
* [[0, 0, 10], [10, 10, 20]], // coordinates
|
|
130
|
+
* [1000, 2000], // deltas (in milliseconds)
|
|
131
|
+
* ["Linear", "ElasticIn"], // easings
|
|
132
|
+
* { zoom: [10, 15] } // additional properties
|
|
133
|
+
* );
|
|
134
|
+
*/
|
|
135
|
+
export declare function getKeyframes(coordinates: number[][], deltas: number[], easings: EasingFunctionName[], properties?: Record<string, number[]>): Keyframe[];
|
|
136
|
+
/**
|
|
137
|
+
* Creates a smoothed path using cubic Bezier curves from an array of coordinates.
|
|
138
|
+
*
|
|
139
|
+
* This function takes a series of points and creates a smooth path by generating cubic
|
|
140
|
+
* Bezier curves between them. It uses the Catmull-Rom method to automatically calculate
|
|
141
|
+
* control points for each curve segment. If the path has fewer than 4 points, the original
|
|
142
|
+
* path is returned unchanged.
|
|
143
|
+
*
|
|
144
|
+
* @param inputPath - Array of [x, y] coordinates that define the original path
|
|
145
|
+
* @param outputResolution - Controls how many points are generated along each segment
|
|
146
|
+
* (higher values create smoother curves with more points)
|
|
147
|
+
* @param simplificationThreshold - Optional threshold for simplifying the input path before
|
|
148
|
+
* creating the curves.
|
|
149
|
+
* @returns An array of [x, y] coordinates representing the smoothed path
|
|
150
|
+
*/
|
|
151
|
+
export declare function createBezierPathFromCoordinates(inputPath: [number, number][], outputResolution?: number, simplificationThreshold?: number): [number, number][];
|
|
152
|
+
/**
|
|
153
|
+
* Calculates the average distance between points in an array of coordinates.
|
|
154
|
+
*
|
|
155
|
+
* This function computes the average distance between consecutive points in the array.
|
|
156
|
+
* It uses the LngLat class from MapLibre to calculate distances based on geographical coordinates.
|
|
157
|
+
*
|
|
158
|
+
* @param arr - An array of coordinate pairs [longitude, latitude]
|
|
159
|
+
* @returns The average distance between points in the array
|
|
160
|
+
*/
|
|
161
|
+
export declare function getAverageDistance(arr: [number, number][]): number;
|
|
162
|
+
/**
|
|
163
|
+
* Simplfies a path by removing points that are too close together.
|
|
164
|
+
*
|
|
165
|
+
* This function first resamples the path based on the average distance between points,
|
|
166
|
+
* then filters out points that are closer than the specified distance from the last included point.
|
|
167
|
+
* The first and last points of the original path are always preserved.
|
|
168
|
+
*
|
|
169
|
+
* @param points - An array of coordinate pairs [longitude, latitude]
|
|
170
|
+
* @param distance - The minimum distance between points in the simplified path
|
|
171
|
+
* @returns A new array containing a simplified version of the input path
|
|
172
|
+
*/
|
|
173
|
+
export declare function simplifyPath(points: [number, number][], distance: number): [number, number][];
|
|
174
|
+
/**
|
|
175
|
+
* Resamples a geographic path to have points spaced at approximately equal distances.
|
|
176
|
+
* If the original path has fewer than 2 points, it is returned unchanged.
|
|
177
|
+
*
|
|
178
|
+
* @param path - An array of coordinate pairs [longitude, latitude] representing the path to resample
|
|
179
|
+
* @param spacing - The desired spacing between points in the resampled path (in the same unit as used by the distanceTo method), defaults to 10
|
|
180
|
+
* @returns A new array of coordinate pairs representing the resampled path with approximately equal spacing between points
|
|
181
|
+
*
|
|
182
|
+
*/
|
|
183
|
+
export declare function resamplePath(path: [number, number][], spacing?: number): [number, number][];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { default as MaptilerAnimation } from './MaptilerAnimation';
|
|
2
|
+
export { MaptilerAnimation };
|
|
3
|
+
export type * from './MaptilerAnimation';
|
|
4
|
+
export type * from './types';
|
|
5
|
+
export * from './easing';
|
|
6
|
+
export { type KeyframeableGeometry, type KeyframeableGeoJSONFeature, lerp, lerpArrayValues, parseGeoJSONFeatureToKeyframes, createBezierPathFromCoordinates, getAverageDistance, simplifyPath, resamplePath, stretchNumericalArray, } from './animation-helpers';
|
|
7
|
+
export type * from './animation-helpers';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { default as MaptilerAnimation } from './MaptilerAnimation';
|
|
2
|
+
export type EasingFunctionName = "Linear" | "QuadraticIn" | "QuadraticOut" | "QuadraticInOut" | "CubicIn" | "CubicOut" | "CubicInOut" | "SinusoidalIn" | "SinusoidalOut" | "SinusoidalInOut" | "ExponentialIn" | "ExponentialOut" | "ExponentialInOut" | "ElasticIn" | "ElasticOut" | "ElasticInOut" | "BounceIn" | "BounceOut" | "BounceInOut";
|
|
3
|
+
export type Keyframe = {
|
|
4
|
+
props: Record<string, number | null>;
|
|
5
|
+
delta: number;
|
|
6
|
+
easing?: EasingFunctionName;
|
|
7
|
+
userData?: Record<string, any>;
|
|
8
|
+
};
|
|
9
|
+
export type AnimationEventTypes = "pause" | "reset" | "play" | "stop" | "timeupdate" | "scrub" | "playbackratechange" | "animationstart" | "animationend" | "keyframe" | "iteration";
|
|
10
|
+
export declare const AnimationEventTypesArray: AnimationEventTypes[];
|
|
11
|
+
export type NumericArrayWithNull = (number | null)[];
|
|
12
|
+
export type AnimationEvent = {
|
|
13
|
+
type: AnimationEventTypes;
|
|
14
|
+
target: MaptilerAnimation;
|
|
15
|
+
currentTime: number;
|
|
16
|
+
currentDelta: number;
|
|
17
|
+
playbackRate: number;
|
|
18
|
+
keyframe?: Keyframe | null;
|
|
19
|
+
nextKeyframe?: Keyframe | null;
|
|
20
|
+
props: Record<string, number>;
|
|
21
|
+
previousProps: Record<string, number>;
|
|
22
|
+
iteration?: number;
|
|
23
|
+
};
|
|
24
|
+
export type AnimationEventListenersRecord = Record<AnimationEventTypes, AnimationEventCallback[]>;
|
|
25
|
+
export type AnimationEventCallback = (event: AnimationEvent) => void;
|
|
26
|
+
export { MaptilerAnimation };
|