forked from maplibre/maplibre-gl-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker_source.ts
117 lines (110 loc) · 3.84 KB
/
worker_source.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import type {ExpiryData, RequestParameters} from '../util/ajax';
import type {RGBAImage, AlphaImage} from '../util/image';
import type {GlyphPositions} from '../render/glyph_atlas';
import type {ImageAtlas} from '../render/image_atlas';
import type {OverscaledTileID} from './tile_id';
import type {Bucket} from '../data/bucket';
import type {FeatureIndex} from '../data/feature_index';
import type {CollisionBoxArray} from '../data/array_types.g';
import type {DEMEncoding} from '../data/dem_data';
import type {StyleGlyph} from '../style/style_glyph';
import type {StyleImage} from '../style/style_image';
import type {PromoteIdSpecification} from '@maplibre/maplibre-gl-style-spec';
import type {RemoveSourceParams} from '../util/actor_messages';
import type {IActor} from '../util/actor';
import type {StyleLayerIndex} from '../style/style_layer_index';
/**
* Parameters to identify a tile
*/
export type TileParameters = {
type: string;
source: string;
uid: string | number;
};
/**
* Parameters that are send when requesting to load a tile to the worker
*/
export type WorkerTileParameters = TileParameters & {
tileID: OverscaledTileID;
request?: RequestParameters;
zoom: number;
maxZoom?: number;
tileSize: number;
promoteId: PromoteIdSpecification;
pixelRatio: number;
showCollisionBoxes: boolean;
collectResourceTiming?: boolean;
returnDependencies?: boolean;
};
/**
* The paremeters needed in order to load a DEM tile
*/
export type WorkerDEMTileParameters = TileParameters & {
rawImageData: RGBAImage | ImageBitmap | ImageData;
encoding: DEMEncoding;
redFactor: number;
greenFactor: number;
blueFactor: number;
baseShift: number;
};
/**
* The worker tile's result type
*/
export type WorkerTileResult = ExpiryData & {
buckets: Array<Bucket>;
imageAtlas: ImageAtlas;
glyphAtlasImage: AlphaImage;
featureIndex: FeatureIndex;
collisionBoxArray: CollisionBoxArray;
rawTileData?: ArrayBuffer;
resourceTiming?: Array<PerformanceResourceTiming>;
// Only used for benchmarking:
glyphMap?: {
[_: string]: {
[_: number]: StyleGlyph;
};
} | null;
iconMap?: {
[_: string]: StyleImage;
} | null;
glyphPositions?: GlyphPositions | null;
};
/**
* This is how the @see {@link WorkerSource} constructor should look like.
*/
export interface WorkerSourceConstructor {
new (actor: IActor, layerIndex: StyleLayerIndex, availableImages: Array<string>): WorkerSource;
}
/**
* `WorkerSource` should be implemented by custom source types to provide code that can be run on the WebWorkers.
* Each of the methods has a relevant event that triggers it from the main thread with the relevant parameters.
* @see {@link Map#addSourceType}
*/
export interface WorkerSource {
availableImages: Array<string>;
/**
* Loads a tile from the given params and parse it into buckets ready to send
* back to the main thread for rendering. Should call the callback with:
* `{ buckets, featureIndex, collisionIndex, rawTileData}`.
*/
loadTile(params: WorkerTileParameters): Promise<WorkerTileResult>;
/**
* Re-parses a tile that has already been loaded. Yields the same data as
* {@link WorkerSource#loadTile}.
*/
reloadTile(params: WorkerTileParameters): Promise<WorkerTileResult>;
/**
* Aborts loading a tile that is in progress.
*/
abortTile(params: TileParameters): Promise<void>;
/**
* Removes this tile from any local caches.
*/
removeTile(params: TileParameters): Promise<void>;
/**
* Tells the WorkerSource to abort in-progress tasks and release resources.
* The foreground Source is responsible for ensuring that 'removeSource' is
* the last message sent to the WorkerSource.
*/
removeSource?: (params: RemoveSourceParams) => Promise<void>;
}