maplibre-gl-layers 0.6.0 → 0.11.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/dist/types.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: maplibre-gl-layers
3
- * version: 0.6.0
3
+ * version: 0.11.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: 481f544de02fd3e71a2ba6c28bbb7eeb98b49eff
8
+ * git.commit.hash: 371efb126f281333d59ec75cfe788d45f3b1482e
9
9
  */
10
10
 
11
11
  import { CustomLayerInterface } from 'maplibre-gl';
@@ -71,6 +71,28 @@ export interface SpriteImageOriginLocation {
71
71
  */
72
72
  useResolvedAnchor?: boolean;
73
73
  }
74
+ /** Defines movement interpolation modes. */
75
+ export type SpriteInterpolationMode = 'feedback' | 'feedforward';
76
+ /** Easing function signature used to map interpolation progress. */
77
+ export type EasingFunction = (progress: number) => number;
78
+ /** Options for interpolating values. */
79
+ export interface SpriteInterpolationOptions {
80
+ /** Interpolation mode; defaults to feedback. */
81
+ mode?: SpriteInterpolationMode;
82
+ /** Duration in milliseconds. */
83
+ durationMs: number;
84
+ /** Easing function mapping interpolation progress. Defaults to linear. */
85
+ easing?: EasingFunction;
86
+ }
87
+ /** Interpolation configuration for rotateDeg and offsetDeg. */
88
+ export interface SpriteImageInterpolationOptions {
89
+ /** Interpolation settings for rotateDeg; null disables interpolation. */
90
+ rotateDeg?: SpriteInterpolationOptions | null;
91
+ /** Interpolation settings for offset.offsetDeg; null disables interpolation. */
92
+ offsetDeg?: SpriteInterpolationOptions | null;
93
+ /** Interpolation settings for offset.offsetMeters; null disables interpolation. */
94
+ offsetMeters?: SpriteInterpolationOptions | null;
95
+ }
74
96
  /**
75
97
  * Initial attributes that define a sprite image.
76
98
  */
@@ -108,9 +130,9 @@ export interface SpriteImageDefinitionInit {
108
130
  */
109
131
  autoRotationMinDistanceMeters?: number;
110
132
  /**
111
- * Optional interpolation settings for rotateDeg and offsetDeg.
133
+ * Optional interpolation settings.
112
134
  */
113
- rotationInterpolation?: SpriteImageRotationInterpolationOptions;
135
+ interpolation?: SpriteImageInterpolationOptions;
114
136
  }
115
137
  /**
116
138
  * Update payload for a sprite image. Properties left undefined are ignored.
@@ -134,8 +156,8 @@ export interface SpriteImageDefinitionUpdate {
134
156
  autoRotation?: boolean;
135
157
  /** Minimum distance in meters before auto-rotation updates. */
136
158
  autoRotationMinDistanceMeters?: number;
137
- /** Optional interpolation settings applied to rotateDeg and offsetDeg. */
138
- rotationInterpolation?: SpriteImageRotationInterpolationOptions;
159
+ /** Optional interpolation settings. */
160
+ interpolation?: SpriteImageInterpolationOptions;
139
161
  }
140
162
  /**
141
163
  * Helper for bulk initializing sprite images.
@@ -255,40 +277,13 @@ export interface SpriteCurrentState<TTag> {
255
277
  /** Optional tag value; null indicates no tag. */
256
278
  readonly tag: TTag | null;
257
279
  }
