@yappkit/front-module-map 0.1.8 → 0.2.1
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/lib/DeckGLOverlay.js +76 -0
- package/lib/providers/deckgl.js +111 -110
- package/lib/providers/google-maps.js +287 -332
- package/lib/providers/mapbox.js +230 -238
- package/lib/providers/maplibre.js +27 -244
- package/lib/searoute.js +38321 -59
- package/lib/types/main.d.ts +121 -0
- package/lib/types/providers/DeckGL.d.ts +102 -0
- package/lib/types/providers/DeckGLOverlay.d.ts +84 -0
- package/lib/types/providers/GoogleMaps.d.ts +321 -0
- package/lib/types/providers/Mapbox.d.ts +210 -0
- package/lib/types/providers/Maplibre.d.ts +37 -0
- package/lib/types/searoute/searoute.d.ts +45 -0
- package/lib/types/utils/getAirRoute.d.ts +71 -0
- package/lib/types/utils/getWaterRoute.d.ts +40 -0
- package/lib/types/utils/normalizeRoute.d.ts +8 -0
- package/lib/yappkit-map.js +60 -729
- package/package.json +21 -17
- package/lib/mapbox-gl.css +0 -1
- package/lib/mapbox-gl.js +0 -32271
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { DeckGLOverlay } from './DeckGLOverlay.js';
|
|
2
|
+
/** Shared wiring lives in DeckGLOverlay.js (#174); only the detach mode is provider-specific. */
|
|
3
|
+
declare class MapboxDeckGLOverlay extends DeckGLOverlay {
|
|
4
|
+
/** @type {import('mapbox-gl').Map|import('maplibre-gl').Map|null} The host map; released by destroy (#284). */
|
|
5
|
+
map: import('mapbox-gl').Map | import('maplibre-gl').Map | null;
|
|
6
|
+
/** Wire the shared overlay state and keep the host map for `_detach` (#151).
|
|
7
|
+
* @param {object} args - Constructor args.
|
|
8
|
+
* @param {import('vue').WatchStopHandle[]} args.unwatchFn - The overlay's own watcher stop handles (#151).
|
|
9
|
+
* @param {import('mapbox-gl').Map|import('maplibre-gl').Map} args.map - The host map (maplibre-gl's on the Maplibre provider).
|
|
10
|
+
* @param {MapboxDeckGLOverlay[]} [args.trackedIn] - The owning map wrapper's overlays list (#156).
|
|
11
|
+
*/
|
|
12
|
+
constructor({ unwatchFn, map, trackedIn }: {
|
|
13
|
+
unwatchFn: import('vue').WatchStopHandle[];
|
|
14
|
+
map: import('mapbox-gl').Map | import('maplibre-gl').Map;
|
|
15
|
+
trackedIn?: MapboxDeckGLOverlay[];
|
|
16
|
+
});
|
|
17
|
+
/** mapbox-gl's removeControl triggers MapboxOverlay's onRemove, which finalizes the
|
|
18
|
+
* underlying deck instance (#151).
|
|
19
|
+
* @returns {void}
|
|
20
|
+
*/
|
|
21
|
+
_detach(): void;
|
|
22
|
+
/** Release the provider-specific Map reference after the base cleanup: a destroyed wrapper still
|
|
23
|
+
* held by the consumer (setDeckGLOverlay return, @loaded payload) retained the whole mapbox-gl
|
|
24
|
+
* Map graph — the base destroy only clears what IT owns (#212 covered the list→wrapper side). (#284)
|
|
25
|
+
* @returns {void}
|
|
26
|
+
*/
|
|
27
|
+
destroy(): void;
|
|
28
|
+
}
|
|
29
|
+
export type MapSourceDef = (Parameters<import('mapbox-gl').Map['addSource']>[1] | Parameters<import('maplibre-gl').Map['addSource']>[1]) & {
|
|
30
|
+
id: string;
|
|
31
|
+
};
|
|
32
|
+
export type MapLayerDef = Parameters<import('mapbox-gl').Map['addLayer']>[0] | Parameters<import('maplibre-gl').Map['addLayer']>[0];
|
|
33
|
+
/**
|
|
34
|
+
* One entry of the `sources` array/prop: whatever the underlying map's `addSource` accepts (a source
|
|
35
|
+
* specification — GeoJSON, vector, raster… — or a custom source), plus the `id` the wrapper diffs by (#143).
|
|
36
|
+
* @typedef {(Parameters<import('mapbox-gl').Map['addSource']>[1]|Parameters<import('maplibre-gl').Map['addSource']>[1]) & { id: string }} MapSourceDef
|
|
37
|
+
*/
|
|
38
|
+
/**
|
|
39
|
+
* One entry of the `layers` array/prop: whatever the underlying map's `addLayer` accepts — a layer
|
|
40
|
+
* specification (whose `source` may be an inline source object, see the #9135 workaround in
|
|
41
|
+
* watchLayers) or a custom layer.
|
|
42
|
+
* @typedef {Parameters<import('mapbox-gl').Map['addLayer']>[0]|Parameters<import('maplibre-gl').Map['addLayer']>[0]} MapLayerDef
|
|
43
|
+
*/
|
|
44
|
+
/**
|
|
45
|
+
* The resolved map wrapper: the raw map on `.map`, the reactive watchers, and setDeckGLOverlay.
|
|
46
|
+
* Shared by the Mapbox and Maplibre providers (createMap is not overridden, #154).
|
|
47
|
+
*/
|
|
48
|
+
declare class MapboxMap {
|
|
49
|
+
/** @type {import('mapbox-gl').Map|import('maplibre-gl').Map|null} The raw underlying map (maplibre-gl's on the Maplibre provider), set by createMap. */
|
|
50
|
+
map: import('mapbox-gl').Map | import('maplibre-gl').Map | null;
|
|
51
|
+
watching: {
|
|
52
|
+
sources: boolean;
|
|
53
|
+
layers: boolean;
|
|
54
|
+
};
|
|
55
|
+
/** @type {import('vue').WatchStopHandle[]} Stop handles of every watcher owned by the map, run on unmount. */
|
|
56
|
+
unwatchFn: import('vue').WatchStopHandle[];
|
|
57
|
+
/** @type {MapboxDeckGLOverlay[]} */
|
|
58
|
+
overlays: MapboxDeckGLOverlay[];
|
|
59
|
+
/** @type {WeakMap<object, string>} */
|
|
60
|
+
_propsIds: WeakMap<object, string>;
|
|
61
|
+
constructor();
|
|
62
|
+
/** Signature of a source's non-data props, cached per object identity (#158).
|
|
63
|
+
* @param {MapSourceDef} source - A source object from the `sources` prop.
|
|
64
|
+
* @returns {string} The JSON signature of the source without its `data`.
|
|
65
|
+
*/
|
|
66
|
+
_propsIdOf(source: MapSourceDef): string;
|
|
67
|
+
/** Keep the map's sources in sync with the reactive array, diffed by source id (#143): sources are
|
|
68
|
+
* shallow-compared — swap array/object identity to update — except a data-only change (same
|
|
69
|
+
* propsId), applied in place through setData.
|
|
70
|
+
* @template {MapSourceDef[]|undefined} T
|
|
71
|
+
* @param {import('vue').Ref<T>} sources - The reactive sources array.
|
|
72
|
+
* @param {import('vue').WatchOptions} [options] - Extra vue watch options, merged over `{ immediate: true }`.
|
|
73
|
+
* @returns {void}
|
|
74
|
+
*/
|
|
75
|
+
watchSources<T extends MapSourceDef[] | undefined>(sources: import('vue').Ref<T>, options?: import('vue').WatchOptions): void;
|
|
76
|
+
/** Keep the map's layers in sync with the reactive array, diffed by layer id (#144): layers are
|
|
77
|
+
* shallow-compared — swap array/layer identity to update; added/changed layers land at their array
|
|
78
|
+
* position in the z-order (#301).
|
|
79
|
+
* @template {MapLayerDef[]|undefined} T
|
|
80
|
+
* @param {import('vue').Ref<T>} layers - The reactive layers array.
|
|
81
|
+
* @param {import('vue').WatchOptions} [options] - Extra vue watch options, merged over `{ immediate: true }`.
|
|
82
|
+
* @returns {void}
|
|
83
|
+
*/
|
|
84
|
+
watchLayers<T extends MapLayerDef[] | undefined>(layers: import('vue').Ref<T>, options?: import('vue').WatchOptions): void;
|
|
85
|
+
/** Attach a deck.gl overlay (lazy-loaded MapboxOverlay) to the map.
|
|
86
|
+
* @param {import('@deck.gl/mapbox').MapboxOverlayProps} [options] - The overlay's constructor props (deck.gl layers, interleaved, …).
|
|
87
|
+
* @returns {Promise<MapboxDeckGLOverlay>} The overlay wrapper: its own watchOptions/watchLayers/destroy.
|
|
88
|
+
*/
|
|
89
|
+
setDeckGLOverlay(options?: import('@deck.gl/mapbox').MapboxOverlayProps): Promise<MapboxDeckGLOverlay>;
|
|
90
|
+
}
|
|
91
|
+
export type MapboxServiceName = NonNullable<import('../main.js').MapboxConfig['services']>[number];
|
|
92
|
+
export type MapboxMapExtraOptions = {
|
|
93
|
+
/**
|
|
94
|
+
* - Take over map creation timing: receives the
|
|
95
|
+
* `loadMap` thunk and decides when to call it.
|
|
96
|
+
*/
|
|
97
|
+
onMounted?: (loadMap: () => void) => void;
|
|
98
|
+
/**
|
|
99
|
+
* - Vue watch options for the component's sources watcher.
|
|
100
|
+
*/
|
|
101
|
+
watchSourcesOptions?: import('vue').WatchOptions;
|
|
102
|
+
/**
|
|
103
|
+
* - Vue watch options for the component's layers watcher.
|
|
104
|
+
*/
|
|
105
|
+
watchLayersOptions?: import('vue').WatchOptions;
|
|
106
|
+
};
|
|
107
|
+
export type MapboxMapOptions = Omit<import('mapbox-gl').MapOptions, 'container'> & MapboxMapExtraOptions;
|
|
108
|
+
/**
|
|
109
|
+
* A Mapbox REST SDK service name (the keys of `servicesLoader`).
|
|
110
|
+
* @typedef {NonNullable<import('../main.js').MapboxConfig['services']>[number]} MapboxServiceName
|
|
111
|
+
*/
|
|
112
|
+
/**
|
|
113
|
+
* Wrapper-specific options riding along the map constructor options.
|
|
114
|
+
* @typedef {object} MapboxMapExtraOptions
|
|
115
|
+
* @property {(loadMap: () => void) => void} [onMounted] - Take over map creation timing: receives the
|
|
116
|
+
* `loadMap` thunk and decides when to call it.
|
|
117
|
+
* @property {import('vue').WatchOptions} [watchSourcesOptions] - Vue watch options for the component's sources watcher.
|
|
118
|
+
* @property {import('vue').WatchOptions} [watchLayersOptions] - Vue watch options for the component's layers watcher.
|
|
119
|
+
*/
|
|
120
|
+
/**
|
|
121
|
+
* Options of the Mapbox `Map` component / `createMap`: mapbox-gl's `MapOptions` minus `container`
|
|
122
|
+
* (the component's element / `elemRef` provides it) — `accessToken` defaults to the config `apiKey` —
|
|
123
|
+
* plus the wrapper extras.
|
|
124
|
+
* @typedef {Omit<import('mapbox-gl').MapOptions, 'container'> & MapboxMapExtraOptions} MapboxMapOptions
|
|
125
|
+
*/
|
|
126
|
+
/** Mapbox provider (`type: 'mapbox'`): the `Map`/`DeckGLOverlay` components, `createMap` and the REST SDK. */
|
|
127
|
+
export default class Mapbox {
|
|
128
|
+
/** @type {string|undefined} The configured access token (undefined on the token-less Maplibre subclass, #154). */
|
|
129
|
+
apiKey: string | undefined;
|
|
130
|
+
/** @type {MapboxServiceName[]} The REST SDK services to (pre)load. */
|
|
131
|
+
services: MapboxServiceName[];
|
|
132
|
+
/** @type {Partial<Record<MapboxServiceName, object>>} The loaded REST service clients by name (plain objects: the mapbox SDK ships no types). */
|
|
133
|
+
sdk: Partial<Record<MapboxServiceName, object>>;
|
|
134
|
+
/** @type {typeof import('mapbox-gl/esm')|typeof import('maplibre-gl')|null} The lazily loaded gl namespace (maplibre-gl's on the Maplibre subclass). */
|
|
135
|
+
mapboxgl: typeof import('mapbox-gl/esm') | typeof import('maplibre-gl') | null;
|
|
136
|
+
/** @type {import('vue').Component|null} */
|
|
137
|
+
_MapComponent: import('vue').Component | null;
|
|
138
|
+
/** @type {import('vue').Component|null} */
|
|
139
|
+
_DeckGLOverlayComponent: import('vue').Component | null;
|
|
140
|
+
/** @type {Promise<object>} The SDK preload: resolves with the `sdk` registry, rejects like getSDK(). */
|
|
141
|
+
ready: Promise<object>;
|
|
142
|
+
/** Subclasses can opt out of the token requirement (#154): MapLibre works without any key.
|
|
143
|
+
* @returns {boolean} Whether the constructor requires an apiKey.
|
|
144
|
+
*/
|
|
145
|
+
get requiresApiKey(): boolean;
|
|
146
|
+
/** Build the provider from its `maps` config entry and kick off the SDK preload (#149).
|
|
147
|
+
* @param {import('../main.js').MapboxConfig|import('../main.js').MaplibreConfig} mapConfig - The
|
|
148
|
+
* `maps.<key>` config entry (the token-less MaplibreConfig on the Maplibre subclass, #154).
|
|
149
|
+
*/
|
|
150
|
+
constructor(mapConfig: import('../main.js').MapboxConfig | import('../main.js').MaplibreConfig);
|
|
151
|
+
/** The map Vue component: `:options` ({@link MapboxMapOptions}), `:layers` ({@link MapLayerDef}
|
|
152
|
+
* array), `:sources` ({@link MapSourceDef} array); emits `loaded` with the {@link MapboxMap}
|
|
153
|
+
* wrapper, and `error`.
|
|
154
|
+
* @returns {import('vue').Component} The memoized component definition (#139).
|
|
155
|
+
*/
|
|
156
|
+
get Map(): import('vue').Component;
|
|
157
|
+
/** The deck.gl overlay Vue component (nests inside `Map`): `:options`, `:layers`; emits `loaded`
|
|
158
|
+
* with the overlay wrapper, and `error`.
|
|
159
|
+
* @returns {import('vue').Component} The memoized component definition (#139).
|
|
160
|
+
*/
|
|
161
|
+
get DeckGLOverlay(): import('vue').Component;
|
|
162
|
+
/** Lazy-load the gl namespace (and its css) into `this.mapboxgl`, once.
|
|
163
|
+
* @returns {Promise<void>}
|
|
164
|
+
*/
|
|
165
|
+
loadMapbox(): Promise<void>;
|
|
166
|
+
/** The lazy REST SDK service loaders — one dynamic import per service, so only the requested
|
|
167
|
+
* services are fetched; its keys are the valid {@link MapboxServiceName}s.
|
|
168
|
+
* @returns {Record<MapboxServiceName, () => Promise<{ default: (client: object) => object }>>} Service
|
|
169
|
+
* name → loader of the service module, whose `default` builds the client-bound service.
|
|
170
|
+
*/
|
|
171
|
+
get servicesLoader(): Record<MapboxServiceName, () => Promise<{
|
|
172
|
+
default: (client: object) => object;
|
|
173
|
+
}>>;
|
|
174
|
+
/** Build the token-bound SDK client and load the wanted services into `this.sdk` (#150).
|
|
175
|
+
* @param {object} [options] - Options.
|
|
176
|
+
* @param {MapboxServiceName[]} [options.services] - Services to load on top of the configured ones.
|
|
177
|
+
* @returns {Promise<void>}
|
|
178
|
+
*/
|
|
179
|
+
loadMapboxSDK({ services }?: {
|
|
180
|
+
services?: MapboxServiceName[];
|
|
181
|
+
}): Promise<void>;
|
|
182
|
+
/** Load and return Mapbox REST SDK services (the config `services` plus the requested ones).
|
|
183
|
+
* @param {MapboxServiceName|{services?: MapboxServiceName[]}} [options] - A single service name, or
|
|
184
|
+
* `{ services }` to load several at once.
|
|
185
|
+
* @returns {Promise<object>} The named service client for a string argument, the whole `sdk`
|
|
186
|
+
* registry otherwise (plain objects: the mapbox SDK ships no types).
|
|
187
|
+
* @throws {Error} When a service name is unknown (#150) or its client is not loaded.
|
|
188
|
+
*/
|
|
189
|
+
getSDK(options?: MapboxServiceName | {
|
|
190
|
+
services?: MapboxServiceName[];
|
|
191
|
+
}): Promise<object>;
|
|
192
|
+
/** Map constructor options, overridable per subclass (maplibre-gl has no accessToken option, #154).
|
|
193
|
+
* @param {HTMLElement} container - The map container element.
|
|
194
|
+
* @param {MapboxMapOptions} options - Consumer-provided map options.
|
|
195
|
+
* @returns {import('mapbox-gl').MapOptions} The options passed to `new mapboxgl.Map()`.
|
|
196
|
+
*/
|
|
197
|
+
_getMapOptions(container: HTMLElement, options: MapboxMapOptions): import('mapbox-gl').MapOptions;
|
|
198
|
+
/** Create the map imperatively (must run in a component's setup(): the lifecycle hooks drive it):
|
|
199
|
+
* resolves the wrapper once the map emits 'load', rejects on ANY failure (#148/#228) — with
|
|
200
|
+
* `error.code === 'MAP_UNMOUNTED'` when the component unmounted first — and tears the map, its
|
|
201
|
+
* watchers and its overlays down on unmount.
|
|
202
|
+
* @template {HTMLElement|null|undefined} TEl
|
|
203
|
+
* @param {import('vue').Ref<TEl>} elemRef - Template ref to the map's container element.
|
|
204
|
+
* @param {MapboxMapOptions} [options] - Map constructor options plus the wrapper extras
|
|
205
|
+
* (maplibre-gl's own options on the Maplibre subclass).
|
|
206
|
+
* @returns {Promise<MapboxMap>} The map wrapper.
|
|
207
|
+
*/
|
|
208
|
+
createMap<TEl extends HTMLElement | null | undefined>(elemRef: import('vue').Ref<TEl>, options?: MapboxMapOptions): Promise<MapboxMap>;
|
|
209
|
+
}
|
|
210
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import Mapbox from './Mapbox.js';
|
|
2
|
+
export type MaplibreMapOptions = Omit<import('maplibre-gl').MapOptions, 'container'> & import('./Mapbox.js').MapboxMapExtraOptions;
|
|
3
|
+
/**
|
|
4
|
+
* Options of the Maplibre `Map` component / `createMap`: maplibre-gl's `MapOptions` minus `container`
|
|
5
|
+
* (the component's element / `elemRef` provides it), plus the wrapper extras shared with Mapbox.
|
|
6
|
+
* @typedef {Omit<import('maplibre-gl').MapOptions, 'container'> & import('./Mapbox.js').MapboxMapExtraOptions} MaplibreMapOptions
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Maplibre provider (`type: 'maplibre'`/`'maplibre-gl'`): the token-less mapbox-gl fork — same
|
|
10
|
+
* Map/DeckGLOverlay/createMap surface as Mapbox, minus the REST SDK (#154).
|
|
11
|
+
*/
|
|
12
|
+
export default class Maplibre extends Mapbox {
|
|
13
|
+
/** MapLibre is the token-less mapbox-gl fork (#154).
|
|
14
|
+
* @returns {boolean} Always false: no apiKey needed.
|
|
15
|
+
*/
|
|
16
|
+
get requiresApiKey(): boolean;
|
|
17
|
+
/** Lazy-load the maplibre-gl namespace (and its css) into `this.mapboxgl`, once, pinning its web
|
|
18
|
+
* worker — the whole story below.
|
|
19
|
+
* @returns {Promise<void>}
|
|
20
|
+
*/
|
|
21
|
+
loadMapbox(): Promise<void>;
|
|
22
|
+
/** No Mapbox REST SDK on maplibre (#154): the constructor preload resolves to an empty sdk,
|
|
23
|
+
* and requesting a service (argument or configured `services`) is a consumer error.
|
|
24
|
+
* @param {string|{services?: string[]}} [options] - Service name or `{ services }` object, like Mapbox's getSDK.
|
|
25
|
+
* @returns {Promise<object>} The (empty) sdk registry.
|
|
26
|
+
* @throws {Error} When a service is requested.
|
|
27
|
+
*/
|
|
28
|
+
getSDK(options?: string | {
|
|
29
|
+
services?: string[];
|
|
30
|
+
}): Promise<object>;
|
|
31
|
+
/** maplibre-gl has no accessToken option (#154): container + consumer options only.
|
|
32
|
+
* @param {HTMLElement} container - The map container element.
|
|
33
|
+
* @param {MaplibreMapOptions} options - Consumer-provided map options.
|
|
34
|
+
* @returns {import('maplibre-gl').MapOptions} The options passed to `new maplibregl.Map()`.
|
|
35
|
+
*/
|
|
36
|
+
_getMapOptions(container: HTMLElement, options: MaplibreMapOptions): import('maplibre-gl').MapOptions;
|
|
37
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export type SeaRouteFeature = {
|
|
2
|
+
/**
|
|
3
|
+
* - GeoJSON object type.
|
|
4
|
+
*/
|
|
5
|
+
type: 'Feature';
|
|
6
|
+
/**
|
|
7
|
+
* - The `[lng, lat]` network
|
|
8
|
+
* path, from origin's snap to destination's snap.
|
|
9
|
+
*/
|
|
10
|
+
geometry: {
|
|
11
|
+
type: 'LineString';
|
|
12
|
+
coordinates: number[][];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* - The route
|
|
16
|
+
* length, expressed in `units`.
|
|
17
|
+
*/
|
|
18
|
+
properties: {
|
|
19
|
+
units: 'nm' | import('@turf/turf').Units;
|
|
20
|
+
length: number;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The returned route: the GeoJSON LineString Feature built by turf's lineString() over the snapped
|
|
25
|
+
* network path, with the measured length stamped on `properties` (#138, same contract as the air
|
|
26
|
+
* twin, #257).
|
|
27
|
+
* @typedef {object} SeaRouteFeature
|
|
28
|
+
* @property {'Feature'} type - GeoJSON object type.
|
|
29
|
+
* @property {{type: 'LineString', coordinates: number[][]}} geometry - The `[lng, lat]` network
|
|
30
|
+
* path, from origin's snap to destination's snap.
|
|
31
|
+
* @property {{units: 'nm'|import('@turf/turf').Units, length: number}} properties - The route
|
|
32
|
+
* length, expressed in `units`.
|
|
33
|
+
*/
|
|
34
|
+
/**
|
|
35
|
+
* Shortest sea route between two points, each snapped to the Marnet network first, via
|
|
36
|
+
* geojson-path-finder (weight() bridges the anti-meridian edges).
|
|
37
|
+
* @param {import('@turf/turf').Coord} origin - Start point: a turf point() Feature, a bare Point
|
|
38
|
+
* geometry, or a `[lng, lat]` position.
|
|
39
|
+
* @param {import('@turf/turf').Coord} destination - End point, same accepted shapes.
|
|
40
|
+
* @param {'nm'|import('@turf/turf').Units} [units='nm'] - Unit of `properties.length`; 'nm' is the
|
|
41
|
+
* module's alias for turf's 'nauticalmiles' (#138).
|
|
42
|
+
* @returns {SeaRouteFeature|null} The snapped route — null when no path exists (reachable on valid
|
|
43
|
+
* inputs, the network is fragmented, #141).
|
|
44
|
+
*/
|
|
45
|
+
export default function searoute(origin: import('@turf/turf').Coord, destination: import('@turf/turf').Coord, units?: 'nm' | import('@turf/turf').Units): SeaRouteFeature | null;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export type AirRouteOptions = {
|
|
2
|
+
/**
|
|
3
|
+
* - Start position, `[lng, lat]`.
|
|
4
|
+
*/
|
|
5
|
+
origin: number[];
|
|
6
|
+
/**
|
|
7
|
+
* - End position, `[lng, lat]`.
|
|
8
|
+
*/
|
|
9
|
+
destination: number[];
|
|
10
|
+
/**
|
|
11
|
+
* - Number of arc segments (the geometry holds `step` interpolated
|
|
12
|
+
* positions plus the destination, before dedupe); a non-integer or non-positive value falls back
|
|
13
|
+
* to 100 (#157).
|
|
14
|
+
*/
|
|
15
|
+
step?: number;
|
|
16
|
+
/**
|
|
17
|
+
* - Unit of `properties.length`; 'nm' is
|
|
18
|
+
* the module's alias for turf's 'nauticalmiles' (#138).
|
|
19
|
+
*/
|
|
20
|
+
units?: 'nm' | import('@turf/turf').Units;
|
|
21
|
+
};
|
|
22
|
+
export type AirRouteFeature = {
|
|
23
|
+
/**
|
|
24
|
+
* - GeoJSON object type.
|
|
25
|
+
*/
|
|
26
|
+
type: 'Feature';
|
|
27
|
+
/**
|
|
28
|
+
* - The arc's `[lng, lat]`
|
|
29
|
+
* positions; longitudes are unfolded by normalizeRoute and may run past ±180 (#159).
|
|
30
|
+
*/
|
|
31
|
+
geometry: {
|
|
32
|
+
type: 'LineString';
|
|
33
|
+
coordinates: number[][];
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* - The route
|
|
37
|
+
* length, expressed in `units`.
|
|
38
|
+
*/
|
|
39
|
+
properties: {
|
|
40
|
+
units: 'nm' | import('@turf/turf').Units;
|
|
41
|
+
length: number;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Arguments of getAirRoute.
|
|
46
|
+
* @typedef {object} AirRouteOptions
|
|
47
|
+
* @property {number[]} origin - Start position, `[lng, lat]`.
|
|
48
|
+
* @property {number[]} destination - End position, `[lng, lat]`.
|
|
49
|
+
* @property {number} [step=100] - Number of arc segments (the geometry holds `step` interpolated
|
|
50
|
+
* positions plus the destination, before dedupe); a non-integer or non-positive value falls back
|
|
51
|
+
* to 100 (#157).
|
|
52
|
+
* @property {'nm'|import('@turf/turf').Units} [units='nm'] - Unit of `properties.length`; 'nm' is
|
|
53
|
+
* the module's alias for turf's 'nauticalmiles' (#138).
|
|
54
|
+
*/
|
|
55
|
+
/**
|
|
56
|
+
* The returned route: the GeoJSON LineString Feature built by turf's lineString(), with the
|
|
57
|
+
* measured length stamped on `properties` (#257).
|
|
58
|
+
* @typedef {object} AirRouteFeature
|
|
59
|
+
* @property {'Feature'} type - GeoJSON object type.
|
|
60
|
+
* @property {{type: 'LineString', coordinates: number[][]}} geometry - The arc's `[lng, lat]`
|
|
61
|
+
* positions; longitudes are unfolded by normalizeRoute and may run past ±180 (#159).
|
|
62
|
+
* @property {{units: 'nm'|import('@turf/turf').Units, length: number}} properties - The route
|
|
63
|
+
* length, expressed in `units`.
|
|
64
|
+
*/
|
|
65
|
+
/**
|
|
66
|
+
* Great-circle ("air") route between origin and destination: a geodesic arc interpolated with
|
|
67
|
+
* turf's along(), then unfolded across the anti-meridian and measured on the final geometry.
|
|
68
|
+
* @param {AirRouteOptions} options - Route endpoints and arc options.
|
|
69
|
+
* @returns {AirRouteFeature} The arc as a GeoJSON LineString Feature.
|
|
70
|
+
*/
|
|
71
|
+
export default function getAirRoute({ origin, destination, step, units }: AirRouteOptions): AirRouteFeature;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export type WaterRouteOptions = {
|
|
2
|
+
/**
|
|
3
|
+
* - Start position, `[lng, lat]`.
|
|
4
|
+
*/
|
|
5
|
+
origin: number[];
|
|
6
|
+
/**
|
|
7
|
+
* - End position, `[lng, lat]`.
|
|
8
|
+
*/
|
|
9
|
+
destination: number[];
|
|
10
|
+
/**
|
|
11
|
+
* - Prepend/append the REAL origin/destination to the
|
|
12
|
+
* snapped network path (boundary legs), and recompute `properties.length` over the extended
|
|
13
|
+
* geometry (#159).
|
|
14
|
+
*/
|
|
15
|
+
includeBoundaries?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* - Unit of `properties.length`; 'nm' is
|
|
18
|
+
* the module's alias for turf's 'nauticalmiles' (#138).
|
|
19
|
+
*/
|
|
20
|
+
units?: 'nm' | import('@turf/turf').Units;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Arguments of getWaterRoute.
|
|
24
|
+
* @typedef {object} WaterRouteOptions
|
|
25
|
+
* @property {number[]} origin - Start position, `[lng, lat]`.
|
|
26
|
+
* @property {number[]} destination - End position, `[lng, lat]`.
|
|
27
|
+
* @property {boolean} [includeBoundaries=false] - Prepend/append the REAL origin/destination to the
|
|
28
|
+
* snapped network path (boundary legs), and recompute `properties.length` over the extended
|
|
29
|
+
* geometry (#159).
|
|
30
|
+
* @property {'nm'|import('@turf/turf').Units} [units='nm'] - Unit of `properties.length`; 'nm' is
|
|
31
|
+
* the module's alias for turf's 'nauticalmiles' (#138).
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* Sea ("water") route between origin and destination over the Marnet network, computed by the
|
|
35
|
+
* dynamically-imported searoute engine, then unfolded across the anti-meridian.
|
|
36
|
+
* @param {WaterRouteOptions} options - Route endpoints and options.
|
|
37
|
+
* @returns {Promise<import('../searoute/searoute.js').SeaRouteFeature|null>} The route as a GeoJSON
|
|
38
|
+
* LineString Feature (`properties.units`/`length` set) — null when no path exists (#141).
|
|
39
|
+
*/
|
|
40
|
+
export default function getWaterRoute({ origin, destination, includeBoundaries, units }: WaterRouteOptions): Promise<import('../searoute/searoute.js').SeaRouteFeature | null>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unfold a route's longitudes across anti-meridian crossings: whenever two consecutive longitudes
|
|
3
|
+
* jump by more than 180°, shift by ±360 so the line never wraps — the unfolded longitudes may run
|
|
4
|
+
* past ±180 (turf's haversine handles them, #159). Drops any altitude member on the way.
|
|
5
|
+
* @param {number[][]} coords - The route positions, `[lng, lat]` first.
|
|
6
|
+
* @returns {Array<[number, number]>} The unfolded `[lng, lat]` pairs, consecutive duplicates removed.
|
|
7
|
+
*/
|
|
8
|
+
export default function normalizeRoute(coords: number[][]): Array<[number, number]>;
|