@maptiler/sdk 4.0.3-rc.1 → 4.1.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.
@@ -162,7 +162,13 @@ export type SortKeyRange = SymbolBucket["sortKeyRanges"][number];
162
162
  /** @deprecated Will be removed from public API in MapTiler SDK v4 */
163
163
  export type Entry = GlyphManager["entries"][string];
164
164
  /** @deprecated Will be removed from public API in MapTiler SDK v4 */
165
- export type PoolObject = ReturnType<RenderPool["getObjectForId"]>;
165
+ export type PoolObject = {
166
+ id: number;
167
+ fbo: Framebuffer;
168
+ texture: Texture;
169
+ stamp: number;
170
+ inUse: boolean;
171
+ };
166
172
  /** @deprecated Will be removed from public API in MapTiler SDK v4 */
167
173
  export type RenderPass = "offscreen" | "opaque" | "translucent";
168
174
  /** @deprecated Will be removed from public API in MapTiler SDK v4 */
@@ -504,8 +510,6 @@ type GlyphManager = Painter["glyphManager"];
504
510
  /** @deprecated Will be removed from public API in MapTiler SDK v4 */
505
511
  type RenderToTexture = Painter["renderToTexture"];
506
512
  /** @deprecated Will be removed from public API in MapTiler SDK v4 */
507
- type RenderPool = RenderToTexture["pool"];
508
- /** @deprecated Will be removed from public API in MapTiler SDK v4 */
509
513
  type CollisionIndex = Placement["collisionIndex"];
510
514
  /** @deprecated Will be removed from public API in MapTiler SDK v4 */
511
515
  type RGBAImage = StyleImageData["data"];