258
- /** Defines movement interpolation modes. */
259
- export type SpriteInterpolationMode = 'feedback' | 'feedforward';
260
- /** Easing function signature used to map interpolation progress. */
261
- export type EasingFunction = (progress: number) => number;
262
- /** Options controlling position interpolation. */
263
- export interface SpriteInterpolationOptions {
264
- /** Interpolation mode; defaults to feedback. */
265
- mode?: SpriteInterpolationMode;
266
- /** Duration in milliseconds. */
267
- durationMs: number;
268
- /** Easing function mapping interpolation progress. Defaults to linear. */
269
- easing?: EasingFunction;
270
- }
271
- /** Options for interpolating numeric values such as angles. */
272
- export interface SpriteNumericInterpolationOptions {
273
- /** Duration in milliseconds. */
274
- durationMs: number;
275
- /** Easing function mapping interpolation progress. Defaults to linear. */
276
- easing?: EasingFunction;
277
- }
278
- /** Interpolation configuration for rotateDeg and offsetDeg. */
279
- export interface SpriteImageRotationInterpolationOptions {
280
- /** Interpolation settings for rotateDeg; null disables interpolation. */
281
- rotateDeg?: SpriteNumericInterpolationOptions | null;
282
- /** Interpolation settings for offset.offsetDeg; null disables interpolation. */
283
- offsetDeg?: SpriteNumericInterpolationOptions | null;
284
- }
285
280
  /**
286
281
  * Base structure for sprite updates.
287
282
  *
288
283
  * @template TTag Tag type stored on the sprite.
289
284
  * @property {boolean | undefined} isEnabled - Optional toggle to enable or disable the sprite.
290
285
  * @property {SpriteLocation | undefined} location - Optional target location for the sprite.
291
- * @property {SpriteInterpolationOptions | null | undefined} interpolation - Optional interpolation settings; `null` disables interpolation.
286
+ * @property {SpriteLocationInterpolationOptions | null | undefined} interpolation - Optional location interpolation settings; `null` disables interpolation.
292
287
  * @property {TTag | null | undefined} tag - Optional tag value to replace the current one; `null` clears the tag.
293
288
  */
294
289
  export interface SpriteUpdateEntryBase<TTag> {
@@ -326,11 +321,6 @@ export interface SpriteUpdateEntry<TTag> extends SpriteUpdateEntryBase<TTag> {
326
321
  /** Optional set of image updates. */
327
322
  images?: SpriteImageDefinitionUpdateEntry[];
328
323
  }
329
- /** @deprecated Scheduled for removal in a future release. Use {@link SpriteLayerInterface.mutateSprites} instead. */
330
- export interface SpriteUpdateBulkEntry<T> extends SpriteUpdateEntry<T> {
331
- /** @deprecated Scheduled for removal in a future release. Use {@link SpriteLayerInterface.mutateSprites} instead. */
332
- spriteId: string;
333
- }
334
324
  /**
335
325
  * Callback-based helper for mutating sprite state.
336
326
  *
@@ -374,7 +364,7 @@ export interface SpriteMutateCallbacks<TTag, TSourceItem extends SpriteMutateSou
374
364
  * (or `null`) to skip creation.
375
365
  *
376
366
  * @param sourceItem Source item that produced the sprite ID.
377
- * @returns Sprite initialiser to insert, or `undefined`/`null` to skip.
367
+ * @returns Sprite initializer to insert, or `undefined`/`null` to skip.
378
368
  */
379
369
  add: (sourceItem: TSourceItem) => SpriteInit<TTag> | null | undefined;
380
370
  /**
@@ -413,24 +403,49 @@ export interface SpriteScreenPoint {
413
403
  export interface SpriteLayerClickEvent<T> {
414
404
  /** Discriminated event type. */
415
405
  readonly type: 'spriteclick';
416
- /** Snapshot of the sprite that was hit. */
417
- readonly sprite: SpriteCurrentState<T>;
418
- /** Sprite image that received the interaction. */
419
- readonly image: SpriteImageState;
406
+ /** Snapshot of the sprite that was hit, or `undefined` when it no longer exists. */
407
+ readonly sprite: SpriteCurrentState<T> | undefined;
408
+ /** Sprite image that received the interaction, or `undefined` when missing. */
409
+ readonly image: SpriteImageState | undefined;
420
410
  /** Screen position of the interaction. */
421
411
  readonly screenPoint: SpriteScreenPoint;
422
412
  /** Original DOM event. */
423
413
  readonly originalEvent: MouseEvent | PointerEvent | TouchEvent;
424
414
  }
