maplibre-gl-layers 0.1.0 → 0.2.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/README.md +1 -1
- package/dist/SpriteLayer.d.ts +15 -2
- package/dist/easing.d.ts +2 -2
- package/dist/index.cjs +292 -82
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +292 -82
- package/dist/index.mjs.map +1 -1
- package/dist/interpolation.d.ts +2 -2
- package/dist/location.d.ts +2 -2
- package/dist/math.d.ts +40 -4
- package/dist/numericInterpolation.d.ts +2 -2
- package/dist/rotationInterpolation.d.ts +2 -2
- package/dist/types.d.ts +346 -25
- package/dist/utils.d.ts +2 -2
- package/package.json +7 -7
package/dist/interpolation.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: maplibre-gl-layers
|
|
3
|
-
* version: 0.
|
|
3
|
+
* version: 0.2.0
|
|
4
4
|
* description: MapLibre's layer extension library enabling the display, movement, and modification of large numbers of dynamic sprite images
|
|
5
5
|
* author: Kouji Matsui (@kekyo@mi.kekyo.net)
|
|
6
6
|
* license: MIT
|
|
7
7
|
* repository.url: https://github.com/kekyo/maplibre-gl-layers.git
|
|
8
|
-
* git.commit.hash:
|
|
8
|
+
* git.commit.hash: 4fe3389ad068a5950d4f01e01ec9d3b34c049fb2
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { EasingFunction, SpriteInterpolationMode, SpriteInterpolationOptions, SpriteLocation } from './types';
|
package/dist/location.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: maplibre-gl-layers
|
|
3
|
-
* version: 0.
|
|
3
|
+
* version: 0.2.0
|
|
4
4
|
* description: MapLibre's layer extension library enabling the display, movement, and modification of large numbers of dynamic sprite images
|
|
5
5
|
* author: Kouji Matsui (@kekyo@mi.kekyo.net)
|
|
6
6
|
* license: MIT
|
|
7
7
|
* repository.url: https://github.com/kekyo/maplibre-gl-layers.git
|
|
8
|
-
* git.commit.hash:
|
|
8
|
+
* git.commit.hash: 4fe3389ad068a5950d4f01e01ec9d3b34c049fb2
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { SpriteLocation } from './types';
|
package/dist/math.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: maplibre-gl-layers
|
|
3
|
-
* version: 0.
|
|
3
|
+
* version: 0.2.0
|
|
4
4
|
* description: MapLibre's layer extension library enabling the display, movement, and modification of large numbers of dynamic sprite images
|
|
5
5
|
* author: Kouji Matsui (@kekyo@mi.kekyo.net)
|
|
6
6
|
* license: MIT
|
|
7
7
|
* repository.url: https://github.com/kekyo/maplibre-gl-layers.git
|
|
8
|
-
* git.commit.hash:
|
|
8
|
+
* git.commit.hash: 4fe3389ad068a5950d4f01e01ec9d3b34c049fb2
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { SpriteAnchor, SpriteImageOffset, SpriteLocation, SpriteScalingOptions } from './types';
|
|
@@ -185,6 +185,18 @@ export declare const applySurfaceDisplacement: (baseLng: number, baseLat: number
|
|
|
185
185
|
* @returns {[number, number]} Clip-space coordinates in the range [-1, 1].
|
|
186
186
|
*/
|
|
187
187
|
export declare const screenToClip: (x: number, y: number, drawingBufferWidth: number, drawingBufferHeight: number, pixelRatio: number) => [number, number];
|
|
188
|
+
/**
|
|
189
|
+
* Converts homogeneous clip coordinates back into screen-space pixels.
|
|
190
|
+
* @param {[number, number, number, number]} clipPosition - Homogeneous clip coordinates.
|
|
191
|
+
* @param {number} drawingBufferWidth - WebGL drawing buffer width in device pixels.
|
|
192
|
+
* @param {number} drawingBufferHeight - WebGL drawing buffer height in device pixels.
|
|
193
|
+
* @param {number} pixelRatio - Device pixel ratio relating CSS pixels to device pixels.
|
|
194
|
+
* @returns {{ x: number; y: number } | null} Screen-space coordinates or `null` when invalid.
|
|
195
|
+
*/
|
|
196
|
+
export declare const clipToScreen: (clipPosition: readonly [number, number, number, number], drawingBufferWidth: number, drawingBufferHeight: number, pixelRatio: number) => {
|
|
197
|
+
x: number;
|
|
198
|
+
y: number;
|
|
199
|
+
} | null;
|
|
188
200
|
/**
|
|
189
201
|
* Index order used to decompose a quad into two triangles.
|
|
190
202
|
* @constant
|
|
@@ -387,7 +399,13 @@ export declare const calculateBillboardCornerScreenPositions: (params: Billboard
|
|
|
387
399
|
* @property {number} totalRotateDeg - Rotation applied to the sprite in degrees.
|
|
388
400
|
* @property {SpriteAnchor} [anchor] - Anchor definition normalized between -1 and 1.
|
|
389
401
|
* @property {SpriteImageOffset} [offset] - Offset definition applied in meters/deg.
|
|
390
|
-
* @property {ProjectLngLatFn} project - Projection function mapping longitude/latitude to screen space.
|
|
402
|
+
* @property {ProjectLngLatFn} [project] - Projection function mapping longitude/latitude to screen space.
|
|
403
|
+
* @property {ProjectToClipSpaceFn} [projectToClipSpace] - Projection into clip space when available.
|
|
404
|
+
* @property {number} [drawingBufferWidth] - WebGL drawing buffer width in device pixels.
|
|
405
|
+
* @property {number} [drawingBufferHeight] - WebGL drawing buffer height in device pixels.
|
|
406
|
+
* @property {number} [pixelRatio] - Device pixel ratio relating CSS pixels to device pixels.
|
|
407
|
+
* @property {number} [altitudeMeters] - Altitude used when projecting points into clip space.
|
|
408
|
+
* @property {boolean} [resolveAnchorless] - When true, also computes the anchorless center.
|
|
391
409
|
*/
|
|
392
410
|
export type SurfaceCenterParams = {
|
|
393
411
|
baseLngLat: SpriteLocation;
|
|
@@ -399,7 +417,13 @@ export type SurfaceCenterParams = {
|
|
|
399
417
|
totalRotateDeg: number;
|
|
400
418
|
anchor?: SpriteAnchor;
|
|
401
419
|
offset?: SpriteImageOffset;
|
|
402
|
-
project
|
|
420
|
+
project?: ProjectLngLatFn;
|
|
421
|
+
projectToClipSpace?: ProjectToClipSpaceFn;
|
|
422
|
+
drawingBufferWidth?: number;
|
|
423
|
+
drawingBufferHeight?: number;
|
|
424
|
+
pixelRatio?: number;
|
|
425
|
+
altitudeMeters?: number;
|
|
426
|
+
resolveAnchorless?: boolean;
|
|
403
427
|
};
|
|
404
428
|
/**
|
|
405
429
|
* Output describing the resolved surface center and displacement details.
|
|
@@ -408,6 +432,9 @@ export type SurfaceCenterParams = {
|
|
|
408
432
|
* @property {{ width: number; height: number }} worldDimensions - Sprite dimensions in world meters.
|
|
409
433
|
* @property {{ east: number; north: number }} totalDisplacement - Combined anchor and offset displacement in meters.
|
|
410
434
|
* @property {SpriteLocation} displacedLngLat - Geographic coordinates after applying displacement.
|
|
435
|
+
* @property {{ x: number; y: number } | null | undefined} [anchorlessCenter] - Anchorless screen coordinates when requested.
|
|
436
|
+
* @property {{ east: number; north: number } | undefined} [anchorlessDisplacement] - Offset-only displacement when requested.
|
|
437
|
+
* @property {SpriteLocation | undefined} [anchorlessLngLat] - Anchorless geographic coordinate when requested.
|
|
411
438
|
*/
|
|
412
439
|
export type SurfaceCenterResult = {
|
|
413
440
|
center: {
|
|
@@ -423,6 +450,15 @@ export type SurfaceCenterResult = {
|
|
|
423
450
|
north: number;
|
|
424
451
|
};
|
|
425
452
|
displacedLngLat: SpriteLocation;
|
|
453
|
+
anchorlessCenter?: {
|
|
454
|
+
x: number;
|
|
455
|
+
y: number;
|
|
456
|
+
} | null;
|
|
457
|
+
anchorlessDisplacement?: {
|
|
458
|
+
east: number;
|
|
459
|
+
north: number;
|
|
460
|
+
};
|
|
461
|
+
anchorlessLngLat?: SpriteLocation;
|
|
426
462
|
};
|
|
427
463
|
/**
|
|
428
464
|
* Calculates the projected center of a surface sprite and derives related world-space displacements.
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: maplibre-gl-layers
|
|
3
|
-
* version: 0.
|
|
3
|
+
* version: 0.2.0
|
|
4
4
|
* description: MapLibre's layer extension library enabling the display, movement, and modification of large numbers of dynamic sprite images
|
|
5
5
|
* author: Kouji Matsui (@kekyo@mi.kekyo.net)
|
|
6
6
|
* license: MIT
|
|
7
7
|
* repository.url: https://github.com/kekyo/maplibre-gl-layers.git
|
|
8
|
-
* git.commit.hash:
|
|
8
|
+
* git.commit.hash: 4fe3389ad068a5950d4f01e01ec9d3b34c049fb2
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { EasingFunction, SpriteNumericInterpolationOptions } from './types';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: maplibre-gl-layers
|
|
3
|
-
* version: 0.
|
|
3
|
+
* version: 0.2.0
|
|
4
4
|
* description: MapLibre's layer extension library enabling the display, movement, and modification of large numbers of dynamic sprite images
|
|
5
5
|
* author: Kouji Matsui (@kekyo@mi.kekyo.net)
|
|
6
6
|
* license: MIT
|
|
7
7
|
* repository.url: https://github.com/kekyo/maplibre-gl-layers.git
|
|
8
|
-
* git.commit.hash:
|
|
8
|
+
* git.commit.hash: 4fe3389ad068a5950d4f01e01ec9d3b34c049fb2
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { SpriteNumericInterpolationOptions } from './types';
|
package/dist/types.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: maplibre-gl-layers
|
|
3
|
-
* version: 0.
|
|
3
|
+
* version: 0.2.0
|
|
4
4
|
* description: MapLibre's layer extension library enabling the display, movement, and modification of large numbers of dynamic sprite images
|
|
5
5
|
* author: Kouji Matsui (@kekyo@mi.kekyo.net)
|
|
6
6
|
* license: MIT
|
|
7
7
|
* repository.url: https://github.com/kekyo/maplibre-gl-layers.git
|
|
8
|
-
* git.commit.hash:
|
|
8
|
+
* git.commit.hash: 4fe3389ad068a5950d4f01e01ec9d3b34c049fb2
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { CustomLayerInterface } from 'maplibre-gl';
|
|
@@ -150,7 +150,8 @@ export interface SpriteImageDefinitionInitEntry extends SpriteImageDefinitionIni
|
|
|
150
150
|
}
|
|
151
151
|
/**
|
|
152
152
|
* Parameters required to construct a new sprite.
|
|
153
|
-
*
|
|
153
|
+
*
|
|
154
|
+
* @template TTag Tag type.
|
|
154
155
|
*/
|
|
155
156
|
export interface SpriteInit<TTag> {
|
|
156
157
|
/** Whether the sprite starts enabled. Defaults to true. */
|
|
@@ -162,26 +163,73 @@ export interface SpriteInit<TTag> {
|
|
|
162
163
|
/** Optional tag value; null or omission means no tag. */
|
|
163
164
|
tag?: TTag | null;
|
|
164
165
|
}
|
|
165
|
-
/**
|
|
166
|
+
/**
|
|
167
|
+
* Entry for batch sprite creation, pairing a sprite identifier with its initial settings.
|
|
168
|
+
*
|
|
169
|
+
* @template TTag Tag type.
|
|
170
|
+
*/
|
|
171
|
+
export interface SpriteInitEntry<TTag> extends SpriteInit<TTag> {
|
|
172
|
+
/** Sprite identifier. */
|
|
173
|
+
spriteId: string;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Batch payload accepted by addSprites. Supports both record and array inputs.
|
|
177
|
+
*
|
|
178
|
+
* @template TTag Tag type.
|
|
179
|
+
*/
|
|
180
|
+
export type SpriteInitCollection<TTag> = Record<string, SpriteInit<TTag>> | readonly SpriteInitEntry<TTag>[];
|
|
181
|
+
/**
|
|
182
|
+
* Sprite image state evaluated at runtime.
|
|
183
|
+
*
|
|
184
|
+
* @property {number} subLayer - Sub-layer index the image belongs to.
|
|
185
|
+
* @property {number} order - Ordering slot within the sub-layer.
|
|
186
|
+
* @property {string} imageId - Identifier of the registered image or glyph.
|
|
187
|
+
* @property {SpriteMode} mode - Rendering mode applied to the image.
|
|
188
|
+
* @property {number} opacity - Opacity multiplier applied when rendering.
|
|
189
|
+
* @property {number} scale - Scale factor converting pixels to meters.
|
|
190
|
+
* @property {Readonly<SpriteAnchor>} anchor - Anchor coordinates resolved for the image.
|
|
191
|
+
* @property {Readonly<SpriteImageOffset>} offset - Offset applied relative to the anchor point.
|
|
192
|
+
* @property {number} rotateDeg - Additional rotation in degrees.
|
|
193
|
+
* @property {boolean} autoRotation - Indicates whether auto-rotation is active.
|
|
194
|
+
* @property {number} autoRotationMinDistanceMeters - Minimum travel distance before auto-rotation updates.
|
|
195
|
+
* @property {number} resolvedBaseRotateDeg - Internal base rotation resolved for the current frame.
|
|
196
|
+
* @property {number} displayedRotateDeg - Rotation value actually used for rendering.
|
|
197
|
+
* @property {Readonly<SpriteImageOriginLocation> | undefined} originLocation - Optional reference to another image used for anchoring.
|
|
198
|
+
*/
|
|
166
199
|
export interface SpriteImageState {
|
|
200
|
+
/** Sub-layer index the image belongs to. */
|
|
167
201
|
readonly subLayer: number;
|
|
202
|
+
/** Ordering slot within the sub-layer. */
|
|
168
203
|
readonly order: number;
|
|
204
|
+
/** Identifier of the registered image or glyph. */
|
|
169
205
|
readonly imageId: string;
|
|
206
|
+
/** Rendering mode applied to the image. */
|
|
170
207
|
readonly mode: SpriteMode;
|
|
208
|
+
/** Opacity multiplier applied when rendering. */
|
|
171
209
|
readonly opacity: number;
|
|
210
|
+
/** Scale factor converting pixels to meters. */
|
|
172
211
|
readonly scale: number;
|
|
212
|
+
/** Anchor coordinates resolved for the image. */
|
|
173
213
|
readonly anchor: Readonly<SpriteAnchor>;
|
|
214
|
+
/** Offset applied relative to the anchor point. */
|
|
174
215
|
readonly offset: Readonly<SpriteImageOffset>;
|
|
216
|
+
/** Additional rotation in degrees. */
|
|
175
217
|
readonly rotateDeg: number;
|
|
218
|
+
/** Indicates whether auto-rotation is active. */
|
|
176
219
|
readonly autoRotation: boolean;
|
|
220
|
+
/** Minimum travel distance before auto-rotation updates. */
|
|
177
221
|
readonly autoRotationMinDistanceMeters: number;
|
|
222
|
+
/** Internal base rotation resolved for the current frame. */
|
|
178
223
|
readonly resolvedBaseRotateDeg: number;
|
|
224
|
+
/** Rotation value actually used for rendering. */
|
|
179
225
|
readonly displayedRotateDeg: number;
|
|
226
|
+
/** Optional reference to another image used for anchoring. */
|
|
180
227
|
readonly originLocation: Readonly<SpriteImageOriginLocation> | undefined;
|
|
181
228
|
}
|
|
182
229
|
/**
|
|
183
230
|
* Current runtime state of a sprite.
|
|
184
|
-
*
|
|
231
|
+
*
|
|
232
|
+
* @template TTag Tag type.
|
|
185
233
|
*/
|
|
186
234
|
export interface SpriteCurrentState<TTag> {
|
|
187
235
|
/** Sprite identifier. */
|
|
@@ -234,66 +282,169 @@ export interface SpriteImageRotationInterpolationOptions {
|
|
|
234
282
|
/** Interpolation settings for offset.offsetDeg; null disables interpolation. */
|
|
235
283
|
offsetDeg?: SpriteNumericInterpolationOptions | null;
|
|
236
284
|
}
|
|
237
|
-
/**
|
|
285
|
+
/**
|
|
286
|
+
* Base structure for sprite updates.
|
|
287
|
+
*
|
|
288
|
+
* @template TTag Tag type stored on the sprite.
|
|
289
|
+
* @property {boolean | undefined} isEnabled - Optional toggle to enable or disable the sprite.
|
|
290
|
+
* @property {SpriteLocation | undefined} location - Optional target location for the sprite.
|
|
291
|
+
* @property {SpriteInterpolationOptions | null | undefined} interpolation - Optional interpolation settings; `null` disables interpolation.
|
|
292
|
+
* @property {TTag | null | undefined} tag - Optional tag value to replace the current one; `null` clears the tag.
|
|
293
|
+
*/
|
|
238
294
|
export interface SpriteUpdateEntryBase<TTag> {
|
|
295
|
+
/** Optional toggle to enable or disable the sprite. */
|
|
239
296
|
isEnabled?: boolean;
|
|
297
|
+
/** Optional target location for the sprite. */
|
|
240
298
|
location?: SpriteLocation;
|
|
299
|
+
/** Optional interpolation settings; `null` disables interpolation. */
|
|
241
300
|
interpolation?: SpriteInterpolationOptions | null;
|
|
301
|
+
/** Optional tag value to replace the current one; `null` clears the tag. */
|
|
242
302
|
tag?: TTag | null;
|
|
243
303
|
}
|
|
244
|
-
/**
|
|
304
|
+
/**
|
|
305
|
+
* Update entry describing a sprite image modification.
|
|
306
|
+
*
|
|
307
|
+
* @property {number} subLayer - Target sub-layer that contains the image.
|
|
308
|
+
* @property {number} order - Order slot within the sub-layer.
|
|
309
|
+
* @property {SpriteImageDefinitionUpdate | null} image - Update payload, or `null` to remove the image.
|
|
310
|
+
*/
|
|
245
311
|
export interface SpriteImageDefinitionUpdateEntry {
|
|
312
|
+
/** Target sub-layer that contains the image. */
|
|
246
313
|
subLayer: number;
|
|
314
|
+
/** Order slot within the sub-layer. */
|
|
247
315
|
order: number;
|
|
316
|
+
/** Update payload, or `null` to remove the image. */
|
|
248
317
|
image: SpriteImageDefinitionUpdate | null;
|
|
249
318
|
}
|
|
250
|
-
/**
|
|
319
|
+
/**
|
|
320
|
+
* Sprite update entry with optional image list.
|
|
321
|
+
*
|
|
322
|
+
* @template TTag Tag type stored on the sprite.
|
|
323
|
+
* @property {SpriteImageDefinitionUpdateEntry[] | undefined} images - Optional set of image updates.
|
|
324
|
+
*/
|
|
251
325
|
export interface SpriteUpdateEntry<TTag> extends SpriteUpdateEntryBase<TTag> {
|
|
326
|
+
/** Optional set of image updates. */
|
|
252
327
|
images?: SpriteImageDefinitionUpdateEntry[];
|
|
253
328
|
}
|
|
254
|
-
/**
|
|
329
|
+
/**
|
|
330
|
+
* Entry consumed by updateBulk to target a specific sprite.
|
|
331
|
+
*
|
|
332
|
+
* @template T Tag type stored on the sprite.
|
|
333
|
+
* @property {string} spriteId - Identifier of the sprite to update.
|
|
334
|
+
*/
|
|
255
335
|
export interface SpriteUpdateBulkEntry<T> extends SpriteUpdateEntry<T> {
|
|
336
|
+
/** Identifier of the sprite to update. */
|
|
256
337
|
spriteId: string;
|
|
257
338
|
}
|
|
258
|
-
/**
|
|
339
|
+
/**
|
|
340
|
+
* Callback-based helper for mutating sprite state.
|
|
341
|
+
*
|
|
342
|
+
* @template TTag Tag type stored on the sprite.
|
|
343
|
+
* @property {() => ReadonlyMap<number, ReadonlySet<number>>} getImageIndexMap - Retrieves the current image layout.
|
|
344
|
+
* @property {(subLayer: number, order: number, imageInit: SpriteImageDefinitionInit) => boolean} addImage - Adds an image definition.
|
|
345
|
+
* @property {(subLayer: number, order: number, imageUpdate: SpriteImageDefinitionUpdate) => boolean} updateImage - Applies image updates.
|
|
346
|
+
* @property {(subLayer: number, order: number) => boolean} removeImage - Removes an image slot.
|
|
347
|
+
*/
|
|
259
348
|
export interface SpriteUpdaterEntry<TTag> extends SpriteUpdateEntryBase<TTag> {
|
|
349
|
+
/** Retrieves the current image layout. */
|
|
260
350
|
readonly getImageIndexMap: () => ReadonlyMap<number, ReadonlySet<number>>;
|
|
351
|
+
/** Adds an image definition. */
|
|
261
352
|
readonly addImage: (subLayer: number, order: number, imageInit: SpriteImageDefinitionInit) => boolean;
|
|
353
|
+
/** Applies image updates. */
|
|
262
354
|
readonly updateImage: (subLayer: number, order: number, imageUpdate: SpriteImageDefinitionUpdate) => boolean;
|
|
355
|
+
/** Removes an image slot. */
|
|
263
356
|
readonly removeImage: (subLayer: number, order: number) => boolean;
|
|
264
357
|
}
|
|
265
|
-
/**
|
|
358
|
+
/**
|
|
359
|
+
* Represents a point in screen space.
|
|
360
|
+
*
|
|
361
|
+
* @property {number} x - Horizontal screen coordinate in pixels.
|
|
362
|
+
* @property {number} y - Vertical screen coordinate in pixels.
|
|
363
|
+
*/
|
|
266
364
|
export interface SpriteScreenPoint {
|
|
365
|
+
/** Horizontal screen coordinate in pixels. */
|
|
267
366
|
readonly x: number;
|
|
367
|
+
/** Vertical screen coordinate in pixels. */
|
|
268
368
|
readonly y: number;
|
|
269
369
|
}
|
|
270
|
-
/**
|
|
370
|
+
/**
|
|
371
|
+
* Event dispatched when a sprite is clicked or tapped.
|
|
372
|
+
*
|
|
373
|
+
* @template T Tag type stored on sprites.
|
|
374
|
+
* @property {'spriteclick'} type - Discriminated event type.
|
|
375
|
+
* @property {SpriteCurrentState<T>} sprite - Snapshot of the sprite that was hit.
|
|
376
|
+
* @property {SpriteImageState} image - Sprite image that received the interaction.
|
|
377
|
+
* @property {SpriteScreenPoint} screenPoint - Screen position of the interaction.
|
|
378
|
+
* @property {MouseEvent | PointerEvent | TouchEvent} originalEvent - Original DOM event.
|
|
379
|
+
*/
|
|
271
380
|
export interface SpriteLayerClickEvent<T> {
|
|
381
|
+
/** Discriminated event type. */
|
|
272
382
|
readonly type: 'spriteclick';
|
|
383
|
+
/** Snapshot of the sprite that was hit. */
|
|
273
384
|
readonly sprite: SpriteCurrentState<T>;
|
|
385
|
+
/** Sprite image that received the interaction. */
|
|
274
386
|
readonly image: SpriteImageState;
|
|
387
|
+
/** Screen position of the interaction. */
|
|
275
388
|
readonly screenPoint: SpriteScreenPoint;
|
|
389
|
+
/** Original DOM event. */
|
|
276
390
|
readonly originalEvent: MouseEvent | PointerEvent | TouchEvent;
|
|
277
391
|
}
|
|
278
|
-
/**
|
|
392
|
+
/**
|
|
393
|
+
* Map of events emitted by SpriteLayer.
|
|
394
|
+
*
|
|
395
|
+
* @template T Tag type stored on sprites.
|
|
396
|
+
* @property {SpriteLayerClickEvent<T>} spriteclick - Event fired when a sprite image is clicked.
|
|
397
|
+
*/
|
|
279
398
|
export interface SpriteLayerEventMap<T> {
|
|
399
|
+
/** Event fired when a sprite image is clicked. */
|
|
280
400
|
readonly spriteclick: SpriteLayerClickEvent<T>;
|
|
281
401
|
}
|
|
282
|
-
/**
|
|
402
|
+
/**
|
|
403
|
+
* Event listener callback.
|
|
404
|
+
*
|
|
405
|
+
* @template T Tag type stored on sprites.
|
|
406
|
+
* @template K Event key from {@link SpriteLayerEventMap}.
|
|
407
|
+
* @param {SpriteLayerEventMap<T>[K]} event - Event payload dispatched by SpriteLayer.
|
|
408
|
+
* @returns {void}
|
|
409
|
+
*/
|
|
283
410
|
export type SpriteLayerEventListener<T, K extends keyof SpriteLayerEventMap<T>> = (event: SpriteLayerEventMap<T>[K]) => void;
|
|
284
|
-
/**
|
|
411
|
+
/**
|
|
412
|
+
* Options controlling zoom-to-pixel scaling.
|
|
413
|
+
*
|
|
414
|
+
* @property {number | undefined} metersPerPixel - Overrides the baseline meters-per-pixel ratio.
|
|
415
|
+
* @property {number | undefined} zoomMin - Minimum zoom level before scaling adjustments apply.
|
|
416
|
+
* @property {number | undefined} zoomMax - Maximum zoom level before scaling adjustments apply.
|
|
417
|
+
* @property {number | undefined} scaleMin - Lower limit for scale clamping.
|
|
418
|
+
* @property {number | undefined} scaleMax - Upper limit for scale clamping.
|
|
419
|
+
* @property {number | undefined} spriteMinPixel - Minimum on-screen pixel size for sprites.
|
|
420
|
+
* @property {number | undefined} spriteMaxPixel - Maximum on-screen pixel size for sprites.
|
|
421
|
+
*/
|
|
285
422
|
export interface SpriteScalingOptions {
|
|
423
|
+
/** Overrides the baseline meters-per-pixel ratio. */
|
|
286
424
|
metersPerPixel?: number;
|
|
425
|
+
/** Minimum zoom level before scaling adjustments apply. */
|
|
287
426
|
zoomMin?: number;
|
|
427
|
+
/** Maximum zoom level before scaling adjustments apply. */
|
|
288
428
|
zoomMax?: number;
|
|
429
|
+
/** Lower limit for scale clamping. */
|
|
289
430
|
scaleMin?: number;
|
|
431
|
+
/** Upper limit for scale clamping. */
|
|
290
432
|
scaleMax?: number;
|
|
433
|
+
/** Minimum on-screen pixel size for sprites. */
|
|
291
434
|
spriteMinPixel?: number;
|
|
435
|
+
/** Maximum on-screen pixel size for sprites. */
|
|
292
436
|
spriteMaxPixel?: number;
|
|
293
437
|
}
|
|
294
|
-
/**
|
|
438
|
+
/**
|
|
439
|
+
* Options accepted when creating a SpriteLayer.
|
|
440
|
+
*
|
|
441
|
+
* @property {string | undefined} id - Optional layer identifier supplied to MapLibre.
|
|
442
|
+
* @property {SpriteScalingOptions | undefined} spriteScaling - Optional scaling controls.
|
|
443
|
+
*/
|
|
295
444
|
export interface SpriteLayerOptions {
|
|
445
|
+
/** Optional layer identifier supplied to MapLibre. */
|
|
296
446
|
id?: string;
|
|
447
|
+
/** Optional scaling controls. */
|
|
297
448
|
spriteScaling?: SpriteScalingOptions;
|
|
298
449
|
}
|
|
299
450
|
/** Horizontal alignment options for text glyphs. */
|
|
@@ -313,39 +464,209 @@ export type SpriteTextGlyphDimensions = {
|
|
|
313
464
|
readonly maxWidthPixel: number;
|
|
314
465
|
readonly lineHeightPixel?: never;
|
|
315
466
|
};
|
|
467
|
+
/**
|
|
468
|
+
* Text glyph appearance options.
|
|
469
|
+
*
|
|
470
|
+
* @property {string | undefined} fontFamily - Font family name.
|
|
471
|
+
* @property {number | undefined} fontSizePixel - Font size in pixels.
|
|
472
|
+
* @property {string | undefined} fontWeight - CSS font-weight value.
|
|
473
|
+
* @property {'normal' | 'italic' | undefined} fontStyle - CSS font-style value.
|
|
474
|
+
* @property {string | undefined} color - Text fill color.
|
|
475
|
+
* @property {number | undefined} letterSpacingPixel - Letter spacing in pixels.
|
|
476
|
+
* @property {string | undefined} backgroundColor - Background color applied behind the text.
|
|
477
|
+
* @property {SpriteTextGlyphPaddingPixel | undefined} paddingPixel - Padding around the glyph.
|
|
478
|
+
* @property {string | undefined} borderColor - Outline color.
|
|
479
|
+
* @property {number | undefined} borderWidthPixel - Outline width in pixels.
|
|
480
|
+
* @property {number | undefined} borderRadiusPixel - Border radius in pixels.
|
|
481
|
+
* @property {SpriteTextGlyphHorizontalAlign | undefined} textAlign - Horizontal alignment of multiline text.
|
|
482
|
+
* @property {number | undefined} renderPixelRatio - Pixel ratio used when rendering the glyph.
|
|
483
|
+
*/
|
|
316
484
|
export interface SpriteTextGlyphOptions {
|
|
485
|
+
/** Font family name. */
|
|
317
486
|
fontFamily?: string;
|
|
487
|
+
/** Font size in pixels. */
|
|
318
488
|
fontSizePixel?: number;
|
|
489
|
+
/** CSS font-weight value. */
|
|
319
490
|
fontWeight?: string;
|
|
491
|
+
/** CSS font-style value. */
|
|
320
492
|
fontStyle?: 'normal' | 'italic';
|
|
493
|
+
/** Text fill color. */
|
|
321
494
|
color?: string;
|
|
495
|
+
/** Letter spacing in pixels. */
|
|
322
496
|
letterSpacingPixel?: number;
|
|
497
|
+
/** Background color applied behind the text. */
|
|
323
498
|
backgroundColor?: string;
|
|
499
|
+
/** Padding around the glyph. */
|
|
324
500
|
paddingPixel?: SpriteTextGlyphPaddingPixel;
|
|
501
|
+
/** Outline color. */
|
|
325
502
|
borderColor?: string;
|
|
503
|
+
/** Outline width in pixels. */
|
|
326
504
|
borderWidthPixel?: number;
|
|
505
|
+
/** Border radius in pixels. */
|
|
327
506
|
borderRadiusPixel?: number;
|
|
507
|
+
/** Horizontal alignment of multiline text. */
|
|
328
508
|
textAlign?: SpriteTextGlyphHorizontalAlign;
|
|
509
|
+
/** Pixel ratio used when rendering the glyph. */
|
|
329
510
|
renderPixelRatio?: number;
|
|
330
511
|
}
|
|
331
512
|
/**
|
|
332
513
|
* MapLibre layer interface for SpriteLayer.
|
|
333
514
|
* Renders large numbers of sprites and supports high-frequency updates.
|
|
334
|
-
*
|
|
515
|
+
*
|
|
516
|
+
* @template TTag Sprite tag type.
|
|
335
517
|
*/
|
|
336
|
-
export interface SpriteLayerInterface<
|
|
518
|
+
export interface SpriteLayerInterface<TTag = any> extends CustomLayerInterface {
|
|
519
|
+
/**
|
|
520
|
+
* Registers an image or glyph so it can be referenced by sprite images.
|
|
521
|
+
*
|
|
522
|
+
* @param {string} imageId - Unique image identifier.
|
|
523
|
+
* @param {string | ImageBitmap} image - Image source (URL or ImageBitmap) to upload.
|
|
524
|
+
* @returns {Promise<boolean>} Resolves to `true` when the image was registered; `false` if the ID already existed.
|
|
525
|
+
*/
|
|
337
526
|
readonly registerImage: (imageId: string, image: string | ImageBitmap) => Promise<boolean>;
|
|
527
|
+
/**
|
|
528
|
+
* Registers a text glyph texture for later use.
|
|
529
|
+
*
|
|
530
|
+
* @param {string} textGlyphId - Unique identifier for the text glyph.
|
|
531
|
+
* @param {string} text - Text content to render.
|
|
532
|
+
* @param {SpriteTextGlyphDimensions} dimensions - Glyph sizing options.
|
|
533
|
+
* @param {SpriteTextGlyphOptions | undefined} options - Optional styling information.
|
|
534
|
+
* @returns {Promise<boolean>} Resolves to `true` when the glyph was registered; `false` if the ID already existed.
|
|
535
|
+
*/
|
|
338
536
|
readonly registerTextGlyph: (textGlyphId: string, text: string, dimensions: SpriteTextGlyphDimensions, options?: SpriteTextGlyphOptions) => Promise<boolean>;
|
|
537
|
+
/**
|
|
538
|
+
* Removes a previously registered image or glyph.
|
|
539
|
+
*
|
|
540
|
+
* @param {string} imageId - Identifier of the image to remove.
|
|
541
|
+
* @returns {boolean} `true` when the image existed and was removed.
|
|
542
|
+
*/
|
|
339
543
|
readonly unregisterImage: (imageId: string) => boolean;
|
|
340
|
-
|
|
544
|
+
/**
|
|
545
|
+
* Removes every registered image and glyph, releasing associated GPU resources.
|
|
546
|
+
*
|
|
547
|
+
* @returns {void}
|
|
548
|
+
*/
|
|
549
|
+
readonly unregisterAllImages: () => void;
|
|
550
|
+
/**
|
|
551
|
+
* Returns all currently registered image IDs.
|
|
552
|
+
*
|
|
553
|
+
* @returns {string[]} Array of registered image identifiers.
|
|
554
|
+
*/
|
|
555
|
+
readonly getAllImageIds: () => string[];
|
|
556
|
+
/**
|
|
557
|
+
* Adds a sprite to the layer.
|
|
558
|
+
*
|
|
559
|
+
* @param {string} spriteId - Unique sprite identifier.
|
|
560
|
+
* @param {SpriteInit<TTag>} init - Initial sprite configuration.
|
|
561
|
+
* @returns {boolean} `true` when the sprite was inserted; `false` if the ID already existed.
|
|
562
|
+
*/
|
|
563
|
+
readonly addSprite: (spriteId: string, init: SpriteInit<TTag>) => boolean;
|
|
564
|
+
/**
|
|
565
|
+
* Adds multiple sprites in one call.
|
|
566
|
+
*
|
|
567
|
+
* @param {SpriteInitCollection<TTag>} sprites - Sprite definitions keyed by ID or supplied as entries.
|
|
568
|
+
* @returns {number} Number of sprites that were inserted.
|
|
569
|
+
*/
|
|
570
|
+
readonly addSprites: (sprites: SpriteInitCollection<TTag>) => number;
|
|
571
|
+
/**
|
|
572
|
+
* Removes a sprite.
|
|
573
|
+
*
|
|
574
|
+
* @param {string} spriteId - Identifier of the sprite to remove.
|
|
575
|
+
* @returns {void}
|
|
576
|
+
*/
|
|
341
577
|
readonly removeSprite: (spriteId: string) => void;
|
|
342
|
-
|
|
578
|
+
/**
|
|
579
|
+
* Removes multiple sprites.
|
|
580
|
+
*
|
|
581
|
+
* @param {readonly string[]} spriteIds - Identifiers of the sprites to remove.
|
|
582
|
+
* @returns {number} Number of sprites that were removed.
|
|
583
|
+
*/
|
|
584
|
+
readonly removeSprites: (spriteIds: readonly string[]) => number;
|
|
585
|
+
/**
|
|
586
|
+
* Removes all sprites.
|
|
587
|
+
*
|
|
588
|
+
* @returns {number} Number of sprites that were removed.
|
|
589
|
+
*/
|
|
590
|
+
readonly removeAllSprites: () => number;
|
|
591
|
+
/**
|
|
592
|
+
* Retrieves the current state for a sprite.
|
|
593
|
+
*
|
|
594
|
+
* @param {string} spriteId - Identifier of the sprite.
|
|
595
|
+
* @returns {SpriteCurrentState<TTag> | undefined} Current state or `undefined` when not found.
|
|
596
|
+
*/
|
|
597
|
+
readonly getSpriteState: (spriteId: string) => SpriteCurrentState<TTag> | undefined;
|
|
598
|
+
/**
|
|
599
|
+
* Attaches an image definition to a sprite.
|
|
600
|
+
*
|
|
601
|
+
* @param {string} spriteId - Target sprite identifier.
|
|
602
|
+
* @param {number} subLayer - Sub-layer index.
|
|
603
|
+
* @param {number} order - Order slot within the sub-layer.
|
|
604
|
+
* @param {SpriteImageDefinitionInit} imageInit - Image definition to insert.
|
|
605
|
+
* @returns {boolean} `true` when the image slot was empty and the definition applied.
|
|
606
|
+
*/
|
|
343
607
|
readonly addSpriteImage: (spriteId: string, subLayer: number, order: number, imageInit: SpriteImageDefinitionInit) => boolean;
|
|
608
|
+
/**
|
|
609
|
+
* Updates an image assigned to a sprite.
|
|
610
|
+
*
|
|
611
|
+
* @param {string} spriteId - Target sprite identifier.
|
|
612
|
+
* @param {number} subLayer - Sub-layer index containing the image.
|
|
613
|
+
* @param {number} order - Order slot within the sub-layer.
|
|
614
|
+
* @param {SpriteImageDefinitionUpdate} imageUpdate - Update payload.
|
|
615
|
+
* @returns {boolean} `true` when the image existed and was updated.
|
|
616
|
+
*/
|
|
344
617
|
readonly updateSpriteImage: (spriteId: string, subLayer: number, order: number, imageUpdate: SpriteImageDefinitionUpdate) => boolean;
|
|
618
|
+
/**
|
|
619
|
+
* Removes an image from a sprite.
|
|
620
|
+
*
|
|
621
|
+
* @param {string} spriteId - Target sprite identifier.
|
|
622
|
+
* @param {number} subLayer - Sub-layer index containing the image.
|
|
623
|
+
* @param {number} order - Order slot within the sub-layer.
|
|
624
|
+
* @returns {boolean} `true` when the image existed and was removed.
|
|
625
|
+
*/
|
|
345
626
|
readonly removeSpriteImage: (spriteId: string, subLayer: number, order: number) => boolean;
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
627
|
+
/**
|
|
628
|
+
* Removes all images attached to the specified sprite.
|
|
629
|
+
*
|
|
630
|
+
* @param {string} spriteId - Identifier of the sprite whose images should be removed.
|
|
631
|
+
* @returns {number} Number of images that were removed.
|
|
632
|
+
*/
|
|
633
|
+
readonly removeAllSpriteImages: (spriteId: string) => number;
|
|
634
|
+
/**
|
|
635
|
+
* Updates a sprite with the provided payload.
|
|
636
|
+
*
|
|
637
|
+
* @param {string} spriteId - Target sprite identifier.
|
|
638
|
+
* @param {SpriteUpdateEntry<TTag>} update - Update payload describing property changes.
|
|
639
|
+
* @returns {boolean} `true` when the sprite was found and updated.
|
|
640
|
+
*/
|
|
641
|
+
readonly updateSprite: (spriteId: string, update: SpriteUpdateEntry<TTag>) => boolean;
|
|
642
|
+
/**
|
|
643
|
+
* Applies a batch of sprite updates.
|
|
644
|
+
*
|
|
645
|
+
* @param {SpriteUpdateBulkEntry<TTag>[]} updateBulkList - List of sprite updates.
|
|
646
|
+
* @returns {number} Number of sprites that were updated.
|
|
647
|
+
*/
|
|
648
|
+
readonly updateBulk: (updateBulkList: SpriteUpdateBulkEntry<TTag>[]) => number;
|
|
649
|
+
/**
|
|
650
|
+
* Iterates over each sprite and allows modifications through a callback.
|
|
651
|
+
*
|
|
652
|
+
* @param {(sprite: SpriteCurrentState<TTag>, update: SpriteUpdaterEntry<TTag>) => boolean} updater - Callback invoked for each sprite. Return `false` to stop iteration early.
|
|
653
|
+
* @returns {number} Number of sprites that were updated.
|
|
654
|
+
*/
|
|
655
|
+
readonly updateForEach: (updater: (sprite: SpriteCurrentState<TTag>, update: SpriteUpdaterEntry<TTag>) => boolean) => number;
|
|
656
|
+
/**
|
|
657
|
+
* Adds an event listener.
|
|
658
|
+
*
|
|
659
|
+
* @param {K} type - Event name.
|
|
660
|
+
* @param {SpriteLayerEventListener<TTag, K>} listener - Listener callback.
|
|
661
|
+
* @returns {void}
|
|
662
|
+
*/
|
|
663
|
+
readonly on: <K extends keyof SpriteLayerEventMap<TTag>>(type: K, listener: SpriteLayerEventListener<TTag, K>) => void;
|
|
664
|
+
/**
|
|
665
|
+
* Removes a previously registered event listener.
|
|
666
|
+
*
|
|
667
|
+
* @param {K} type - Event name.
|
|
668
|
+
* @param {SpriteLayerEventListener<TTag, K>} listener - Listener callback to remove.
|
|
669
|
+
* @returns {void}
|
|
670
|
+
*/
|
|
671
|
+
readonly off: <K extends keyof SpriteLayerEventMap<TTag>>(type: K, listener: SpriteLayerEventListener<TTag, K>) => void;
|
|
351
672
|
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: maplibre-gl-layers
|
|
3
|
-
* version: 0.
|
|
3
|
+
* version: 0.2.0
|
|
4
4
|
* description: MapLibre's layer extension library enabling the display, movement, and modification of large numbers of dynamic sprite images
|
|
5
5
|
* author: Kouji Matsui (@kekyo@mi.kekyo.net)
|
|
6
6
|
* license: MIT
|
|
7
7
|
* repository.url: https://github.com/kekyo/maplibre-gl-layers.git
|
|
8
|
-
* git.commit.hash:
|
|
8
|
+
* git.commit.hash: 4fe3389ad068a5950d4f01e01ec9d3b34c049fb2
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
/**
|