@@ -0,0 +1,96 @@
1
+ import { Map as SDKMap } from '../Map';
2
+ import { PreloadTilesForBoundsOptions, PreloadTilesForCameraPositionsOptions, PreloadTilesForLinearPathOptions, PreloadTilesOptions, TileCoord } from './types';
3
+ /**
4
+ * Handles tile preloading for a {@link Map} instance.
5
+ *
6
+ * Prefetches tiles for every active tile source in the current style and stores
7
+ * them in the SDK tile cache so MapLibre can render them without a network
8
+ * round-trip.
9
+ *
10
+ * Preload strategies include geographic bounds with a zoom range
11
+ * (`preloadForBounds`), prefetch a tilePyramid for a LatLngBounds
12
+ * (`preloadForCameraPositions`), a sampled linear camera path
13
+ * (`preloadForLinearPath`), and explicit `"z/x/y"` tile IDs (`preloadByTileIDs`).
14
+ * Each method returns a `Promise` that resolves when the preloading is complete.
15
+ * Call `abortAll()` to cancel in-flight requests.
16
+ *
17
+ * @remarks
18
+ * **API Key Usage**: Every tile fetched by this class counts against your
19
+ * MapTiler Cloud API key quota. Prefer narrow zoom ranges and small geographic
20
+ * areas where possible, and use the `onProgress` callback to monitor consumption.
21
+ *
22
+ * If you update the version of the tile preloader, please update the version in the `EXPERIMENTAL_TILE_PRELOADING_VERSION` constant.
23
+ * @example
24
+ * ```ts
25
+ * import { EXPERIMENTAL_TILE_PRELOADING_VERSION } from "./version";
26
+
27
+ * EXPERIMENTAL_TILE_PRELOADING_VERSION = "0.2.0";
28
+ * ```
29
+ */
30
+ export declare class TilePreloader {
31
+ private readonly map;
32
+ private readonly activeAbortControllers;
33
+ constructor(map: SDKMap);
34
+ /**
35
+ * Cancels all in-flight preload requests. Called automatically when a new
36
+ * camera movement begins so stale prefetches do not waste quota.
37
+ */
38
+ abortAll(): void;
39
+ /**
40
+ * Preloads all tiles within a geographic bounds across a range of zoom levels.
41
+ *
42
+ * @remarks
43
+ * **API Key Usage**: Tile count grows exponentially with zoom level. A wide zoom
44
+ * range over a large area can trigger thousands of requests.
45
+ * @param {PreloadTilesForBoundsOptions} options Options for preloading tiles for bounds.
46
+ * @returns A promise that resolves when the preloading is complete.
47
+ * @example
48
+ * ```ts
49
+ * await map.preloadTilesForBounds({
50
+ * bounds: map.getBounds(),
51
+ * minZoom: 8,
52
+ * maxZoom: 12,
53
+ * });
54
+ */
55
+ preloadForBounds({ bounds, minZoom, maxZoom, onProgress, onError }: PreloadTilesForBoundsOptions): Promise<void>;
56
+ /**
57
+ * Preloads tiles visible from each of the given camera positions.
58
+ *
59
+ * @remarks
60
+ * **API Key Usage**: Each position triggers requests for all tiles visible from
61
+ * that viewpoint. More positions at higher zoom levels increase API usage significantly.
62
+ */
63
+ preloadForCameraPositions({ positions, onProgress, onError }: PreloadTilesForCameraPositionsOptions): Promise<TileCoord[]>;
64
+ /**
65
+ * Preloads a specific set of tiles by their IDs (`"z/x/y"` format).
66
+ * @param {PreloadTilesOptions} options - The options for preloading tiles by tile IDs.
67
+ * @returns A promise that resolves when the preloading is complete.
68
+ * @example
69
+ * ```ts
70
+ * await map.preloadByTileIDs({
71
+ * tileIDs: ["12/1205/1540", "12/1206/1540"],
72
+ * });
73
+ * ```
74
+ */
75
+ preloadByTileIDs({ tileIDs, onProgress, onError }: PreloadTilesOptions): Promise<void>;
76
+ /**
77
+ * Preloads tiles along a linear camera path (used by panTo and easeTo overrides).
78
+ * @param {PreloadTilesForLinearPathOptions} options - The options for preloading tiles along a linear camera path.
79
+ * @returns A promise that resolves when the preloading is complete.
80
+ * @example
81
+ * ```ts
82
+ * await map.preloadForLinearPath({
83
+ * start: { lng: -74.006, lat: 40.7128, zoom: 12 },
84
+ * end: { lng: -73.935, lat: 40.730, zoom: 14 },
85
+ * });
86
+ * ```
87
+ */
88
+ preloadForLinearPath({ start, end, onProgress, onError }: PreloadTilesForLinearPathOptions): Promise<TileCoord[]>;
89
+ /**
90
+ * Fetches tiles for the given tile coordinates and stores them in the SDK tile cache.
91
+ * @param tiles - The tile coordinates to fetch.
92
+ * @param {TilePreloadOptions} callbacks - The callbacks for the preloading.
93
+ * @returns A promise that resolves when the preloading is complete.
94
+ */
95
+ private fetchTiles;
96
+ }
@@ -0,0 +1,2 @@
1
+ export { TilePreloader } from './TilePreloader';
2
+ export type { CameraPosition, TilePreloadOptions, WithTilePreload, PreloadTilesForBoundsOptions, PreloadTilesForCameraPositionsOptions, PreloadTilesOptions, TilePreloadErrorCallback, TilePreloadProgressCallback, } from './types';
@@ -0,0 +1,57 @@
1
+ import { LngLatBoundsLike } from 'maplibre-gl';
2
+ import { CameraPosition, TileCoord } from './types';
3
+ /**
4
+ * Returns all tile coordinates that fall within the given geographic bounds
5
+ * at each integer zoom level from `minZoom` to `maxZoom` (inclusive).
6
+ *
7
+ * @internal
8
+ */
9
+ export declare function tilesForBounds(bounds: LngLatBoundsLike, minZoom: number, maxZoom: number): TileCoord[];
10
+ /**
11
+ * Returns all tile coordinates visible from a camera position given the
12
+ * current map viewport dimensions. Accounts for pitch by extending the
13
+ * visible area toward the horizon.
14
+ *
15
+ * @internal
16
+ */
17
+ export declare function tilesForCameraPosition(position: CameraPosition, viewportWidth: number, viewportHeight: number): TileCoord[];
18
+ /**
19
+ * Returns the geographic bounds visible from a camera position at the given
20
+ * viewport size. Matches the tile footprint used by {@link tilesForCameraPosition}
21
+ * without the extra padding margin.
22
+ *
23
+ * @internal
24
+ */
25
+ export declare function viewBoundsForCameraPosition(position: CameraPosition, viewportWidth: number, viewportHeight: number): LngLatBoundsLike;
26
+ /**
27
+ * Samples positions along a linear camera path (panTo, easeTo) at the
28
+ * given number of steps.
29
+ *
30
+ * @internal
31
+ */
32
+ export declare function sampleLinearPath(start: CameraPosition, end: CameraPosition, steps: number): CameraPosition[];
33
+ /**
34
+ * Parses a tile ID string in `"z/x/y"` format into a {@link TileCoord}.
35
+ * Returns `null` if the string is not valid.
36
+ *
37
+ * @internal
38
+ */
39
+ export declare function parseTileID(tileID: string): TileCoord | null;
40
+ /**
41
+ * Formats a {@link TileCoord} as a `"z/x/y"` string.
42
+ *
43
+ * @internal
44
+ */
45
+ export declare function formatTileID(tile: TileCoord): string;
46
+ /**
47
+ * Substitutes `{z}`, `{x}`, `{y}` placeholders in a tile URL template.
48
+ *
49
+ * @internal
50
+ */
51
+ export declare function buildTileUrl(urlTemplate: string, tile: TileCoord): string;
52
+ /**
53
+ * Deduplicates an array of tile coordinates using a string-keyed Set.
54
+ *
55
+ * @internal
56
+ */
57
+ export declare function deduplicateTiles(tiles: TileCoord[]): TileCoord[];
@@ -0,0 +1,144 @@
1
+ import { LngLatBoundsLike } from 'maplibre-gl';
2
+ /**
3
+ * Called after each tile fetch attempt during preloading.
4
+ *
5
+ * @param done - Number of tiles attempted so far (loaded or failed)
6
+ * @param total - Total number of tiles to preload
7
+ * @param tileID - ID of the tile just attempted, in `"z/x/y"` format
8
+ *
9
+ * @remarks
10
+ * **API Key Usage**: Each tile fetch counts against your MapTiler Cloud API key quota.
11
+ */
12
+ export type TilePreloadProgressCallback = (done: number, total: number, tileID?: string | null) => void;
13
+ /**
14
+ * Called when a tile fails to load during preloading.
15
+ *
16
+ * @param error - The error that occurred
17
+ */
18
+ export type TilePreloadErrorCallback = (error: unknown) => void;
19
+ /**
20
+ * Options shared by all tile preloading APIs.
21
+ *
22
+ * @remarks
23
+ * **API Key Usage**: Tile preloading issues one network request per tile per active source.
24
+ * These requests count against your MapTiler Cloud API key quota. Use `onProgress` to
25
+ * monitor consumption and prefer narrow zoom ranges and small bounds where possible.
26
+ */
27
+ export type TilePreloadOptions = {
28
+ /**
29
+ * Called after each tile fetch attempt, whether it succeeded or failed.
30
+ */
31
+ onProgress?: TilePreloadProgressCallback;
32
+ /**
33
+ * Called when a tile fails to load.
34
+ */
35
+ onError?: TilePreloadErrorCallback;
36
+ /**
37
+ * Maximum number of tiles to fetch across all sources. Tiles beyond this
38
+ * limit are silently dropped. Defaults to `512`.
39
+ *
40
+ * @remarks
41
+ * **API Key Usage**: Each tile counts against your MapTiler Cloud API key quota.
42
+ * Keep this value conservative, especially across wide zoom ranges.
43
+ *
44
+ * @defaultValue 512
45
+ */
46
+ maxTiles?: number;
47
+ };
48
+ /**
49
+ * Adds optional experimental tile preloading to camera animation method options.
50
+ */
51
+ export type WithTilePreload<T> = T & {
52
+ /**
53
+ * Experimental tile preloading options. This will only work if `useExperimentalTilePreloading` is set to `true` on the map options.
54
+ */
55
+ experimental_preload?: TilePreloadOptions;
56
+ };
57
+ /**
58
+ * Options for preloading all tiles within a geographic bounds across a range of zoom levels.
59
+ *
60
+ * @remarks
61
+ * **API Key Usage**: The number of tiles grows exponentially with zoom level. For example,
62
+ * a city-scale area at zoom 12–15 can result in thousands of tile requests per source.
63
+ * Each request counts against your MapTiler Cloud API key quota.
64
+ */
65
+ export type PreloadTilesForBoundsOptions = TilePreloadOptions & {
66
+ /**
67
+ * The geographic bounds to preload tiles for.
68
+ */
69
+ bounds: LngLatBoundsLike;
70
+ /**
71
+ * Minimum zoom level to preload (inclusive).
72
+ */
73
+ minZoom: number;
74
+ /**
75
+ * Maximum zoom level to preload (inclusive).
76
+ */
77
+ maxZoom: number;
78
+ };
79
+ /**
80
+ * A camera viewpoint used to determine which tiles are visible from that position.
81
+ */
82
+ export type CameraPosition = {
83
+ /** Longitude of the camera center */
84
+ lng: number;
85
+ /** Latitude of the camera center */
86
+ lat: number;
87
+ /** Zoom level */
88
+ zoom: number;
89
+ /** Camera pitch in degrees (default: 0) */
90
+ pitch?: number;
91
+ /** Camera bearing in degrees (default: 0) */
92
+ bearing?: number;
93
+ };
94
+ /**
95
+ * Options for preloading tiles visible from one or more camera positions.
96
+ *
97
+ * @remarks
98
+ * **API Key Usage**: Each position triggers tile requests for all tiles visible
99
+ * from that viewpoint. More positions and higher zoom levels result in more
100
+ * requests, each counting against your MapTiler Cloud API key quota.
101
+ */
102
+ export type PreloadTilesForCameraPositionsOptions = TilePreloadOptions & {
103
+ /**
104
+ * Camera positions to preload tiles for. Tiles visible from each position
105
+ * will be fetched and cached.
106
+ */
107
+ positions: CameraPosition[];
108
+ };
109
+ /**
110
+ * Options for preloading tiles along a linear camera path.
111
+ */
112
+ export type PreloadTilesForLinearPathOptions = TilePreloadOptions & {
113
+ /**
114
+ * Start camera position.
115
+ */
116
+ start: CameraPosition;
117
+ /**
118
+ * End camera position.
119
+ */
120
+ end: CameraPosition;
121
+ /**
122
+ * Number of steps to sample along the path.
123
+ */
124
+ steps?: number;
125
+ };
126
+ /**
127
+ * Options for preloading a specific set of tiles by their IDs.
128
+ *
129
+ * @remarks
130
+ * **API Key Usage**: Each tile ID results in one fetch per active map source.
131
+ * Each request counts against your MapTiler Cloud API key quota.
132
+ */
133
+ export type PreloadTilesOptions = TilePreloadOptions & {
134
+ /**
135
+ * Tile IDs to preload, in `"z/x/y"` format.
136
+ */
137
+ tileIDs: string[];
138
+ };
139
+ /** @internal */
140
+ export type TileCoord = {
141
+ z: number;
142
+ x: number;
143
+ y: number;
144
+ };
@@ -0,0 +1,2 @@
1
+ declare const EXPERIMENTAL_TILE_PRELOADING_VERSION = "0.1.0";
2
+ export { EXPERIMENTAL_TILE_PRELOADING_VERSION };
@@ -1 +1,2 @@
1
1
  export * from './dom';