415
+ /**
416
+ * Event dispatched when a sprite is hovered by a pointing device.
417
+ *
418
+ * @template T Tag type stored on sprites.
419
+ * @property {'spritehover'} type - Discriminated event type.
420
+ * @property {SpriteCurrentState<T>} sprite - Snapshot of the sprite that was hit.
421
+ * @property {SpriteImageState} image - Sprite image that received the interaction.
422
+ * @property {SpriteScreenPoint} screenPoint - Screen position of the interaction.
423
+ * @property {MouseEvent | PointerEvent} originalEvent - Original hover-capable DOM event.
424
+ */
425
+ export interface SpriteLayerHoverEvent<T> {
426
+ /** Discriminated event type. */
427
+ readonly type: 'spritehover';
428
+ /** Snapshot of the sprite that was hit, or `undefined` when it no longer exists. */
429
+ readonly sprite: SpriteCurrentState<T> | undefined;
430
+ /** Sprite image that received the interaction, or `undefined` when missing. */
431
+ readonly image: SpriteImageState | undefined;
432
+ /** Screen position of the interaction. */
433
+ readonly screenPoint: SpriteScreenPoint;
434
+ /** Original hover-capable DOM event. */
435
+ readonly originalEvent: MouseEvent | PointerEvent;
436
+ }
425
437
  /**
426
438
  * Map of events emitted by SpriteLayer.
427
439
  *
428
440
  * @template T Tag type stored on sprites.
429
441
  * @property {SpriteLayerClickEvent<T>} spriteclick - Event fired when a sprite image is clicked.
442
+ * @property {SpriteLayerHoverEvent<T>} spritehover - Event fired when a sprite image is hovered.
430
443
  */
431
444
  export interface SpriteLayerEventMap<T> {
432
445
  /** Event fired when a sprite image is clicked. */
433
446
  readonly spriteclick: SpriteLayerClickEvent<T>;
447
+ /** Event fired when a sprite image is hovered. */
448
+ readonly spritehover: SpriteLayerHoverEvent<T>;
434
449
  }
435
450
  /**
436
451
  * Event listener callback.
@@ -471,16 +486,6 @@ export interface SpriteScalingOptions {
471
486
  /** Maximum on-screen pixel size for sprites (0 disables the upper clamp). */
472
487
  spriteMaxPixel?: number;
473
488
  }
474
- /**
475
- * Unlimited (default) values that fill in missing {@link SpriteScalingOptions} fields supplied by callers.
476
- * metersPerPixel is 1.
477
- */
478
- export declare const UNLIMITED_SPRITE_SCALING_OPTIONS: SpriteScalingOptions;
479
- /**
480
- * Standard values that fill in missing {@link SpriteScalingOptions} fields supplied by callers.
481
- * metersPerPixel is 1.
482
- */
483
- export declare const STANDARD_SPRITE_SCALING_OPTIONS: SpriteScalingOptions;
484
489
  /**
485
490
  * Allowed minification filters for sprite textures.
486
491
  */
@@ -503,14 +508,6 @@ export interface SpriteTextureFilteringOptions {
503
508
  generateMipmaps?: boolean;
504
509
  maxAnisotropy?: number;
505
510
  }
506
- /**
507
- * Defaulted text filtering options.
508
- */
509
- export declare const DEFAULT_TEXTURE_FILTERING_OPTIONS: SpriteTextureFilteringOptions;
510
- /**
511
- * Better text filtering options than default options.
512
- */
513
- export declare const BETTER_TEXTURE_FILTERING_OPTIONS: SpriteTextureFilteringOptions;
514
511
  /**
515
512
  * Options accepted when creating a SpriteLayer.
516
513
  *
@@ -525,6 +522,38 @@ export interface SpriteLayerOptions {
525
522
  spriteScaling?: SpriteScalingOptions;
526
523
  /** Optional texture filtering configuration. */
527
524
  textureFiltering?: SpriteTextureFilteringOptions;
