@duoquote/polytini 0.1.0 → 0.1.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/LICENSE +21 -21
- package/README.md +120 -120
- package/dist/types/cli.d.cts +2 -2
- package/dist/types/deckgl.d.cts +72 -60
- package/dist/types/flexible.d.cts +92 -80
- package/dist/types/geojson.jsr.d.cts +111 -0
- package/dist/types/google.d.cts +48 -48
- package/dist/types/google.jsr.d.cts +72 -60
- package/dist/types/index.d.cts +109 -87
- package/dist/types/leaflet-auto.d.cts +4 -4
- package/dist/types/leaflet-auto.jsr.d.cts +2 -2
- package/dist/types/leaflet.d.cts +39 -39
- package/dist/types/leaflet.jsr.d.cts +15 -13
- package/dist/types/mapbox.d.cts +50 -50
- package/dist/types/mapbox.jsr.d.cts +5 -0
- package/dist/types/maplibre.d.cts +54 -54
- package/dist/types/maplibre.jsr.d.cts +92 -0
- package/dist/types/openlayers.d.cts +23 -23
- package/dist/types/openlayers.jsr.d.cts +42 -0
- package/dist/types/presets.d.cts +70 -66
- package/dist/types/turf.d.cts +33 -33
- package/dist/types/turf.jsr.d.cts +46 -0
- package/dist/types/wasm.d.cts +42 -33
- package/package.json +200 -200
- package/src/browser.js +15 -15
- package/src/bun.js +4 -4
- package/src/cli-lib.js +160 -160
- package/src/cli.js +7 -7
- package/src/core.js +268 -268
- package/src/deckgl.js +176 -176
- package/src/deno.js +12 -12
- package/src/error.js +15 -15
- package/src/fast.js +179 -179
- package/src/flexible.js +283 -283
- package/src/google.js +70 -70
- package/src/leaflet-auto.js +11 -11
- package/src/leaflet.js +44 -44
- package/src/mapbox.js +10 -10
- package/src/maplibre.js +57 -57
- package/src/node.js +17 -17
- package/src/openlayers.js +172 -172
- package/src/presets.js +242 -242
- package/src/text.js +111 -111
- package/src/turf.js +80 -80
- package/src/wasm-bytes.js +2 -2
- package/src/wasm.js +235 -235
- package/src/web.js +9 -9
- package/types/cli.d.ts +2 -2
- package/types/deckgl.d.ts +72 -60
- package/types/flexible.d.ts +92 -80
- package/types/geojson.jsr.d.ts +111 -0
- package/types/google.d.ts +48 -48
- package/types/google.jsr.d.ts +72 -60
- package/types/index.d.ts +109 -87
- package/types/leaflet-auto.d.ts +4 -4
- package/types/leaflet-auto.jsr.d.ts +2 -2
- package/types/leaflet.d.ts +39 -39
- package/types/leaflet.jsr.d.ts +15 -13
- package/types/mapbox.d.ts +50 -50
- package/types/mapbox.jsr.d.ts +5 -0
- package/types/maplibre.d.ts +54 -54
- package/types/maplibre.jsr.d.ts +92 -0
- package/types/openlayers.d.ts +23 -23
- package/types/openlayers.jsr.d.ts +42 -0
- package/types/presets.d.ts +70 -66
- package/types/turf.d.ts +33 -33
- package/types/turf.jsr.d.ts +46 -0
- package/types/wasm.d.ts +42 -33
package/types/index.d.ts
CHANGED
|
@@ -1,87 +1,109 @@
|
|
|
1
|
-
// Types for every Google-format entry point of @duoquote/polytini: the
|
|
2
|
-
// default (web), node, bun, deno and wasm entries share this API.
|
|
3
|
-
|
|
4
|
-
/** A point as [lat, lng], or [lng, lat] with `order: 'lnglat'`. More values with `dimensions`. */
|
|
5
|
-
export type Point = [number, number, ...number[]];
|
|
6
|
-
|
|
7
|
-
/** Objects encode reads by name: lat or latitude, lng, lon or longitude, alt or altitude. */
|
|
8
|
-
export interface LatLngLike {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
|
|
1
|
+
// Types for every Google-format entry point of @duoquote/polytini: the
|
|
2
|
+
// default (web), node, bun, deno and wasm entries share this API.
|
|
3
|
+
|
|
4
|
+
/** A point as [lat, lng], or [lng, lat] with `order: 'lnglat'`. More values with `dimensions`. */
|
|
5
|
+
export type Point = [number, number, ...number[]];
|
|
6
|
+
|
|
7
|
+
/** Objects encode reads by name: lat or latitude, lng, lon or longitude, alt or altitude. */
|
|
8
|
+
export interface LatLngLike {
|
|
9
|
+
/** Latitude. */
|
|
10
|
+
lat?: number;
|
|
11
|
+
/** Latitude, the long name. */
|
|
12
|
+
latitude?: number;
|
|
13
|
+
/** Longitude. */
|
|
14
|
+
lng?: number;
|
|
15
|
+
/** Longitude, another short name. */
|
|
16
|
+
lon?: number;
|
|
17
|
+
/** Longitude, the long name. */
|
|
18
|
+
longitude?: number;
|
|
19
|
+
/** Altitude, the third value with `dimensions: 3`. */
|
|
20
|
+
alt?: number;
|
|
21
|
+
/** Altitude, the long name. */
|
|
22
|
+
altitude?: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Options for every encode and decode function. */
|
|
26
|
+
export interface Options {
|
|
27
|
+
/** Decimal places, an integer from 0 to 15. Default 5. Google uses 5, OSRM's polyline6 and Valhalla 6. */
|
|
28
|
+
precision?: number;
|
|
29
|
+
/** Multiply by this instead of 10 ** precision. */
|
|
30
|
+
factor?: number;
|
|
31
|
+
/**
|
|
32
|
+
* The order of the tuples you pass in and get back. The encoded string
|
|
33
|
+
* always stores latitude first. Default 'latlng'; GeoJSON uses 'lnglat'.
|
|
34
|
+
*/
|
|
35
|
+
order?: 'latlng' | 'lnglat';
|
|
36
|
+
/**
|
|
37
|
+
* Throw a PolylineError on malformed input. Default true. With false,
|
|
38
|
+
* decode skips invalid characters and drops an incomplete last point, and
|
|
39
|
+
* encode treats missing or non-finite coordinates as 0.
|
|
40
|
+
*/
|
|
41
|
+
strict?: boolean;
|
|
42
|
+
/** Values per point, 1 to 16. Default 2. The third can be elevation, like GraphHopper's. */
|
|
43
|
+
dimensions?: number;
|
|
44
|
+
/** Factor for the third and later values. Defaults to the main factor. */
|
|
45
|
+
zFactor?: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Options, or just the precision. */
|
|
49
|
+
export type OptionsArg = number | Options;
|
|
50
|
+
|
|
51
|
+
/** PolylineError codes: a bad character, a cut-off string, a value past 2^53, a bad coordinate, input that isn't a string or array, a bad option, or /wasm used before init(). */
|
|
52
|
+
export type ErrorCode = 'char' | 'truncated' | 'overflow' | 'coordinate' | 'input' | 'option' | 'init';
|
|
53
|
+
|
|
54
|
+
/** What strict mode throws, with a code and, where it makes sense, an index. */
|
|
55
|
+
export class PolylineError extends Error {
|
|
56
|
+
/** Always "PolylineError". */
|
|
57
|
+
readonly name: 'PolylineError';
|
|
58
|
+
/** What went wrong. */
|
|
59
|
+
readonly code: ErrorCode;
|
|
60
|
+
/** Character index (decode) or point index (encode), when there is one. */
|
|
61
|
+
readonly index: number | undefined;
|
|
62
|
+
/** Makes an error; the message gets " at <index>" appended when there's an index. */
|
|
63
|
+
constructor(code: ErrorCode, message: string, index?: number);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** A GeoJSON LineString, [lng, lat] positions. */
|
|
67
|
+
export interface LineString {
|
|
68
|
+
/** Always "LineString". */
|
|
69
|
+
type: 'LineString';
|
|
70
|
+
/** The positions. */
|
|
71
|
+
coordinates: number[][];
|
|
72
|
+
/** Optional bounding box. */
|
|
73
|
+
bbox?: number[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** A GeoJSON Feature with a LineString geometry. */
|
|
77
|
+
export interface LineStringFeature {
|
|
78
|
+
/** Always "Feature". */
|
|
79
|
+
type: 'Feature';
|
|
80
|
+
/** The line. */
|
|
81
|
+
geometry: LineString;
|
|
82
|
+
/** The feature's properties. */
|
|
83
|
+
properties: Record<string, unknown> | null;
|
|
84
|
+
/** Optional id. */
|
|
85
|
+
id?: string | number;
|
|
86
|
+
/** Optional bounding box. */
|
|
87
|
+
bbox?: number[];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Encodes points: tuples (or any array-like) or lat/lng objects. */
|
|
91
|
+
export function encode(points: ArrayLike<ArrayLike<number> | LatLngLike>, options?: OptionsArg): string;
|
|
92
|
+
|
|
93
|
+
/** Decodes to tuples, [lat, lng] by default. */
|
|
94
|
+
export function decode(str: string, options?: OptionsArg): Point[];
|
|
95
|
+
|
|
96
|
+
/** Encodes a flat array of numbers: [lat0, lng0, lat1, lng1, ...] (or lng first with order 'lnglat'). */
|
|
97
|
+
export function encodeFlat(values: ArrayLike<number>, options?: OptionsArg): string;
|
|
98
|
+
|
|
99
|
+
/** Decodes to one flat Float64Array, without an array per point. */
|
|
100
|
+
export function decodeFlat(str: string, options?: OptionsArg): Float64Array;
|
|
101
|
+
|
|
102
|
+
/** Decodes to {lat, lng} objects, the shape Google Maps and Leaflet take. */
|
|
103
|
+
export function decodeLatLng(str: string, options?: OptionsArg): { lat: number; lng: number }[];
|
|
104
|
+
|
|
105
|
+
/** Decodes to a GeoJSON LineString, [lng, lat] order. */
|
|
106
|
+
export function toGeoJSON(str: string, options?: OptionsArg): LineString;
|
|
107
|
+
|
|
108
|
+
/** Encodes a GeoJSON LineString, or a Feature with one. */
|
|
109
|
+
export function fromGeoJSON(geojson: LineString | LineStringFeature, options?: OptionsArg): string;
|
package/types/leaflet-auto.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Side-effect import that patches the global L. The added methods are
|
|
2
|
-
// typed in leaflet.d.ts.
|
|
3
|
-
/// <reference path="./leaflet.d.ts" />
|
|
4
|
-
export {};
|
|
1
|
+
// Side-effect import that patches the global L. The added methods are
|
|
2
|
+
// typed in leaflet.d.ts.
|
|
3
|
+
/// <reference path="./leaflet.d.ts" />
|
|
4
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// Side-effect import that patches the global L (JSR version, see leaflet.jsr.d.ts).
|
|
2
|
-
export {};
|
|
1
|
+
// Side-effect import that patches the global L (JSR version, see leaflet.jsr.d.ts).
|
|
2
|
+
export {};
|
package/types/leaflet.d.ts
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
// Types for @duoquote/polytini/leaflet. Leaflet's own types come from
|
|
2
|
-
// @types/leaflet (1.9) or leaflet's bundled types (2.x); this only adds the
|
|
3
|
-
// plugin's methods.
|
|
4
|
-
import type * as P from './index.d.ts';
|
|
5
|
-
import type { OptionsArg } from './index.d.ts';
|
|
6
|
-
import type { Polyline as LeafletPolyline, Polygon as LeafletPolygon } from 'leaflet';
|
|
7
|
-
|
|
8
|
-
/** One encoded line or ring, or nested arrays of them (multi-polylines, holes, multi-polygons). */
|
|
9
|
-
export type Encoded = string | Encoded[];
|
|
10
|
-
|
|
11
|
-
/** Leaflet path options plus polytini's precision, factor, strict and dimensions. */
|
|
12
|
-
export type EncodedOptions = Record<string, unknown> & Exclude<OptionsArg, number>;
|
|
13
|
-
|
|
14
|
-
/** Adds fromEncoded, toEncoded, encodePath and the polylineEncoded/polygonEncoded factories. Returns L. */
|
|
15
|
-
export function install<T>(L: T): T;
|
|
16
|
-
|
|
17
|
-
export declare const encode: typeof P.encode;
|
|
18
|
-
export declare const decode: typeof P.decode;
|
|
19
|
-
|
|
20
|
-
declare module 'leaflet' {
|
|
21
|
-
namespace Polyline {
|
|
22
|
-
/** A polyline from an encoded string, or a multi-polyline from an array of strings. */
|
|
23
|
-
// Generic with a default so Polygon's static side still extends Polyline's.
|
|
24
|
-
function fromEncoded<T = LeafletPolyline>(encoded: Encoded, options?: EncodedOptions): T;
|
|
25
|
-
}
|
|
26
|
-
namespace Polygon {
|
|
27
|
-
/** A polygon from one string, rings (outer, then holes) from string[], a multi-polygon from string[][]. */
|
|
28
|
-
function fromEncoded<T = LeafletPolygon>(encoded: Encoded, options?: EncodedOptions): T;
|
|
29
|
-
}
|
|
30
|
-
interface Polyline {
|
|
31
|
-
/** A string for a simple line, string[] for a multi-polyline. Polygons give string[] (rings) or string[][]. */
|
|
32
|
-
toEncoded(options?: OptionsArg): Encoded;
|
|
33
|
-
/** Alias of toEncoded, the Polyline.encoded.js name. */
|
|
34
|
-
encodePath(options?: OptionsArg): Encoded;
|
|
35
|
-
}
|
|
36
|
-
function polylineEncoded(encoded: Encoded, options?: EncodedOptions): LeafletPolyline;
|
|
37
|
-
function polygonEncoded(encoded: Encoded, options?: EncodedOptions): LeafletPolygon;
|
|
38
|
-
const PolylineUtil: { encode: typeof P.encode; decode: typeof P.decode };
|
|
39
|
-
}
|
|
1
|
+
// Types for @duoquote/polytini/leaflet. Leaflet's own types come from
|
|
2
|
+
// @types/leaflet (1.9) or leaflet's bundled types (2.x); this only adds the
|
|
3
|
+
// plugin's methods.
|
|
4
|
+
import type * as P from './index.d.ts';
|
|
5
|
+
import type { OptionsArg } from './index.d.ts';
|
|
6
|
+
import type { Polyline as LeafletPolyline, Polygon as LeafletPolygon } from 'leaflet';
|
|
7
|
+
|
|
8
|
+
/** One encoded line or ring, or nested arrays of them (multi-polylines, holes, multi-polygons). */
|
|
9
|
+
export type Encoded = string | Encoded[];
|
|
10
|
+
|
|
11
|
+
/** Leaflet path options plus polytini's precision, factor, strict and dimensions. */
|
|
12
|
+
export type EncodedOptions = Record<string, unknown> & Exclude<OptionsArg, number>;
|
|
13
|
+
|
|
14
|
+
/** Adds fromEncoded, toEncoded, encodePath and the polylineEncoded/polygonEncoded factories. Returns L. */
|
|
15
|
+
export function install<T>(L: T): T;
|
|
16
|
+
|
|
17
|
+
export declare const encode: typeof P.encode;
|
|
18
|
+
export declare const decode: typeof P.decode;
|
|
19
|
+
|
|
20
|
+
declare module 'leaflet' {
|
|
21
|
+
namespace Polyline {
|
|
22
|
+
/** A polyline from an encoded string, or a multi-polyline from an array of strings. */
|
|
23
|
+
// Generic with a default so Polygon's static side still extends Polyline's.
|
|
24
|
+
function fromEncoded<T = LeafletPolyline>(encoded: Encoded, options?: EncodedOptions): T;
|
|
25
|
+
}
|
|
26
|
+
namespace Polygon {
|
|
27
|
+
/** A polygon from one string, rings (outer, then holes) from string[], a multi-polygon from string[][]. */
|
|
28
|
+
function fromEncoded<T = LeafletPolygon>(encoded: Encoded, options?: EncodedOptions): T;
|
|
29
|
+
}
|
|
30
|
+
interface Polyline {
|
|
31
|
+
/** A string for a simple line, string[] for a multi-polyline. Polygons give string[] (rings) or string[][]. */
|
|
32
|
+
toEncoded(options?: OptionsArg): Encoded;
|
|
33
|
+
/** Alias of toEncoded, the Polyline.encoded.js name. */
|
|
34
|
+
encodePath(options?: OptionsArg): Encoded;
|
|
35
|
+
}
|
|
36
|
+
function polylineEncoded(encoded: Encoded, options?: EncodedOptions): LeafletPolyline;
|
|
37
|
+
function polygonEncoded(encoded: Encoded, options?: EncodedOptions): LeafletPolygon;
|
|
38
|
+
const PolylineUtil: { encode: typeof P.encode; decode: typeof P.decode };
|
|
39
|
+
}
|
package/types/leaflet.jsr.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
// Types for @duoquote/polytini/leaflet on JSR. JSR doesn't allow module
|
|
2
|
-
// augmentation, so this has the plugin's own exports but not the methods it
|
|
3
|
-
// adds to Leaflet's classes. The npm package's leaflet.d.ts has those.
|
|
4
|
-
import type * as P from './index.d.ts';
|
|
5
|
-
|
|
6
|
-
/** One encoded line or ring, or nested arrays of them (multi-polylines, holes, multi-polygons). */
|
|
7
|
-
export type Encoded = string | Encoded[];
|
|
8
|
-
|
|
9
|
-
/** Adds fromEncoded, toEncoded, encodePath and the polylineEncoded/polygonEncoded factories. Returns L. */
|
|
10
|
-
export function install<T>(L: T): T;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export declare const
|
|
1
|
+
// Types for @duoquote/polytini/leaflet on JSR. JSR doesn't allow module
|
|
2
|
+
// augmentation, so this has the plugin's own exports but not the methods it
|
|
3
|
+
// adds to Leaflet's classes. The npm package's leaflet.d.ts has those.
|
|
4
|
+
import type * as P from './index.d.ts';
|
|
5
|
+
|
|
6
|
+
/** One encoded line or ring, or nested arrays of them (multi-polylines, holes, multi-polygons). */
|
|
7
|
+
export type Encoded = string | Encoded[];
|
|
8
|
+
|
|
9
|
+
/** Adds fromEncoded, toEncoded, encodePath and the polylineEncoded/polygonEncoded factories. Returns L. */
|
|
10
|
+
export function install<T>(L: T): T;
|
|
11
|
+
|
|
12
|
+
/** The main entry's encode. */
|
|
13
|
+
export declare const encode: typeof P.encode;
|
|
14
|
+
/** The main entry's decode. */
|
|
15
|
+
export declare const decode: typeof P.decode;
|
package/types/mapbox.d.ts
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
// Types for @duoquote/polytini/mapbox: the same functions as the maplibre
|
|
2
|
-
// module, typed with mapbox-gl's own types (type-only imports). mapbox-gl's
|
|
3
|
-
// types use the GeoJSON namespace from @types/geojson.
|
|
4
|
-
import type { Map, GeoJSONSource, GeoJSONSourceSpecification, LineLayerSpecification } from 'mapbox-gl';
|
|
5
|
-
import type { FeatureCollection, LineString, GeoJsonProperties } from 'geojson';
|
|
6
|
-
import type { Options } from './index.d.ts';
|
|
7
|
-
|
|
8
|
-
export type { GeoJSONSourceSpecification, LineLayerSpecification };
|
|
9
|
-
|
|
10
|
-
// Repeated from maplibre.d.ts so this file does not need maplibre-gl installed.
|
|
11
|
-
export type FeatureId = string | number;
|
|
12
|
-
|
|
13
|
-
export interface DataOptions<P = GeoJsonProperties> extends Options {
|
|
14
|
-
/** Properties for every line, or an array with one object per line. Default {}. */
|
|
15
|
-
properties?: P | P[];
|
|
16
|
-
/** Feature id for every line, or an array with one per line. Feature state needs numeric ids or promoteId. */
|
|
17
|
-
id?: FeatureId | FeatureId[];
|
|
18
|
-
/** Add a [west, south, east, north] bbox to each feature. Default false. */
|
|
19
|
-
bbox?: boolean;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface SourceOptions<P = GeoJsonProperties> extends DataOptions<P> {
|
|
23
|
-
/** Other source options: lineMetrics, tolerance, promoteId, generateId, attribution, and so on. */
|
|
24
|
-
source?: Partial<Omit<GeoJSONSourceSpecification, 'type' | 'data'>>;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface LayerOptions<P = GeoJsonProperties> extends SourceOptions<P> {
|
|
28
|
-
/** Merged into the line layer: paint, layout, filter, slot, minzoom, maxzoom, or another id. */
|
|
29
|
-
layer?: Partial<Omit<LineLayerSpecification, 'type' | 'source'>>;
|
|
30
|
-
/** The id of an existing layer to insert the new layer before. */
|
|
31
|
-
beforeId?: string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** A GeoJSON source specification whose data is a FeatureCollection of LineStrings. */
|
|
35
|
-
export type PolylineSource<P = GeoJsonProperties> = GeoJSONSourceSpecification & {
|
|
36
|
-
type: 'geojson';
|
|
37
|
-
data: FeatureCollection<LineString, P>;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
/** A FeatureCollection<LineString> ([lng, lat]) with one Feature per encoded string. */
|
|
41
|
-
export function polylineData<P = GeoJsonProperties>(encoded: string | string[], options?: number | DataOptions<P>): FeatureCollection<LineString, P>;
|
|
42
|
-
|
|
43
|
-
/** `{ type: 'geojson', data }` for map.addSource or a style's sources. */
|
|
44
|
-
export function polylineSource<P = GeoJsonProperties>(encoded: string | string[], options?: number | SourceOptions<P>): PolylineSource<P>;
|
|
45
|
-
|
|
46
|
-
/** Adds a GeoJSON source and a line layer, both named `id`. Returns the map. */
|
|
47
|
-
export function addPolylineLayer<M extends Map, P = GeoJsonProperties>(map: M, id: string, encoded: string | string[], options?: number | LayerOptions<P>): M;
|
|
48
|
-
|
|
49
|
-
/** Replaces the data of the GeoJSON source `id`. Returns what setData returns (the source). Throws a PolylineError if there is no such GeoJSON source. */
|
|
50
|
-
export function setPolylineData<P = GeoJsonProperties>(map: Map, id: string, encoded: string | string[], options?: number | DataOptions<P>): ReturnType<GeoJSONSource['setData']>;
|
|
1
|
+
// Types for @duoquote/polytini/mapbox: the same functions as the maplibre
|
|
2
|
+
// module, typed with mapbox-gl's own types (type-only imports). mapbox-gl's
|
|
3
|
+
// types use the GeoJSON namespace from @types/geojson.
|
|
4
|
+
import type { Map, GeoJSONSource, GeoJSONSourceSpecification, LineLayerSpecification } from 'mapbox-gl';
|
|
5
|
+
import type { FeatureCollection, LineString, GeoJsonProperties } from 'geojson';
|
|
6
|
+
import type { Options } from './index.d.ts';
|
|
7
|
+
|
|
8
|
+
export type { GeoJSONSourceSpecification, LineLayerSpecification };
|
|
9
|
+
|
|
10
|
+
// Repeated from maplibre.d.ts so this file does not need maplibre-gl installed.
|
|
11
|
+
export type FeatureId = string | number;
|
|
12
|
+
|
|
13
|
+
export interface DataOptions<P = GeoJsonProperties> extends Options {
|
|
14
|
+
/** Properties for every line, or an array with one object per line. Default {}. */
|
|
15
|
+
properties?: P | P[];
|
|
16
|
+
/** Feature id for every line, or an array with one per line. Feature state needs numeric ids or promoteId. */
|
|
17
|
+
id?: FeatureId | FeatureId[];
|
|
18
|
+
/** Add a [west, south, east, north] bbox to each feature. Default false. */
|
|
19
|
+
bbox?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface SourceOptions<P = GeoJsonProperties> extends DataOptions<P> {
|
|
23
|
+
/** Other source options: lineMetrics, tolerance, promoteId, generateId, attribution, and so on. */
|
|
24
|
+
source?: Partial<Omit<GeoJSONSourceSpecification, 'type' | 'data'>>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface LayerOptions<P = GeoJsonProperties> extends SourceOptions<P> {
|
|
28
|
+
/** Merged into the line layer: paint, layout, filter, slot, minzoom, maxzoom, or another id. */
|
|
29
|
+
layer?: Partial<Omit<LineLayerSpecification, 'type' | 'source'>>;
|
|
30
|
+
/** The id of an existing layer to insert the new layer before. */
|
|
31
|
+
beforeId?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** A GeoJSON source specification whose data is a FeatureCollection of LineStrings. */
|
|
35
|
+
export type PolylineSource<P = GeoJsonProperties> = GeoJSONSourceSpecification & {
|
|
36
|
+
type: 'geojson';
|
|
37
|
+
data: FeatureCollection<LineString, P>;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/** A FeatureCollection<LineString> ([lng, lat]) with one Feature per encoded string. */
|
|
41
|
+
export function polylineData<P = GeoJsonProperties>(encoded: string | string[], options?: number | DataOptions<P>): FeatureCollection<LineString, P>;
|
|
42
|
+
|
|
43
|
+
/** `{ type: 'geojson', data }` for map.addSource or a style's sources. */
|
|
44
|
+
export function polylineSource<P = GeoJsonProperties>(encoded: string | string[], options?: number | SourceOptions<P>): PolylineSource<P>;
|
|
45
|
+
|
|
46
|
+
/** Adds a GeoJSON source and a line layer, both named `id`. Returns the map. */
|
|
47
|
+
export function addPolylineLayer<M extends Map, P = GeoJsonProperties>(map: M, id: string, encoded: string | string[], options?: number | LayerOptions<P>): M;
|
|
48
|
+
|
|
49
|
+
/** Replaces the data of the GeoJSON source `id`. Returns what setData returns (the source). Throws a PolylineError if there is no such GeoJSON source. */
|
|
50
|
+
export function setPolylineData<P = GeoJsonProperties>(map: Map, id: string, encoded: string | string[], options?: number | DataOptions<P>): ReturnType<GeoJSONSource['setData']>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// JSR copy of mapbox.d.ts: the same functions as the maplibre module, which
|
|
2
|
+
// take the same calls on a Mapbox map. Structural types, for the same reason
|
|
3
|
+
// as maplibre.jsr.d.ts. The npm package's mapbox.d.ts uses mapbox-gl's own
|
|
4
|
+
// types.
|
|
5
|
+
export * from './maplibre.jsr.d.ts';
|
package/types/maplibre.d.ts
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
// Types for @duoquote/polytini/maplibre, built from maplibre-gl's own types
|
|
2
|
-
// (type-only imports, so nothing is loaded at runtime). The source and layer
|
|
3
|
-
// types are taken from Map#addSource and Map#addLayer, so they follow the
|
|
4
|
-
// installed maplibre-gl version.
|
|
5
|
-
import type { Map, GeoJSONSource } from 'maplibre-gl';
|
|
6
|
-
import type { FeatureCollection, LineString, GeoJsonProperties } from 'geojson';
|
|
7
|
-
import type { Options } from './index.d.ts';
|
|
8
|
-
|
|
9
|
-
/** MapLibre's GeoJSON source specification. */
|
|
10
|
-
export type GeoJSONSourceSpecification = Extract<Parameters<Map['addSource']>[1], { type: 'geojson' }>;
|
|
11
|
-
|
|
12
|
-
/** MapLibre's line layer specification. */
|
|
13
|
-
export type LineLayerSpecification = Extract<Parameters<Map['addLayer']>[0], { type: 'line' }>;
|
|
14
|
-
|
|
15
|
-
export type FeatureId = string | number;
|
|
16
|
-
|
|
17
|
-
export interface DataOptions<P = GeoJsonProperties> extends Options {
|
|
18
|
-
/** Properties for every line, or an array with one object per line. Default {}. */
|
|
19
|
-
properties?: P | P[];
|
|
20
|
-
/** Feature id for every line, or an array with one per line. MapLibre's feature state needs numeric ids or promoteId. */
|
|
21
|
-
id?: FeatureId | FeatureId[];
|
|
22
|
-
/** Add a [west, south, east, north] bbox to each feature. Default false. */
|
|
23
|
-
bbox?: boolean;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface SourceOptions<P = GeoJsonProperties> extends DataOptions<P> {
|
|
27
|
-
/** Other source options: lineMetrics, tolerance, promoteId, generateId, attribution, and so on. */
|
|
28
|
-
source?: Partial<Omit<GeoJSONSourceSpecification, 'type' | 'data'>>;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface LayerOptions<P = GeoJsonProperties> extends SourceOptions<P> {
|
|
32
|
-
/** Merged into the line layer: paint, layout, filter, minzoom, maxzoom, metadata, or another id. */
|
|
33
|
-
layer?: Partial<Omit<LineLayerSpecification, 'type' | 'source'>>;
|
|
34
|
-
/** The id of an existing layer to insert the new layer before. */
|
|
35
|
-
beforeId?: string;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** A GeoJSON source specification whose data is a FeatureCollection of LineStrings. */
|
|
39
|
-
export type PolylineSource<P = GeoJsonProperties> = GeoJSONSourceSpecification & {
|
|
40
|
-
type: 'geojson';
|
|
41
|
-
data: FeatureCollection<LineString, P>;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/** A FeatureCollection<LineString> ([lng, lat]) with one Feature per encoded string. */
|
|
45
|
-
export function polylineData<P = GeoJsonProperties>(encoded: string | string[], options?: number | DataOptions<P>): FeatureCollection<LineString, P>;
|
|
46
|
-
|
|
47
|
-
/** `{ type: 'geojson', data }` for map.addSource or a style's sources. */
|
|
48
|
-
export function polylineSource<P = GeoJsonProperties>(encoded: string | string[], options?: number | SourceOptions<P>): PolylineSource<P>;
|
|
49
|
-
|
|
50
|
-
/** Adds a GeoJSON source and a line layer, both named `id`. Returns the map. */
|
|
51
|
-
export function addPolylineLayer<M extends Map, P = GeoJsonProperties>(map: M, id: string, encoded: string | string[], options?: number | LayerOptions<P>): M;
|
|
52
|
-
|
|
53
|
-
/** Replaces the data of the GeoJSON source `id`. Returns setData's Promise. Throws a PolylineError if there is no such GeoJSON source. */
|
|
54
|
-
export function setPolylineData<P = GeoJsonProperties>(map: Map, id: string, encoded: string | string[], options?: number | DataOptions<P>): ReturnType<GeoJSONSource['setData']>;
|
|
1
|
+
// Types for @duoquote/polytini/maplibre, built from maplibre-gl's own types
|
|
2
|
+
// (type-only imports, so nothing is loaded at runtime). The source and layer
|
|
3
|
+
// types are taken from Map#addSource and Map#addLayer, so they follow the
|
|
4
|
+
// installed maplibre-gl version.
|
|
5
|
+
import type { Map, GeoJSONSource } from 'maplibre-gl';
|
|
6
|
+
import type { FeatureCollection, LineString, GeoJsonProperties } from 'geojson';
|
|
7
|
+
import type { Options } from './index.d.ts';
|
|
8
|
+
|
|
9
|
+
/** MapLibre's GeoJSON source specification. */
|
|
10
|
+
export type GeoJSONSourceSpecification = Extract<Parameters<Map['addSource']>[1], { type: 'geojson' }>;
|
|
11
|
+
|
|
12
|
+
/** MapLibre's line layer specification. */
|
|
13
|
+
export type LineLayerSpecification = Extract<Parameters<Map['addLayer']>[0], { type: 'line' }>;
|
|
14
|
+
|
|
15
|
+
export type FeatureId = string | number;
|
|
16
|
+
|
|
17
|
+
export interface DataOptions<P = GeoJsonProperties> extends Options {
|
|
18
|
+
/** Properties for every line, or an array with one object per line. Default {}. */
|
|
19
|
+
properties?: P | P[];
|
|
20
|
+
/** Feature id for every line, or an array with one per line. MapLibre's feature state needs numeric ids or promoteId. */
|
|
21
|
+
id?: FeatureId | FeatureId[];
|
|
22
|
+
/** Add a [west, south, east, north] bbox to each feature. Default false. */
|
|
23
|
+
bbox?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface SourceOptions<P = GeoJsonProperties> extends DataOptions<P> {
|
|
27
|
+
/** Other source options: lineMetrics, tolerance, promoteId, generateId, attribution, and so on. */
|
|
28
|
+
source?: Partial<Omit<GeoJSONSourceSpecification, 'type' | 'data'>>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface LayerOptions<P = GeoJsonProperties> extends SourceOptions<P> {
|
|
32
|
+
/** Merged into the line layer: paint, layout, filter, minzoom, maxzoom, metadata, or another id. */
|
|
33
|
+
layer?: Partial<Omit<LineLayerSpecification, 'type' | 'source'>>;
|
|
34
|
+
/** The id of an existing layer to insert the new layer before. */
|
|
35
|
+
beforeId?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** A GeoJSON source specification whose data is a FeatureCollection of LineStrings. */
|
|
39
|
+
export type PolylineSource<P = GeoJsonProperties> = GeoJSONSourceSpecification & {
|
|
40
|
+
type: 'geojson';
|
|
41
|
+
data: FeatureCollection<LineString, P>;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** A FeatureCollection<LineString> ([lng, lat]) with one Feature per encoded string. */
|
|
45
|
+
export function polylineData<P = GeoJsonProperties>(encoded: string | string[], options?: number | DataOptions<P>): FeatureCollection<LineString, P>;
|
|
46
|
+
|
|
47
|
+
/** `{ type: 'geojson', data }` for map.addSource or a style's sources. */
|
|
48
|
+
export function polylineSource<P = GeoJsonProperties>(encoded: string | string[], options?: number | SourceOptions<P>): PolylineSource<P>;
|
|
49
|
+
|
|
50
|
+
/** Adds a GeoJSON source and a line layer, both named `id`. Returns the map. */
|
|
51
|
+
export function addPolylineLayer<M extends Map, P = GeoJsonProperties>(map: M, id: string, encoded: string | string[], options?: number | LayerOptions<P>): M;
|
|
52
|
+
|
|
53
|
+
/** Replaces the data of the GeoJSON source `id`. Returns setData's Promise. Throws a PolylineError if there is no such GeoJSON source. */
|
|
54
|
+
export function setPolylineData<P = GeoJsonProperties>(map: Map, id: string, encoded: string | string[], options?: number | DataOptions<P>): ReturnType<GeoJSONSource['setData']>;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// JSR copy of maplibre.d.ts. JSR builds its docs without node_modules, so
|
|
2
|
+
// maplibre-gl's and @types/geojson's types can't be imported; the map and
|
|
3
|
+
// the specifications are described structurally here, by the methods and
|
|
4
|
+
// fields this module uses. The npm package's maplibre.d.ts uses maplibre-gl's
|
|
5
|
+
// own types.
|
|
6
|
+
import type { Options } from './index.d.ts';
|
|
7
|
+
import type { FeatureCollection, LineString, GeoJsonProperties } from './geojson.jsr.d.ts';
|
|
8
|
+
|
|
9
|
+
export type { Feature, FeatureCollection, Geometry, GeometryCollection, Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon, Position, BBox, GeoJsonProperties } from './geojson.jsr.d.ts';
|
|
10
|
+
|
|
11
|
+
/** The parts of a MapLibre or Mapbox Map this module calls. */
|
|
12
|
+
export interface MapLike {
|
|
13
|
+
/** Map#addSource. */
|
|
14
|
+
addSource(id: string, source: GeoJSONSourceSpecification): unknown;
|
|
15
|
+
/** Map#addLayer. */
|
|
16
|
+
addLayer(layer: LineLayerSpecification, beforeId?: string): unknown;
|
|
17
|
+
/** Map#getSource. */
|
|
18
|
+
getSource(id: string): unknown;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** A GeoJSON source specification: { type: 'geojson', data, ...options }. */
|
|
22
|
+
export interface GeoJSONSourceSpecification {
|
|
23
|
+
/** Always "geojson". */
|
|
24
|
+
type: 'geojson';
|
|
25
|
+
/** A GeoJSON object or a URL to one. */
|
|
26
|
+
data?: unknown;
|
|
27
|
+
/** Any other source option: lineMetrics, tolerance, promoteId, generateId, attribution, and so on. */
|
|
28
|
+
[option: string]: unknown;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** A line layer specification. */
|
|
32
|
+
export interface LineLayerSpecification {
|
|
33
|
+
/** The layer id. */
|
|
34
|
+
id: string;
|
|
35
|
+
/** Always "line". */
|
|
36
|
+
type: 'line';
|
|
37
|
+
/** The source id. */
|
|
38
|
+
source?: string;
|
|
39
|
+
/** Paint properties. */
|
|
40
|
+
paint?: { [property: string]: unknown };
|
|
41
|
+
/** Layout properties. */
|
|
42
|
+
layout?: { [property: string]: unknown };
|
|
43
|
+
/** Any other layer option: filter, minzoom, maxzoom, metadata, slot, and so on. */
|
|
44
|
+
[option: string]: unknown;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** A feature id: a string, or a number for feature state. */
|
|
48
|
+
export type FeatureId = string | number;
|
|
49
|
+
|
|
50
|
+
/** Options for polylineData: polytini's options plus the feature fields. */
|
|
51
|
+
export interface DataOptions<P = GeoJsonProperties> extends Options {
|
|
52
|
+
/** Properties for every line, or an array with one object per line. Default {}. */
|
|
53
|
+
properties?: P | P[];
|
|
54
|
+
/** Feature id for every line, or an array with one per line. Feature state needs numeric ids or promoteId. */
|
|
55
|
+
id?: FeatureId | FeatureId[];
|
|
56
|
+
/** Add a [west, south, east, north] bbox to each feature. Default false. */
|
|
57
|
+
bbox?: boolean;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Options for polylineSource: DataOptions plus extra source options. */
|
|
61
|
+
export interface SourceOptions<P = GeoJsonProperties> extends DataOptions<P> {
|
|
62
|
+
/** Other source options: lineMetrics, tolerance, promoteId, generateId, attribution, and so on. */
|
|
63
|
+
source?: { [option: string]: unknown };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Options for addPolylineLayer: SourceOptions plus the layer. */
|
|
67
|
+
export interface LayerOptions<P = GeoJsonProperties> extends SourceOptions<P> {
|
|
68
|
+
/** Merged into the line layer: paint, layout, filter, minzoom, maxzoom, metadata, or another id. */
|
|
69
|
+
layer?: { [option: string]: unknown };
|
|
70
|
+
/** The id of an existing layer to insert the new layer before. */
|
|
71
|
+
beforeId?: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** A GeoJSON source specification whose data is a FeatureCollection of LineStrings. */
|
|
75
|
+
export interface PolylineSource<P = GeoJsonProperties> extends GeoJSONSourceSpecification {
|
|
76
|
+
/** Always "geojson". */
|
|
77
|
+
type: 'geojson';
|
|
78
|
+
/** One Feature per encoded line. */
|
|
79
|
+
data: FeatureCollection<LineString, P>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** A FeatureCollection<LineString> ([lng, lat]) with one Feature per encoded string. */
|
|
83
|
+
export function polylineData<P = GeoJsonProperties>(encoded: string | string[], options?: number | DataOptions<P>): FeatureCollection<LineString, P>;
|
|
84
|
+
|
|
85
|
+
/** `{ type: 'geojson', data }` for map.addSource or a style's sources. */
|
|
86
|
+
export function polylineSource<P = GeoJsonProperties>(encoded: string | string[], options?: number | SourceOptions<P>): PolylineSource<P>;
|
|
87
|
+
|
|
88
|
+
/** Adds a GeoJSON source and a line layer, both named `id`. Returns the map. */
|
|
89
|
+
export function addPolylineLayer<M extends MapLike, P = GeoJsonProperties>(map: M, id: string, encoded: string | string[], options?: number | LayerOptions<P>): M;
|
|
90
|
+
|
|
91
|
+
/** Replaces the data of the GeoJSON source `id` and returns what its setData returns. Throws a PolylineError if there is no such GeoJSON source. */
|
|
92
|
+
export function setPolylineData<P = GeoJsonProperties>(map: MapLike, id: string, encoded: string | string[], options?: number | DataOptions<P>): unknown;
|