@duoquote/polytini 0.0.0-stage → 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 -0
- package/README.md +119 -2
- package/dist/deckgl.cjs +250 -0
- package/dist/flexible.cjs +229 -0
- package/dist/google.cjs +232 -0
- package/dist/leaflet-auto.cjs +209 -0
- package/dist/leaflet.cjs +231 -0
- package/dist/mapbox.cjs +185 -0
- package/dist/maplibre.cjs +185 -0
- package/dist/node.cjs +322 -0
- package/dist/presets.cjs +65 -0
- package/dist/turf.cjs +267 -0
- package/dist/types/cli.d.cts +2 -0
- package/dist/types/deckgl.d.cts +72 -0
- package/dist/types/flexible.d.cts +92 -0
- package/dist/types/geojson.jsr.d.cts +111 -0
- package/dist/types/google.d.cts +48 -0
- package/dist/types/google.jsr.d.cts +72 -0
- package/dist/types/index.d.cts +109 -0
- package/dist/types/leaflet-auto.d.cts +4 -0
- package/dist/types/leaflet-auto.jsr.d.cts +2 -0
- package/dist/types/leaflet.d.cts +39 -0
- package/dist/types/leaflet.jsr.d.cts +15 -0
- package/dist/types/mapbox.d.cts +50 -0
- package/dist/types/mapbox.jsr.d.cts +5 -0
- package/dist/types/maplibre.d.cts +54 -0
- package/dist/types/maplibre.jsr.d.cts +92 -0
- package/dist/types/openlayers.d.cts +23 -0
- package/dist/types/openlayers.jsr.d.cts +42 -0
- package/dist/types/presets.d.cts +70 -0
- package/dist/types/turf.d.cts +33 -0
- package/dist/types/turf.jsr.d.cts +46 -0
- package/dist/types/wasm.d.cts +42 -0
- package/dist/web.cjs +231 -0
- package/package.json +198 -4
- package/src/browser.js +15 -0
- package/src/bun.js +4 -0
- package/src/cli-lib.js +160 -0
- package/src/cli.js +7 -0
- package/src/core.js +268 -0
- package/src/deckgl.js +176 -0
- package/src/deno.js +12 -0
- package/src/error.js +15 -0
- package/src/fast.js +179 -0
- package/src/flexible.js +283 -0
- package/src/google.js +70 -0
- package/src/leaflet-auto.js +11 -0
- package/src/leaflet.js +44 -0
- package/src/mapbox.js +10 -0
- package/src/maplibre.js +57 -0
- package/src/node.js +17 -0
- package/src/openlayers.js +172 -0
- package/src/presets.js +242 -0
- package/src/text.js +111 -0
- package/src/turf.js +80 -0
- package/src/wasm-bytes.js +2 -0
- package/src/wasm.js +235 -0
- package/src/web.js +9 -0
- package/types/cli.d.ts +2 -0
- package/types/deckgl.d.ts +72 -0
- package/types/flexible.d.ts +92 -0
- package/types/geojson.jsr.d.ts +111 -0
- package/types/google.d.ts +48 -0
- package/types/google.jsr.d.ts +72 -0
- package/types/index.d.ts +109 -0
- package/types/leaflet-auto.d.ts +4 -0
- package/types/leaflet-auto.jsr.d.ts +2 -0
- package/types/leaflet.d.ts +39 -0
- package/types/leaflet.jsr.d.ts +15 -0
- package/types/mapbox.d.ts +50 -0
- package/types/mapbox.jsr.d.ts +5 -0
- package/types/maplibre.d.ts +54 -0
- package/types/maplibre.jsr.d.ts +92 -0
- package/types/openlayers.d.ts +23 -0
- package/types/openlayers.jsr.d.ts +42 -0
- package/types/presets.d.ts +70 -0
- package/types/turf.d.ts +33 -0
- package/types/turf.jsr.d.ts +46 -0
- package/types/wasm.d.ts +42 -0
- package/wasm/polytini.wasm +0 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// JSR copy of google.d.ts. JSR's type output can't carry the
|
|
2
|
+
// @types/google.maps reference, so the Maps shapes are described
|
|
3
|
+
// structurally here: anything with lat() and lng() is a LatLng. The npm
|
|
4
|
+
// package's google.d.ts uses the real google.maps types.
|
|
5
|
+
import type * as P from './index.d.ts';
|
|
6
|
+
import type { Options, Point } from './index.d.ts';
|
|
7
|
+
|
|
8
|
+
/** Anything with lat() and lng(), such as google.maps.LatLng. */
|
|
9
|
+
export interface LatLng {
|
|
10
|
+
/** Latitude in degrees. */
|
|
11
|
+
lat(): number;
|
|
12
|
+
/** Longitude in degrees. */
|
|
13
|
+
lng(): number;
|
|
14
|
+
}
|
|
15
|
+
/** A plain { lat, lng } object, like google.maps.LatLngLiteral. */
|
|
16
|
+
export interface LatLngLiteral {
|
|
17
|
+
/** Latitude in degrees. */
|
|
18
|
+
lat: number;
|
|
19
|
+
/** Longitude in degrees. */
|
|
20
|
+
lng: number;
|
|
21
|
+
}
|
|
22
|
+
/** Anything with getArray(), such as google.maps.MVCArray. */
|
|
23
|
+
export interface MVCArrayLike<T> {
|
|
24
|
+
/** The items as an array. */
|
|
25
|
+
getArray(): T[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The main entry's PolylineError. */
|
|
29
|
+
export declare const PolylineError: typeof P.PolylineError;
|
|
30
|
+
/** The main entry's PolylineError type. */
|
|
31
|
+
export type PolylineError = P.PolylineError;
|
|
32
|
+
|
|
33
|
+
/** A LatLng constructor: LatLng or anything built the same way. */
|
|
34
|
+
export type LatLngConstructor = new (lat: number, lng: number, noClampNoWrap?: boolean) => LatLng;
|
|
35
|
+
|
|
36
|
+
/** Options for decodePath: polytini's options without order, plus the LatLng class. */
|
|
37
|
+
export interface DecodePathOptions extends Omit<Options, 'order'> {
|
|
38
|
+
/**
|
|
39
|
+
* The class to build points with. Default: globalThis.LatLng
|
|
40
|
+
* when it exists. false or null returns LatLngLiteral objects.
|
|
41
|
+
*/
|
|
42
|
+
LatLng?: LatLngConstructor | false | null;
|
|
43
|
+
/** Passed to the LatLng constructor. Without it, LatLng clamps latitude and wraps longitude into [-180, 180). */
|
|
44
|
+
noClampNoWrap?: boolean;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** A point encodePath takes: LatLng, LatLngLiteral or a [lat, lng] tuple. */
|
|
48
|
+
export type PathPoint = LatLng | LatLngLiteral | Point;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Decodes an encoded path to LatLngLiteral objects (`LatLng: false`).
|
|
52
|
+
*/
|
|
53
|
+
export function decodePath(encodedPath: string, options: DecodePathOptions & { LatLng: false | null }): LatLngLiteral[];
|
|
54
|
+
/**
|
|
55
|
+
* Decodes an encoded path, like google.maps.geometry.encoding.decodePath,
|
|
56
|
+
* to LatLng objects. Without a `LatLng` option this uses
|
|
57
|
+
* globalThis.LatLng; when the Maps JavaScript API isn't loaded
|
|
58
|
+
* the result is LatLngLiteral objects at runtime, so pass `LatLng: false`
|
|
59
|
+
* there to get that type. Strict by default: a malformed string throws a
|
|
60
|
+
* PolylineError unless `strict: false`.
|
|
61
|
+
*/
|
|
62
|
+
export function decodePath(encodedPath: string, options?: number | (DecodePathOptions & { LatLng?: LatLngConstructor })): LatLng[];
|
|
63
|
+
/** decodePath when the LatLng option isn't known until runtime. */
|
|
64
|
+
export function decodePath(encodedPath: string, options?: number | DecodePathOptions): LatLng[] | LatLngLiteral[];
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Encodes a path, like google.maps.geometry.encoding.encodePath: an array or
|
|
68
|
+
* MVCArray of LatLng, LatLngLiteral or [lat, lng] tuples, mixed
|
|
69
|
+
* or not. Precision 5 by default. `order: 'lnglat'` applies to tuples and
|
|
70
|
+
* LatLng objects; literals are read by name. Strict by default.
|
|
71
|
+
*/
|
|
72
|
+
export function encodePath(path: readonly PathPoint[] | MVCArrayLike<PathPoint>, options?: number | Options): string;
|
|
@@ -0,0 +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
|
+
/** 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;
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +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
|
+
/** 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;
|
|
@@ -0,0 +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']>;
|
|
@@ -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';
|
|
@@ -0,0 +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']>;
|
|
@@ -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;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Types for @duoquote/polytini/openlayers. Type-only imports: nothing from
|
|
2
|
+
// ol is loaded at runtime, you pass its classes to createPolylineFormat.
|
|
3
|
+
import type OlPolyline from 'ol/format/Polyline.js';
|
|
4
|
+
import type { Options } from 'ol/format/Polyline.js';
|
|
5
|
+
import type OlLineString from 'ol/geom/LineString.js';
|
|
6
|
+
|
|
7
|
+
export type { Options };
|
|
8
|
+
|
|
9
|
+
/** ol's classes, as imported from ol/format/Polyline.js and ol/geom/LineString.js. */
|
|
10
|
+
export interface OpenLayersClasses {
|
|
11
|
+
Polyline: typeof OlPolyline;
|
|
12
|
+
LineString: typeof OlLineString;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Makes a drop-in for ol/format/Polyline: the same constructor options
|
|
17
|
+
* (factor, geometryLayout), methods and output, faster. Unlike ol's,
|
|
18
|
+
* writeGeometry never changes the geometry it is given. Also takes the `ol`
|
|
19
|
+
* namespace of the full build ({ format: { Polyline }, geom: { LineString } }).
|
|
20
|
+
*/
|
|
21
|
+
export function createPolylineFormat(
|
|
22
|
+
ol: OpenLayersClasses | { format: { Polyline: typeof OlPolyline }; geom: { LineString: typeof OlLineString } },
|
|
23
|
+
): typeof OlPolyline;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// JSR copy of openlayers.d.ts. JSR builds its docs without node_modules, so
|
|
2
|
+
// ol's classes are described structurally: the factory takes your Polyline
|
|
3
|
+
// and LineString classes and returns a subclass of the Polyline class you
|
|
4
|
+
// passed, with its type. The npm package's openlayers.d.ts uses ol's own
|
|
5
|
+
// types.
|
|
6
|
+
|
|
7
|
+
/** ol/format/Polyline's constructor options. */
|
|
8
|
+
export interface Options {
|
|
9
|
+
/** The factor the coordinates were multiplied by. Default 1e5. */
|
|
10
|
+
factor?: number;
|
|
11
|
+
/** The geometry layout. Default "XY". */
|
|
12
|
+
geometryLayout?: 'XY' | 'XYZ' | 'XYM' | 'XYZM';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** A Polyline format class: ol/format/Polyline or a subclass. */
|
|
16
|
+
export type PolylineClass = new (options?: Options) => object;
|
|
17
|
+
|
|
18
|
+
/** A LineString geometry class: ol/geom/LineString. */
|
|
19
|
+
export type LineStringClass = new (...args: never[]) => object;
|
|
20
|
+
|
|
21
|
+
/** ol's classes, as imported from ol/format/Polyline.js and ol/geom/LineString.js. */
|
|
22
|
+
export interface OpenLayersClasses<T extends PolylineClass> {
|
|
23
|
+
/** ol/format/Polyline's default export. */
|
|
24
|
+
Polyline: T;
|
|
25
|
+
/** ol/geom/LineString's default export. */
|
|
26
|
+
LineString: LineStringClass;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The full build's `ol` namespace. */
|
|
30
|
+
export interface OpenLayersNamespace<T extends PolylineClass> {
|
|
31
|
+
/** ol.format, with Polyline. */
|
|
32
|
+
format: { Polyline: T };
|
|
33
|
+
/** ol.geom, with LineString. */
|
|
34
|
+
geom: { LineString: LineStringClass };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Makes a drop-in for ol/format/Polyline: the same constructor options
|
|
39
|
+
* (factor, geometryLayout), methods and output, faster. Unlike ol's,
|
|
40
|
+
* writeGeometry never changes the geometry it is given.
|
|
41
|
+
*/
|
|
42
|
+
export function createPolylineFormat<T extends PolylineClass>(ol: OpenLayersClasses<T> | OpenLayersNamespace<T>): T;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Option presets for routing engines that use the Google encoded polyline
|
|
2
|
+
// format. Each one is a plain options object for encode, decode,
|
|
3
|
+
// encodeFlat, decodeFlat, toGeoJSON and fromGeoJSON. See src/presets.js for
|
|
4
|
+
// the sources behind every value.
|
|
5
|
+
|
|
6
|
+
/** A 2D preset: precision and the order of the tuples you pass and get back. */
|
|
7
|
+
export interface Preset2D<P extends number = number, O extends 'latlng' | 'lnglat' = 'latlng' | 'lnglat'> {
|
|
8
|
+
/** Decimal places. */
|
|
9
|
+
readonly precision: P;
|
|
10
|
+
/** The tuple order. */
|
|
11
|
+
readonly order: O;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** A preset with a third value per point, scaled by `zFactor`. */
|
|
15
|
+
export interface Preset3D<P extends number = number, O extends 'latlng' | 'lnglat' = 'latlng' | 'lnglat'> extends Preset2D<P, O> {
|
|
16
|
+
/** Three values per point. */
|
|
17
|
+
readonly dimensions: 3;
|
|
18
|
+
/** The factor of the third value. */
|
|
19
|
+
readonly zFactor: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Google Maps Platform: precision 5, [lat, lng]. */
|
|
23
|
+
export declare const google: Preset2D<5, 'latlng'>;
|
|
24
|
+
/** OSRM geometries=polyline: precision 5, [lng, lat] like its GeoJSON. */
|
|
25
|
+
export declare const osrm: Preset2D<5, 'lnglat'>;
|
|
26
|
+
/** OSRM geometries=polyline6: precision 6, [lng, lat]. */
|
|
27
|
+
export declare const osrm6: Preset2D<6, 'lnglat'>;
|
|
28
|
+
/** Valhalla shapes: precision 6, [lng, lat] like its format=osrm GeoJSON. */
|
|
29
|
+
export declare const valhalla: Preset2D<6, 'lnglat'>;
|
|
30
|
+
/** Stadia Maps routing (Valhalla): precision 6, [lng, lat]. */
|
|
31
|
+
export declare const stadia: Preset2D<6, 'lnglat'>;
|
|
32
|
+
/**
|
|
33
|
+
* GraphHopper points_encoded=true: precision 5 (the default
|
|
34
|
+
* points_encoded_multiplier), [lng, lat] like points_encoded=false.
|
|
35
|
+
*/
|
|
36
|
+
export declare const graphhopper: Preset2D<5, 'lnglat'>;
|
|
37
|
+
/** GraphHopper with elevation=true: [lng, lat, elevation in meters], elevation stored in centimeters. */
|
|
38
|
+
export declare const graphhopper3d: Preset3D<5, 'lnglat'>;
|
|
39
|
+
/** openrouteservice JSON geometry: precision 5, [lng, lat] like its GeoJSON. */
|
|
40
|
+
export declare const openrouteservice: Preset2D<5, 'lnglat'>;
|
|
41
|
+
/** openrouteservice with elevation=true: [lng, lat, elevation in meters], elevation stored in centimeters. */
|
|
42
|
+
export declare const openrouteservice3d: Preset3D<5, 'lnglat'>;
|
|
43
|
+
/** Mapbox Directions geometries=polyline: precision 5, [lng, lat]. */
|
|
44
|
+
export declare const mapbox: Preset2D<5, 'lnglat'>;
|
|
45
|
+
/** Mapbox Directions geometries=polyline6: precision 6, [lng, lat]. */
|
|
46
|
+
export declare const mapbox6: Preset2D<6, 'lnglat'>;
|
|
47
|
+
/** Strava map.polyline and summary_polyline: precision 5, [lat, lng] like its latlng stream. */
|
|
48
|
+
export declare const strava: Preset2D<5, 'latlng'>;
|
|
49
|
+
/** OpenTripPlanner legGeometry.points: precision 5, [lat, lng]. */
|
|
50
|
+
export declare const otp: Preset2D<5, 'latlng'>;
|
|
51
|
+
|
|
52
|
+
/** Every preset, keyed by its export name. */
|
|
53
|
+
export declare const presets: {
|
|
54
|
+
readonly google: typeof google;
|
|
55
|
+
readonly osrm: typeof osrm;
|
|
56
|
+
readonly osrm6: typeof osrm6;
|
|
57
|
+
readonly valhalla: typeof valhalla;
|
|
58
|
+
readonly stadia: typeof stadia;
|
|
59
|
+
readonly graphhopper: typeof graphhopper;
|
|
60
|
+
readonly graphhopper3d: typeof graphhopper3d;
|
|
61
|
+
readonly openrouteservice: typeof openrouteservice;
|
|
62
|
+
readonly openrouteservice3d: typeof openrouteservice3d;
|
|
63
|
+
readonly mapbox: typeof mapbox;
|
|
64
|
+
readonly mapbox6: typeof mapbox6;
|
|
65
|
+
readonly strava: typeof strava;
|
|
66
|
+
readonly otp: typeof otp;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/** The name of a preset in `presets`. */
|
|
70
|
+
export type PresetName = keyof typeof presets;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Types for @duoquote/polytini/turf, using Turf's and GeoJSON's own types.
|
|
2
|
+
import type { Feature, FeatureCollection, LineString, Polygon, GeoJsonProperties } from 'geojson';
|
|
3
|
+
import type { AllGeoJSON, Id } from '@turf/helpers';
|
|
4
|
+
import type { Options } from './index.d.ts';
|
|
5
|
+
|
|
6
|
+
export interface FeatureOptions<P = GeoJsonProperties> extends Options {
|
|
7
|
+
/** Feature properties. Default {}. */
|
|
8
|
+
properties?: P;
|
|
9
|
+
/** Feature id. */
|
|
10
|
+
id?: Id;
|
|
11
|
+
/** Add a [west, south, east, north] bbox. Default false. */
|
|
12
|
+
bbox?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface CollectionOptions<P = GeoJsonProperties> extends Options {
|
|
16
|
+
/** Shared properties, or one object per line. */
|
|
17
|
+
properties?: P | P[];
|
|
18
|
+
/** One id per line, or the same for all. */
|
|
19
|
+
id?: Id | Id[];
|
|
20
|
+
bbox?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** A Feature<LineString> ([lng, lat], like Turf) from one encoded line. */
|
|
24
|
+
export function toFeature<P = GeoJsonProperties>(encoded: string, options?: number | FeatureOptions<P>): Feature<LineString, P>;
|
|
25
|
+
|
|
26
|
+
/** A FeatureCollection<LineString>, one Feature per string. */
|
|
27
|
+
export function toFeatureCollection<P = GeoJsonProperties>(encoded: string[], options?: number | CollectionOptions<P>): FeatureCollection<LineString, P>;
|
|
28
|
+
|
|
29
|
+
/** A Feature<Polygon> from encoded rings: outer first, then holes. */
|
|
30
|
+
export function toPolygonFeature<P = GeoJsonProperties>(rings: string[], options?: number | FeatureOptions<P>): Feature<Polygon, P>;
|
|
31
|
+
|
|
32
|
+
/** Every line in any GeoJSON: LineStrings, MultiLineString parts and polygon rings, in document order. Points are skipped. */
|
|
33
|
+
export function fromGeoJSON(geojson: AllGeoJSON, options?: number | Options): string[];
|