2
+ export { lerp } from './math-utils';
@@ -4,5 +4,14 @@ declare function normalize(value: number, min: number, max: number): number;
4
4
  declare function diagonalOfSquare(side: number): number;
5
5
  type Lerpable = [number, number, number, number] | Vec4;
6
6
  declare function lerpVec4(a: Lerpable, b: Lerpable, t: number): Vec4;
7
- declare function lerp(a: number, b: number, t: number): number;
7
+ /**
8
+ * Performs simple linear interpolation between two numbers.
9
+ *
10
+ * @param a - The start value
11
+ * @param b - The end value
12
+ * @param alpha - The interpolation factor (typically between 0 and 1):
13
+ * 0 returns a, 1 returns b, and values in between return a proportional mix
14
+ * @returns The interpolated value between a and b
15
+ */
16
+ declare function lerp(a: number, b: number, alpha: number): number;
8
17
  export { minMax, normalize, diagonalOfSquare, lerpVec4, lerp };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maptiler/sdk",
3
- "version": "4.0.3-rc.1",
3
+ "version": "4.1.0-rc.1",
4
4
  "description": "The Javascript & TypeScript map SDK tailored for MapTiler Cloud",
5
5
  "author": "MapTiler",
6
6
  "module": "dist/maptiler-sdk.mjs",
@@ -73,7 +73,7 @@
73
73
  "@canvas/image-data": "^1.0.0",
74
74
  "@eslint/js": "^9.21.0",
75
75
  "@maptiler/3d": "^3.1.0",
76
- "@playwright/test": "^1.51.0",
76
+ "@playwright/test": "^1.60.0",
77
77
  "@types/color-convert": "^2.0.4",
78
78
  "@types/color-name": "^2.0.0",
79
79
  "@types/node": "^25.0.0",
@@ -106,7 +106,7 @@
106
106
  "events": "^3.3.0",
107
107
  "gl-matrix": "^3.4.4",
108
108
  "js-base64": "^3.7.7",
109
- "maplibre-gl": "~5.21.1",
109
+ "maplibre-gl": "5.24",
110
110
  "uuid": "^14.0.0"
111
111
  }
112
112
  }