@apexara/map 1.1.0 → 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.
- package/README.md +315 -6
- package/fesm2022/apexara-map-geo.mjs +340 -0
- package/fesm2022/apexara-map-geo.mjs.map +1 -0
- package/fesm2022/apexara-map-search.mjs +93 -0
- package/fesm2022/apexara-map-search.mjs.map +1 -0
- package/fesm2022/apexara-map.mjs +309 -64
- package/fesm2022/apexara-map.mjs.map +1 -1
- package/package.json +9 -1
- package/types/apexara-map-geo.d.ts +217 -0
- package/types/apexara-map-search.d.ts +39 -0
- package/types/apexara-map.d.ts +160 -24
package/types/apexara-map.d.ts
CHANGED
|
@@ -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
|
-
|
|
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. */
|
|
@@ -70,10 +115,19 @@ declare class MapboxService {
|
|
|
70
115
|
private containerStack;
|
|
71
116
|
private readonly _activeContainer;
|
|
72
117
|
readonly activeContainer: Signal<HTMLElement | null>;
|
|
118
|
+
private supported;
|
|
119
|
+
private readonly fitDefaults;
|
|
73
120
|
/** Back-compat wrapper around `activate`. SSR-safe. */
|
|
74
121
|
init(options: MapInitOptions): Promise<void>;
|
|
75
|
-
|
|
122
|
+
/** Whether this browser can run mapbox (WebGL2, workers, canvas reads). Asked once; false on the server. */
|
|
123
|
+
isSupported(): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Puts the shared map on `container`. False when it did not start there: on the server, in a browser that cannot run
|
|
126
|
+
* mapbox, or when the first start throws (undone and reported). A running map's errors still throw.
|
|
127
|
+
*/
|
|
128
|
+
activate(container: HTMLElement, options: MapInitOptions): boolean;
|
|
76
129
|
deactivate(container: HTMLElement): void;
|
|
130
|
+
private startMap;
|
|
77
131
|
private createMap;
|
|
78
132
|
/** Current map center as a `LngLat`. Prefer the `center` signal for reactive reads. */
|
|
79
133
|
getCenter(): mapboxgl.LngLat;
|
|
@@ -103,25 +157,54 @@ declare class MapboxService {
|
|
|
103
157
|
*/
|
|
104
158
|
getClusterProperties(sourceId: string, clusterId: number, limit?: number, offset?: number): Promise<mapboxgl.GeoJSONFeature[]>;
|
|
105
159
|
/**
|
|
106
|
-
*
|
|
107
|
-
*
|
|
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.
|
|
162
|
+
*/
|
|
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.
|
|
108
167
|
*/
|
|
109
|
-
getRenderedFeatures(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
|
|
114
|
-
/**
|
|
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. */
|
|
115
179
|
moveCenter(center: [number, number], zoom?: number): void;
|
|
116
|
-
/**
|
|
117
|
-
|
|
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;
|
|
118
196
|
/**
|
|
119
197
|
* Add a GeoJSON source. Pass `clustered: true` and optional `clusterRadius`/`clusterMaxZoom`
|
|
120
198
|
* for point clustering. Set `generateId: true` when you plan to use feature-state.
|
|
121
199
|
*/
|
|
122
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;
|
|
123
206
|
/** Replace the data of an existing GeoJSON source in place. No-op if the source is missing. */
|
|
124
|
-
updateSource(id: string, data: GeoJSON.
|
|
207
|
+
updateSource(id: string, data: string | GeoJSON.GeoJSON): void;
|
|
125
208
|
/**
|
|
126
209
|
* Add a layer to the style. Pass `beforeId` to insert the new layer beneath
|
|
127
210
|
* an existing one (useful for controlling draw order against style layers).
|
|
@@ -172,6 +255,8 @@ declare class MapboxService {
|
|
|
172
255
|
* Useful for discovering layer names from a custom Studio style so you can target them at runtime.
|
|
173
256
|
*/
|
|
174
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;
|
|
175
260
|
/** `true` when a layer with this id exists in the current style. */
|
|
176
261
|
hasLayer(id: string): boolean;
|
|
177
262
|
/** `true` when a source with this id exists. */
|
|
@@ -210,14 +295,19 @@ declare class MapboxService {
|
|
|
210
295
|
* Enter polygon-drawing mode. Lazily mounts a `@mapbox/mapbox-gl-draw` control,
|
|
211
296
|
* hides its default UI (consumer controls the toggle), and switches to `draw_polygon`.
|
|
212
297
|
* The user clicks vertices and double-clicks (or clicks the first vertex) to close.
|
|
213
|
-
* The completed polygon is emitted on `polygonCreate`.
|
|
298
|
+
* The completed polygon is emitted on `polygonCreate`. `keepPanZoom` leaves drag and zoom on.
|
|
214
299
|
*/
|
|
215
|
-
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;
|
|
216
306
|
/** Exit polygon-drawing mode and remove any in-progress or drawn polygons. */
|
|
217
307
|
disableDrawPolygon(): void;
|
|
218
308
|
/**
|
|
219
|
-
* Disable pan/zoom handlers so the viewport stays fixed while the user draws
|
|
220
|
-
* 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
|
|
221
311
|
* `unlockInteractions`. Safe to call repeatedly — a second call is a no-op
|
|
222
312
|
* because saved state is only captured on the first lock.
|
|
223
313
|
*/
|
|
@@ -229,6 +319,9 @@ declare class MapboxService {
|
|
|
229
319
|
private unlockInteractions;
|
|
230
320
|
/** Remove every polygon the user has drawn, keeping draw mode active. */
|
|
231
321
|
clearDrawnPolygons(): void;
|
|
322
|
+
private clusterSourceOf;
|
|
323
|
+
private notClusteredError;
|
|
324
|
+
private insetOf;
|
|
232
325
|
/** `isStyleLoaded()` also waits for tiles; what addSource needs is mapbox's one-shot "style parsed" flag. */
|
|
233
326
|
private isStyleParsed;
|
|
234
327
|
/** Fetch a URL into an `HTMLImageElement`. Resolves on `load`, rejects on `error`. */
|
|
@@ -277,6 +370,48 @@ declare class ApexMapComponent {
|
|
|
277
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>;
|
|
278
371
|
}
|
|
279
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
|
+
|
|
280
415
|
type Coord = [number, number];
|
|
281
416
|
/**
|
|
282
417
|
* Recursively flatten any nesting of GeoJSON coordinates down to a flat list of [lng, lat] pairs.
|
|
@@ -284,15 +419,16 @@ type Coord = [number, number];
|
|
|
284
419
|
*/
|
|
285
420
|
declare function flattenCoords(arr: Position | Position[] | Position[][] | Position[][][]): Coord[];
|
|
286
421
|
/**
|
|
287
|
-
* Compute the [[minLng, minLat], [maxLng, maxLat]] bounds of a flat list of coordinates
|
|
288
|
-
*
|
|
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.
|
|
289
425
|
*/
|
|
290
|
-
declare function calculateBounds(coords: Coord[]): mapboxgl.LngLatBoundsLike;
|
|
426
|
+
declare function calculateBounds(coords: Coord[], options?: MapBoundsOptions): mapboxgl.LngLatBoundsLike;
|
|
291
427
|
/**
|
|
292
428
|
* Build a closed square polygon of side `2 * radiusKm` centered at `center`.
|
|
293
429
|
* Useful when you need a small viewport-like polygon for point-in-polygon queries.
|
|
294
430
|
*/
|
|
295
431
|
declare function calculateViewportPolygonFromCenter(center: Coord, radiusKm?: number): number[][][];
|
|
296
432
|
|
|
297
|
-
export { ApexMapComponent, MapboxService, calculateBounds, calculateViewportPolygonFromCenter, flattenCoords };
|
|
298
|
-
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 };
|