@apexara/map 1.1.1 → 1.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.
@@ -1,16 +1,25 @@
1
1
  import * as mapbox_gl from 'mapbox-gl';
2
- import { LayerSpecification, StyleSpecification } from 'mapbox-gl';
2
+ import { PointLike, FilterSpecification, PaddingOptions, EasingOptions, CameraOptions, LayerSpecification, StyleSpecification } from 'mapbox-gl';
3
3
  import * as _angular_core from '@angular/core';
4
- import { Signal, WritableSignal, DestroyRef } from '@angular/core';
4
+ import { Signal, WritableSignal, DestroyRef, OnDestroy } from '@angular/core';
5
5
  import { Subject } from 'rxjs';
6
6
  import * as GeoJSON from 'geojson';
7
7
  import { Position } from 'geojson';
8
+ import { MapLngLat, MapLocateOptions, MapLocateResult, MapBoundsOptions } from '@apexara/map/geo';
8
9
  export { MAP_CONFIG, MapConfig, MapStyles, provideMap } from '@apexara/map/config';
9
10
 
10
11
  /** An image `MapboxService.replaceImage` registers: whatever `mapboxgl.Map.addImage` takes (`ImageData`, an `<img>`, …). */
11
12
  type MapImageSource = Parameters<mapboxgl.Map['addImage']>[1];
12
13
  /** Its options: `pixelRatio`, `sdf`, `stretchX` / `stretchY`, `content`. */
13
14
  type MapImageOptions = Parameters<mapboxgl.Map['addImage']>[2];