525
+ /**
526
+ * When true, renders red outlines around sprite hit-test regions to aid debugging.
527
+ * Defaults to false.
528
+ */
529
+ showDebugBounds?: boolean;
530
+ }
531
+ /**
532
+ * Options used when registering SVG images.
533
+ */
534
+ export interface SpriteImageSvgOptions {
535
+ /** Treat the resource as SVG even when the MIME type is missing or incorrect. */
536
+ readonly assumeSvg?: boolean;
537
+ /** Enables parsing of the SVG markup to detect intrinsic sizing. Defaults to true for SVG images. */
538
+ readonly inspectSize?: boolean;
539
+ /**
540
+ * Uses the SVG viewBox dimensions as the raster size when width/height attributes are missing.
541
+ * When disabled (default), such SVGs fail to load instead of inferring a size.
542
+ */
543
+ readonly useViewBoxDimensions?: boolean;
544
+ }
545
+ /**
546
+ * Options accepted by {@link SpriteLayerInterface.registerImage}.
547
+ */
548
+ export interface SpriteImageRegisterOptions {
549
+ /** Target width in CSS pixels. When only one dimension is supplied, the aspect ratio is preserved if known. */
550
+ readonly width?: number;
551
+ /** Target height in CSS pixels. When only one dimension is supplied, the aspect ratio is preserved if known. */
552
+ readonly height?: number;
553
+ /** Resampling quality used during rasterization. */
554
+ readonly resizeQuality?: ResizeQuality;
555
+ /** SVG-specific configuration. */
556
+ readonly svg?: SpriteImageSvgOptions;
528
557
  }
529
558
  /** Horizontal alignment options for text glyphs. */
530
559
  export type SpriteTextGlyphHorizontalAlign = 'left' | 'center' | 'right';
@@ -605,9 +634,10 @@ export interface SpriteLayerInterface<TTag = any> extends CustomLayerInterface {
605
634
  *
606
635
  * @param {string} imageId - Unique image identifier.
607
636
  * @param {string | ImageBitmap} image - Image source (URL or ImageBitmap) to upload.
637
+ * @param {SpriteImageRegisterOptions | undefined} options - Optional SVG handling controls.
608
638
  * @returns {Promise<boolean>} Resolves to `true` when the image was registered; `false` if the ID already existed.
609
639
  */
610
- readonly registerImage: (imageId: string, image: string | ImageBitmap) => Promise<boolean>;
640
+ readonly registerImage: (imageId: string, image: string | ImageBitmap, options?: SpriteImageRegisterOptions) => Promise<boolean>;
611
641
  /**
612
642
  * Registers a text glyph texture for later use.
613
643
  *
@@ -679,6 +709,12 @@ export interface SpriteLayerInterface<TTag = any> extends CustomLayerInterface {
679
709
  * @returns {SpriteCurrentState<TTag> | undefined} Current state or `undefined` when not found.
680
710
  */
681
711
  readonly getSpriteState: (spriteId: string) => SpriteCurrentState<TTag> | undefined;
712
+ /**
713
+ * Enables or disables hit-test maintenance (quad-tree updates).
714
+ *
715
+ * @param {boolean} enabled - When false, hit testing is skipped and the internal data structure is cleared.
716
+ */
717
+ readonly setHitTestEnabled: (enabled: boolean) => void;
682
718
  /**
683
719
  * Attaches an image definition to a sprite.
684
720
  *
@@ -723,17 +759,13 @@ export interface SpriteLayerInterface<TTag = any> extends CustomLayerInterface {
723
759
  * @returns {boolean} `true` when the sprite was found and updated.
724
760
  */
725
761
  readonly updateSprite: (spriteId: string, update: SpriteUpdateEntry<TTag>) => boolean;
726
- /**
727
- * @deprecated Use {@link SpriteLayerInterface.mutateSprites} instead for clearer mutation flows.
728
- */
729
- readonly updateBulk: (updateBulkList: SpriteUpdateBulkEntry<TTag>[]) => number;
730
762
  /**
731
763
  * Adds, updates, or removes sprites based on an arbitrary collection of source items.
732
764
  *
733
765
  * @param {readonly TSourceItem[]} sourceItems - Source items that describe desired sprite state.
734
766
  * @param {SpriteMutateCallbacks<TTag, TSourceItem>} mutator - Callbacks responsible for creation and modification.
735
767
  * @returns {number} Number of sprites that changed. Counts each `add` that returns a non-null
736
- * initialiser and each `modify` that either invoked the updater helper or returned `'remove'`.
768
+ * initializer and each `modify` that either invoked the updater helper or returned `'remove'`.
737
769
  */
738
770
  readonly mutateSprites: <TSourceItem extends SpriteMutateSourceItem>(sourceItems: readonly TSourceItem[], mutator: SpriteMutateCallbacks<TTag, TSourceItem>) => number;
739
771
  /**
package/dist/utils.d.ts CHANGED
@@ -1,16 +1,32 @@
1
1
  /*!
2
2
  * name: maplibre-gl-layers
3
- * version: 0.6.0
3
+ * version: 0.11.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: 481f544de02fd3e71a2ba6c28bbb7eeb98b49eff
8
+ * git.commit.hash: 371efb126f281333d59ec75cfe788d45f3b1482e
9
9
  */
10
10
 
11
+ import { SpriteImageRegisterOptions } from './types';
12
+ export type SvgSizeResolutionErrorCode = 'size-missing' | 'viewbox-disabled' | 'invalid-dimensions';
13
+ export declare class SvgSizeResolutionError extends Error implements Error {
14
+ readonly code: SvgSizeResolutionErrorCode;
15
+ constructor(message: string, code: SvgSizeResolutionErrorCode);
16
+ }
17
+ /**
18
+ * Helper that read an ImageBitmap from a blob.
19
+ * @param blob Target blob.
20
+ * @param options Optional reading options.
21
+ * @returns Promise resolving to the ImageBitmap.
22
+ * @remarks This function helps reading SVG with better manner.
23
+ */
24
+ export declare const readImageBitmap: (blob: Blob, options?: SpriteImageRegisterOptions) => Promise<ImageBitmap>;
11
25
  /**
12
26
  * Helper that loads an ImageBitmap from a URL.
13
27
  * @param url Target image URL.
28
+ * @param options Optional loading options.
14
29
  * @returns Promise resolving to the ImageBitmap.
30
+ * @remarks This function helps loading SVG with better manner.
15
31
  */
16
- export declare const loadImageBitmap: (url: string) => Promise<ImageBitmap>;
32
+ export declare const loadImageBitmap: (url: string, options?: SpriteImageRegisterOptions) => Promise<ImageBitmap>;
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "git": {
3
3
  "tags": [
4
- "0.6.0"
4
+ "0.11.0"
5
5
  ],
6
6
  "branches": [
7
7
  "main"
8
8
  ],
9
- "version": "0.6.0",
9
+ "version": "0.11.0",
10
10
  "commit": {
11
- "hash": "481f544de02fd3e71a2ba6c28bbb7eeb98b49eff",
12
- "shortHash": "481f544",
13
- "date": "2025-10-30T14:50:01+09:00Z",
11
+ "hash": "371efb126f281333d59ec75cfe788d45f3b1482e",
12
+ "shortHash": "371efb1",
13
+ "date": "2025-11-01T23:41:18+09:00Z",
14
14
  "message": "Merge branch 'develop'"
15
15
  }
16
16
  },
17
- "version": "0.6.0",
17
+ "version": "0.11.0",
18
18
  "description": "MapLibre's layer extension library enabling the display, movement, and modification of large numbers of dynamic sprite images",
19
19
  "author": "Kouji Matsui (@kekyo@mi.kekyo.net)",
20
20
  "license": "MIT",
@@ -1,80 +0,0 @@
1
- /*!
2
- * name: maplibre-gl-layers
3
- * version: 0.6.0
4
- * description: MapLibre's layer extension library enabling the display, movement, and modification of large numbers of dynamic sprite images
5
- * author: Kouji Matsui (@kekyo@mi.kekyo.net)
6
- * license: MIT
7
- * repository.url: https://github.com/kekyo/maplibre-gl-layers.git
8
- * git.commit.hash: 481f544de02fd3e71a2ba6c28bbb7eeb98b49eff
9
- */
10
-
11
- import { EasingFunction, SpriteNumericInterpolationOptions } from './types';
12
- /**
13
- * Runtime state tracked for numeric interpolations.
14
- * @property {number} durationMs - Total duration of the interpolation in milliseconds.
15
- * @property {EasingFunction} easing - Easing function applied to progress samples.
16
- * @property {number} from - Start value used for interpolation.
17
- * @property {number} to - Adjusted target along the shortest rotation path.
18
- * @property {number} finalValue - Caller-requested final value (used once interpolation completes).
19
- * @property {number} startTimestamp - Timestamp when interpolation began, `-1` until evaluation starts.
20
- */
21
- export interface NumericInterpolationState {
22
- readonly durationMs: number;
23
- readonly easing: EasingFunction;
24
- readonly from: number;
25
- readonly to: number;
26
- readonly finalValue: number;
27
- startTimestamp: number;
28
- }
29
- /**
30
- * Parameters required to construct a {@link NumericInterpolationState}.
31
- * @property {number} currentValue - Current numeric value rendered on screen.
32
- * @property {number} targetValue - Desired value after interpolation completes.
33
- * @property {SpriteNumericInterpolationOptions} options - Timing and easing configuration.
34
- */
35
- export interface CreateNumericInterpolationStateParams {
36
- currentValue: number;
37
- targetValue: number;
38
- options: SpriteNumericInterpolationOptions;
39
- }
40
- /**
41
- * Result returned by {@link createNumericInterpolationState} containing state and a flag for activation.
42
- * @property {NumericInterpolationState} state - Resolved state object.
43
- * @property {boolean} requiresInterpolation - Indicates whether the caller should animate or snap.
44
- */
45
- export interface CreateNumericInterpolationStateResult {
46
- readonly state: NumericInterpolationState;
47
- readonly requiresInterpolation: boolean;
48
- }
49
- /**
50
- * Creates interpolation state describing how to move from the current value to the target value.
51
- * @param {CreateNumericInterpolationStateParams} params - Inputs describing the current, target, and options.
52
- * @returns {CreateNumericInterpolationStateResult} State data plus a flag indicating if animation is needed.
53
- */
54
- export declare const createNumericInterpolationState: (params: CreateNumericInterpolationStateParams) => CreateNumericInterpolationStateResult;
55
- /**
56
- * Parameters describing interpolation evaluation state.
57
- * @property {NumericInterpolationState} state - State generated via {@link createNumericInterpolationState}.
58
- * @property {number} timestamp - Timestamp in milliseconds used to sample the interpolation curve.
59
- */
60
- export interface EvaluateNumericInterpolationParams {
61
- state: NumericInterpolationState;
62
- timestamp: number;
63
- }
64
- /**
65
- * Result of evaluating a numeric interpolation at a specific timestamp.
66
- * @property {number} value - Current interpolated value (or final value after completion).
67
- * @property {boolean} completed - Indicates whether interpolation reached the end.
68
- * @property {number} effectiveStartTimestamp - Start timestamp applied during evaluation.
69
- */
70
- export interface EvaluateNumericInterpolationResult {
71
- readonly value: number;
72
- readonly completed: boolean;
73
- readonly effectiveStartTimestamp: number;
74
- }
75
- /**
76
- * Evaluates a numeric interpolation against the provided timestamp.
77
- * @param {EvaluateNumericInterpolationParams} params - Inputs containing interpolation state and sample timestamp.
78
- * @returns {EvaluateNumericInterpolationResult} Current value, completion flag, and effective start time.
79
- */
80
- export declare const evaluateNumericInterpolation: (params: EvaluateNumericInterpolationParams) => EvaluateNumericInterpolationResult;