15
+ /** Camera and animation options for `fitBounds`: `padding` (a number or per side), `maxZoom`, `duration`, `animate`, … */
16
+ type MapFitOptions = EasingOptions;
17
+ /** Data mapbox copies onto a camera move's `movestart` / `moveend`, e.g. to tell an app's own moves from the reader's. */
18
+ type MapEventData = object;
19
+ /** A screen point, or a `[corner, corner]` box, in pixels. */
20
+ type MapQueryGeometry = PointLike | [PointLike, PointLike];
21
+ /** Pixels in from the canvas edges: one number for every side, or per side (a side left out is 0). */
22
+ type MapInsets = number | PaddingOptions;
14
23
  interface MapInitOptions {
15
24
  /** DOM element the map renders into. */
16
25
  container: HTMLElement;
@@ -33,13 +42,49 @@ interface MapInitOptions {
33
42
  }
34
43
  interface SourceConfig {
35
44
  id: string;
36
- data: string | GeoJSON.FeatureCollection;
45
+ /** Any GeoJSON (a collection, a single feature, a geometry) or a URL to fetch it from. */
46
+ data: string | GeoJSON.GeoJSON;
37
47
  clustered?: boolean;
38
48
  clusterRadius?: number;
39
49
  clusterMaxZoom?: number;
40
50
  /** When true, Mapbox auto-generates a stable numeric `id` per feature — required for feature-state APIs. */
41
51
  generateId?: boolean;
42
52
  }
53
+ interface MapStyleOptions {
54
+ /** False rebuilds the style from scratch instead of diffing it, for a swap where mapbox's diff keeps a stale source. */
55
+ diff?: boolean;
56
+ }
57
+ /** What `getRenderedFeatures` keeps: features of these `layers` that pass `filter`. */
58
+ interface MapFeatureQuery {
59
+ layers?: string[];
60
+ filter?: FilterSpecification;
61
+ /** False skips checking `filter` against the style spec, for a filter already known good. */
62
+ validate?: boolean;
63
+ }
64
+ interface MapDrawOptions {
65
+ /**
66
+ * Keep drag-pan, wheel zoom and pinch zoom on while drawing; a click still adds a corner on a moving map. Box zoom,
67
+ * double-click zoom (a double-click closes the shape) and keyboard stay locked. Off by default: everything locks.
68
+ */
69
+ keepPanZoom?: boolean;
70
+ }
71
+ /** The dot `MapUserLocationLayer` draws. */
72
+ interface MapUserLocationStyle {
73
+ circleRadius: number;
74
+ circleColor: string;
75
+ strokeColor: string;
76
+ strokeWidth: number;
77
+ }
78
+ interface MapUserLocationConfig {
79
+ /** Defaults to `'user-location'`. */
80
+ sourceId?: string;
81
+ /** Defaults to `'user-location-dot'`. */
82
+ layerId?: string;
83
+ /** The zoom `locate` flies to: the consumer's own, there is no default. */
84
+ zoom: number;
85
+ /** The dot's look: the consumer's own, there is no default. */
86
+ style: MapUserLocationStyle;
87
+ }
43
88
 
44
89
  declare class MapboxService {
45
90
  /** Click on empty canvas (no features under the cursor). Event stream. */
@@ -71,6 +116,7 @@ declare class MapboxService {
71
116
  private readonly _activeContainer;
72
117
  readonly activeContainer: Signal<HTMLElement | null>;
73
118
  private supported;
119
+ private readonly fitDefaults;
74
120
  /** Back-compat wrapper around `activate`. SSR-safe. */
75
121
  init(options: MapInitOptions): Promise<void>;
76
122
  /** Whether this browser can run mapbox (WebGL2, workers, canvas reads). Asked once; false on the server. */
@@ -111,25 +157,54 @@ declare class MapboxService {
111
157
  */
112
158
  getClusterProperties(sourceId: string, clusterId: number, limit?: number, offset?: number): Promise<mapboxgl.GeoJSONFeature[]>;
113
159
  /**
114
- * Query features rendered at a screen point, optionally restricted to specific layers.
115
- * Returns `[]` when the map has not been initialised yet.
160
+ * The zoom at which a cluster splits into its children, e.g. to `easeTo` it. Rejects as `getClusterProperties` does,
161
+ * and when mapbox answers with no zoom.
116
162
  */
117
- getRenderedFeatures(point: mapboxgl.PointLike, params?: {
118
- layers?: string[];
119
- }): mapboxgl.GeoJSONFeature[];
120
- /** Swap the base style. Custom sources/layers you added must be re-applied after `styledata`. */
121
- setStyle(styleUrl: string): void;
122
- /** Animate the camera to `center` at the given zoom (default 13). */
163
+ getClusterExpansionZoom(sourceId: string, clusterId: number): Promise<number>;
164
+ /**
165
+ * Features rendered at a screen point or in a `[corner, corner]` box (the whole viewport when `geometry` is
166
+ * undefined), kept to `layers` and `filter`. Returns `[]` when the map has not been initialised yet.
167
+ */
168
+ getRenderedFeatures(geometry?: MapQueryGeometry, query?: MapFeatureQuery): mapboxgl.GeoJSONFeature[];
169
+ /** Whether `lngLat` projects inside the canvas, `insets` pixels in from its edges. False before the map exists. */
170
+ isPointOnScreen(lngLat: mapboxgl.LngLatLike, insets?: MapInsets): boolean;
171
+ /** Whether the shared map is on screen inside `element`: its active container is `element` or below it. */
172
+ isShownIn(element: Node): boolean;
173
+ /**
174
+ * Swap the base style. `{ diff: false }` rebuilds it from scratch, for a swap where mapbox's diff keeps a source the
175
+ * rebuild then trips over. Custom sources/layers you added must be re-applied after `styledata`.
176
+ */
177
+ setStyle(styleUrl: string, options?: MapStyleOptions): void;
178
+ /** Animate the camera to `center` at the given zoom (default 13). `flyTo` takes a duration, a curve and event data. */
123
179
  moveCenter(center: [number, number], zoom?: number): void;
124
- /** Fit the viewport to `bounds` with optional pixel padding (default 40). */
125
- fitBounds(bounds: mapboxgl.LngLatBoundsLike, padding?: number): void;
180
+ /**
181
+ * Fit the viewport to `bounds`. A number is the padding (default 40) of a one-second slide; options (`padding` per
182
+ * side, `maxZoom`, `duration`, `animate: false`, …) lay over those same defaults. `eventData` reaches the move's events.
183
+ */
184
+ fitBounds(bounds: mapboxgl.LngLatBoundsLike, options?: number | MapFitOptions, eventData?: MapEventData): void;
185
+ /** Fly the camera (mapbox's `flyTo`: `center`, `zoom`, `duration`, `curve`, `offset`, …). */
186
+ flyTo(options: EasingOptions, eventData?: MapEventData): void;
187
+ /** Ease the camera (mapbox's `easeTo`), e.g. into a cluster's expansion zoom. */
188
+ easeTo(options: EasingOptions, eventData?: MapEventData): void;
189
+ /** Move the camera at once (mapbox's `jumpTo`). */
190
+ jumpTo(options: CameraOptions, eventData?: MapEventData): void;
191
+ /**
192
+ * Have mapbox re-read its container's size, e.g. from a `ResizeObserver`. A resize fires `movestart` / `moveend`, which
193
+ * carry `eventData`. No-op before the map exists.
194
+ */
195
+ resize(eventData?: MapEventData): void;
126
196
  /**
127
197
  * Add a GeoJSON source. Pass `clustered: true` and optional `clusterRadius`/`clusterMaxZoom`
128
198
  * for point clustering. Set `generateId: true` when you plan to use feature-state.
129
199
  */
130
200
  addSource(config: SourceConfig): void;
201
+ /**
202
+ * Add a GeoJSON source, or replace the data of the one already under `config.id` (its other options stay as they
203
+ * were). True when it was added, so the caller adds the layers that draw it.
204
+ */
205
+ upsertSource(config: SourceConfig): boolean;
131
206
  /** Replace the data of an existing GeoJSON source in place. No-op if the source is missing. */
132
- updateSource(id: string, data: GeoJSON.FeatureCollection): void;
207
+ updateSource(id: string, data: string | GeoJSON.GeoJSON): void;
133
208
  /**
134
209
  * Add a layer to the style. Pass `beforeId` to insert the new layer beneath
135
210
  * an existing one (useful for controlling draw order against style layers).
@@ -180,6 +255,8 @@ declare class MapboxService {
180
255
  * Useful for discovering layer names from a custom Studio style so you can target them at runtime.
181
256
  */
182
257
  getLayerIds(): string[];
258
+ /** Move a layer to the top, or just under `beforeId`. No-op when the layer is missing. */
259
+ moveLayer(id: string, beforeId?: string): void;
183
260
  /** `true` when a layer with this id exists in the current style. */
184
261
  hasLayer(id: string): boolean;
185
262
  /** `true` when a source with this id exists. */
@@ -218,14 +295,19 @@ declare class MapboxService {
218
295
  * Enter polygon-drawing mode. Lazily mounts a `@mapbox/mapbox-gl-draw` control,
219
296
  * hides its default UI (consumer controls the toggle), and switches to `draw_polygon`.
220
297
  * The user clicks vertices and double-clicks (or clicks the first vertex) to close.
221
- * The completed polygon is emitted on `polygonCreate`.
298
+ * The completed polygon is emitted on `polygonCreate`. `keepPanZoom` leaves drag and zoom on.
222
299
  */
223
- enableDrawPolygon(): void;
300
+ enableDrawPolygon(options?: MapDrawOptions): void;
301
+ /**
302
+ * Close the polygon being drawn, as a double-click would: it is emitted on `polygonCreate` when it has three corners
303
+ * or more. Draw mode (and its gesture lock) stays until `disableDrawPolygon`. No-op when not drawing.
304
+ */
305
+ finishDrawPolygon(): void;
224
306
  /** Exit polygon-drawing mode and remove any in-progress or drawn polygons. */
225
307
  disableDrawPolygon(): void;
226
308
  /**
227
- * Disable pan/zoom handlers so the viewport stays fixed while the user draws.
228
- * Saves the prior enabled-state for each handler so it can be restored by
309
+ * Disable pan/zoom handlers so the viewport stays fixed while the user draws (drag, wheel and pinch stay on with
310
+ * `keepPanZoom`). Saves the prior enabled-state for each handler so it can be restored by
229
311
  * `unlockInteractions`. Safe to call repeatedly — a second call is a no-op
230
312
  * because saved state is only captured on the first lock.
231
313
  */
@@ -237,6 +319,9 @@ declare class MapboxService {
237
319
  private unlockInteractions;
238
320
  /** Remove every polygon the user has drawn, keeping draw mode active. */
239
321
  clearDrawnPolygons(): void;
322
+ private clusterSourceOf;
323
+ private notClusteredError;
324
+ private insetOf;
240
325
  /** `isStyleLoaded()` also waits for tiles; what addSource needs is mapbox's one-shot "style parsed" flag. */
241
326
  private isStyleParsed;
242
327
  /** Fetch a URL into an `HTMLImageElement`. Resolves on `load`, rejects on `error`. */
@@ -285,6 +370,48 @@ declare class ApexMapComponent {
285
370
  static ɵcmp: _angular_core.ɵɵComponentDeclaration<ApexMapComponent, "apex-map", never, { "center": { "alias": "center"; "required": false; "isSignal": true; }; "zoom": { "alias": "zoom"; "required": false; "isSignal": true; }; "mapStyle": { "alias": "mapStyle"; "required": false; "isSignal": true; }; "maxBounds": { "alias": "maxBounds"; "required": false; "isSignal": true; }; "showNavigation": { "alias": "showNavigation"; "required": false; "isSignal": true; }; }, { "mapReady": "mapReady"; "mapClick": "mapClick"; "featureClick": "featureClick"; }, never, never, true, never>;
286
371
  }
287
372
 
373
+ /**
374
+ * A trackpad pinch arrives as a ctrl+wheel. Over anything laid on the map (a card, the map's buttons, a legend, a top
375
+ * bar) it would zoom the page; this hands it to the shared map under it instead. Put it on the overlay itself, or on a
376
+ * container holding the map and its overlays.
377
+ */
378
+ declare class ApexMapPinchZoomDirective implements OnDestroy {
379
+ constructor();
380
+ private readonly host;
381
+ private readonly map;
382
+ /** Stops listening. */
383
+ ngOnDestroy(): void;
384
+ private readonly onWheel;
385
+ private holdsShownMap;
386
+ static ɵfac: _angular_core.ɵɵFactoryDeclaration<ApexMapPinchZoomDirective, never>;
387
+ static ɵdir: _angular_core.ɵɵDirectiveDeclaration<ApexMapPinchZoomDirective, "[apexMapPinchZoom]", never, {}, {}, never, never, true, never>;
388
+ }
389
+
390
+ /**
391
+ * The reader's location as a dot on the map, in the consumer's `style`, and the camera move to it at the consumer's
392
+ * `zoom`. Not injectable: a map surface builds one with the `MapboxService` it draws on, repaints it after a style swap
393
+ * and destroys it on teardown.
394
+ */
395
+ declare class MapUserLocationLayer {
396
+ private readonly map;
397
+ constructor(map: MapboxService, config: MapUserLocationConfig);
398
+ /** The last location read, as `[lng, lat]`; null until one is. */
399
+ readonly location: _angular_core.WritableSignal<MapLngLat | null>;
400
+ private readonly sourceId;
401
+ private readonly layerId;
402
+ private readonly zoom;
403
+ private readonly style;
404
+ /** Reads the location once and draws the dot; the camera stays where it is. */
405
+ init(options?: MapLocateOptions): Promise<MapLocateResult>;
406
+ /** Flies to the location (at the configured zoom), reading it first when none is known yet. */
407
+ locate(options?: MapLocateOptions): Promise<MapLocateResult>;
408
+ /** Puts the dot (back) on the map, e.g. after a style swap. No-op until a location is known. */
409
+ repaint(): void;
410
+ /** Takes the dot off the map; the location is kept for the next `repaint`. */
411
+ destroy(): void;
412
+ private pointOf;
413
+ }
414
+
288
415
  type Coord = [number, number];
289
416
  /**
290
417
  * Recursively flatten any nesting of GeoJSON coordinates down to a flat list of [lng, lat] pairs.
@@ -292,15 +419,16 @@ type Coord = [number, number];
292
419
  */
293
420
  declare function flattenCoords(arr: Position | Position[] | Position[][] | Position[][][]): Coord[];
294
421
  /**
295
- * Compute the [[minLng, minLat], [maxLng, maxLat]] bounds of a flat list of coordinates.
296
- * Return value is compatible with `mapboxgl.LngLatBoundsLike`.
422
+ * Compute the [[minLng, minLat], [maxLng, maxLat]] bounds of a flat list of coordinates, compatible with
423
+ * `mapboxgl.LngLatBoundsLike`. `wrapAntimeridian` frames a shape across ±180° by its narrower side. No coordinates give
424
+ * `[[180, 90], [-180, -90]]`. For whole GeoJSON, `MapGeometryUtil.boundsOf` walks it without flattening.
297
425
  */
298
- declare function calculateBounds(coords: Coord[]): mapboxgl.LngLatBoundsLike;
426
+ declare function calculateBounds(coords: Coord[], options?: MapBoundsOptions): mapboxgl.LngLatBoundsLike;
299
427
  /**
300
428
  * Build a closed square polygon of side `2 * radiusKm` centered at `center`.
301
429
  * Useful when you need a small viewport-like polygon for point-in-polygon queries.
302
430
  */
303
431
  declare function calculateViewportPolygonFromCenter(center: Coord, radiusKm?: number): number[][][];
304
432
 
305
- export { ApexMapComponent, MapboxService, calculateBounds, calculateViewportPolygonFromCenter, flattenCoords };
306
- export type { MapImageOptions, MapImageSource, MapInitOptions, SourceConfig };
433
+ export { ApexMapComponent, ApexMapPinchZoomDirective, MapUserLocationLayer, MapboxService, calculateBounds, calculateViewportPolygonFromCenter, flattenCoords };
434
+ export type { MapDrawOptions, MapEventData, MapFeatureQuery, MapFitOptions, MapImageOptions, MapImageSource, MapInitOptions, MapInsets, MapQueryGeometry, MapStyleOptions, MapUserLocationConfig, MapUserLocationStyle, SourceConfig };