1 | import { PolylineOptions, LatLng, LatLngLiteral, Polyline, LatLngExpression } from 'leaflet';
|
2 |
|
3 | interface GeodesicOptions extends PolylineOptions {
|
4 | wrap?: boolean;
|
5 | steps?: number;
|
6 | radius?: number;
|
7 | }
|
8 | interface WGS84Vector extends LatLngLiteral {
|
9 | bearing: number;
|
10 | }
|
11 | interface GeoDistance {
|
12 | distance: number;
|
13 | initialBearing: number;
|
14 | finalBearing: number;
|
15 | }
|
16 | declare class GeodesicCore {
|
17 | readonly options: GeodesicOptions;
|
18 | readonly ellipsoid: {
|
19 | a: number;
|
20 | b: number;
|
21 | f: number;
|
22 | };
|
23 | constructor(options?: GeodesicOptions);
|
24 | toRadians(degree: number): number;
|
25 | toDegrees(radians: number): number;
|
26 | /**
|
27 | * implements scientific modulus
|
28 | * source: http://www.codeavenger.com/2017/05/19/JavaScript-Modulo-operation-and-the-Caesar-Cipher.html
|
29 | * @param n
|
30 | * @param p
|
31 | * @return
|
32 | */
|
33 | mod(n: number, p: number): number;
|
34 | /**
|
35 | * source: https://github.com/chrisveness/geodesy/blob/master/dms.js
|
36 | * @param degrees arbitrary value
|
37 | * @return degrees between 0..360
|
38 | */
|
39 | wrap360(degrees: number): number;
|
40 | /**
|
41 | * general wrap function with arbitrary max value
|
42 | * @param degrees arbitrary value
|
43 | * @param max
|
44 | * @return degrees between `-max`..`+max`
|
45 | */
|
46 | wrap(degrees: number, max?: number): number;
|
47 | /**
|
48 | * Vincenty direct calculation.
|
49 | * based on the work of Chris Veness (https://github.com/chrisveness/geodesy)
|
50 | * source: https://github.com/chrisveness/geodesy/blob/master/latlon-ellipsoidal-vincenty.js
|
51 | *
|
52 | * start starting point
|
53 | * in degrees)
bearing initial bearing ( |
54 | * from starting point to calculate along given bearing in meters.
distance distance |
55 | * maxInterations How many iterations can be made to reach the allowed deviation (`ε`), before an error will be thrown.
|
56 | * in degrees)
Final point (destination point) and bearing ( |
57 | */
|
58 | direct(start: LatLng, bearing: number, distance: number, maxInterations?: number): WGS84Vector;
|
59 | /**
|
60 | * Vincenty inverse calculation.
|
61 | * based on the work of Chris Veness (https://github.com/chrisveness/geodesy)
|
62 | * source: https://github.com/chrisveness/geodesy/blob/master/latlon-ellipsoidal-vincenty.js
|
63 | *
|
64 | * @param start Latitude/longitude of starting point.
|
65 | * @param dest Latitude/longitude of destination point.
|
66 | * @return Object including distance, initialBearing, finalBearing.
|
67 | */
|
68 | inverse(start: LatLng, dest: LatLng, maxInterations?: number, mitigateConvergenceError?: boolean): GeoDistance;
|
69 | /**
|
70 | * Returns the point of intersection of two paths defined by position and bearing.
|
71 | * This calculation uses a spherical model of the earth. This will lead to small errors compared to an ellipsiod model.
|
72 | * based on the work of Chris Veness (https://github.com/chrisveness/geodesy)
|
73 | * source: https://github.com/chrisveness/geodesy/blob/master/latlon-spherical.js
|
74 | *
|
75 | * @param firstPos 1st path: position and bearing
|
76 | * @param firstBearing
|
77 | * @param secondPos 2nd path: position and bearing
|
78 | * @param secondBearing
|
79 | */
|
80 | intersection(firstPos: LatLng, firstBearing: number, secondPos: LatLng, secondBearing: number): LatLng | null;
|
81 | midpoint(start: LatLng, dest: LatLng): LatLng;
|
82 | }
|
83 |
|
84 | /** detailled information of the current geometry */
|
85 | interface Statistics {
|
86 | /** Stores the distance for each individual geodesic line */
|
87 | distanceArray: number[];
|
88 | /** overall distance of all lines */
|
89 | totalDistance: number;
|
90 | /** number of positions that the geodesic lines are created from */
|
91 | points: number;
|
92 | /** number vertices that were created during geometry calculation */
|
93 | vertices: number;
|
94 | }
|
95 | declare class GeodesicGeometry {
|
96 | readonly geodesic: GeodesicCore;
|
97 | steps: number;
|
98 | constructor(options?: GeodesicOptions);
|
99 | /**
|
100 | * A geodesic line between `start` and `dest` is created with this recursive function.
|
101 | * It calculates the geodesic midpoint between `start` and `dest` and uses this midpoint to call itself again (twice!).
|
102 | * The results are then merged into one continuous linestring.
|
103 | *
|
104 | * The number of resulting vertices (incl. `start` and `dest`) depends on the initial value for `iterations`
|
105 | * and can be calculated with: vertices == 1 + 2 ** (initialIterations + 1)
|
106 | *
|
107 | * As this is an exponential function, be extra careful to limit the initial value for `iterations` (8 results in 513 vertices).
|
108 | *
|
109 | * @param start start position
|
110 | * @param dest destination
|
111 | * @param iterations
|
112 | * @return resulting linestring
|
113 | */
|
114 | recursiveMidpoint(start: LatLng, dest: LatLng, iterations: number): LatLng[];
|
115 | /**
|
116 | * This is the wrapper-function to generate a geodesic line. It's just for future backwards-compatibility
|
117 | * if there is another algorithm used to create the actual line.
|
118 | *
|
119 | * The `steps`-property is used to define the number of resulting vertices of the linestring: vertices == 1 + 2 ** (steps + 1)
|
120 | * The value for `steps` is currently limited to 8 (513 vertices) for performance reasons until another algorithm is found.
|
121 | *
|
122 | * @param start start position
|
123 | * @param dest destination
|
124 | * @return resulting linestring
|
125 | */
|
126 | line(start: LatLng, dest: LatLng): LatLng[];
|
127 | multiLineString(latlngs: LatLng[][]): LatLng[][];
|
128 | lineString(latlngs: LatLng[]): LatLng[];
|
129 | /**
|
130 | *
|
131 | * Is much (10x) faster than the previous implementation:
|
132 | *
|
133 | * ```
|
134 | * Benchmark (no split): splitLine x 459,044 ops/sec ±0.53% (95 runs sampled)
|
135 | * Benchmark (split): splitLine x 42,999 ops/sec ±0.51% (97 runs sampled)
|
136 | * ```
|
137 | *
|
138 | * @param startPosition
|
139 | * @param destPosition
|
140 | */
|
141 | splitLine(startPosition: LatLng, destPosition: LatLng): LatLng[][];
|
142 | /**
|
143 | * Linestrings of a given multilinestring that cross the antimeridian will be split in two separate linestrings.
|
144 | * This function is used to wrap lines around when they cross the antimeridian
|
145 | * It iterates over all linestrings and reconstructs the step-by-step if no split is needed.
|
146 | * In case the line was split, the linestring ends at the antimeridian and a new linestring is created for the
|
147 | * remaining points of the original linestring.
|
148 | *
|
149 | * @param multilinestring
|
150 | * @return another multilinestring where segments crossing the antimeridian are split
|
151 | */
|
152 | splitMultiLineString(multilinestring: LatLng[][]): LatLng[][];
|
153 | wrapMultiLineString(multilinestring: LatLng[][]): LatLng[][];
|
154 | /**
|
155 | * Creates a circular (constant radius), closed (1st pos == last pos) geodesic linestring.
|
156 | * The number of vertices is calculated with: `vertices == steps + 1` (where 1st == last)
|
157 | *
|
158 | * @param center
|
159 | * @param radius
|
160 | * @return resulting linestring
|
161 | */
|
162 | circle(center: LatLng, radius: number): LatLng[];
|
163 | /**
|
164 | * Handles splitting of circles at the antimeridian.
|
165 | * @param linestring a linestring that resembles the geodesic circle
|
166 | * @return a multilinestring that consist of one or two linestrings
|
167 | */
|
168 | splitCircle(linestring: LatLng[]): LatLng[][];
|
169 | /**
|
170 | * Calculates the distance between two positions on the earths surface
|
171 | * @param start 1st position
|
172 | * @param dest 2nd position
|
173 | * @return the distance in **meters**
|
174 | */
|
175 | distance(start: LatLng, dest: LatLng): number;
|
176 | multilineDistance(multilinestring: LatLng[][]): number[];
|
177 | updateStatistics(points: LatLng[][], vertices: LatLng[][]): Statistics;
|
178 | }
|
179 |
|
180 | /**
|
181 | * Draw geodesic lines based on L.Polyline
|
182 | */
|
183 | declare class GeodesicLine extends Polyline {
|
184 | /** these should be good for most use-cases */
|
185 | defaultOptions: GeodesicOptions;
|
186 | /** does the actual geometry calculations */
|
187 | readonly geom: GeodesicGeometry;
|
188 | /** use this if you need some detailled info about the current geometry */
|
189 | statistics: Statistics;
|
190 | /** stores all positions that are used to create the geodesic line */
|
191 | points: LatLng[][];
|
192 | constructor(latlngs?: LatLngExpression[] | LatLngExpression[][], options?: GeodesicOptions);
|
193 | /** calculates the geodesics and update the polyline-object accordingly */
|
194 | private updateGeometry;
|
195 | /**
|
196 | * overwrites the original function with additional functionality to create a geodesic line
|
197 | * @param latlngs an array (or 2d-array) of positions
|
198 | */
|
199 | setLatLngs(latlngs: LatLngExpression[] | LatLngExpression[][]): this;
|
200 | /**
|
201 | * add a given point to the geodesic line object
|
202 | * @param latlng point to add. The point will always be added to the last linestring of a multiline
|
203 | * @param latlngs define a linestring to add the new point to. Read from points-property before (e.g. `line.addLatLng(Beijing, line.points[0]);`)
|
204 | */
|
205 | addLatLng(latlng: LatLngExpression, latlngs?: LatLng[]): this;
|
206 | /**
|
207 | * Creates geodesic lines from a given GeoJSON-Object.
|
208 | * @param input GeoJSON-Object
|
209 | */
|
210 | fromGeoJson(input: GeoJSON.GeoJSON): this;
|
211 | /**
|
212 | * Calculates the distance between two geo-positions
|
213 | * @param start 1st position
|
214 | * @param dest 2nd position
|
215 | * @return the distance in meters
|
216 | */
|
217 | distance(start: LatLngExpression, dest: LatLngExpression): number;
|
218 | }
|
219 |
|
220 | /**
|
221 | * Can be used to create a geodesic circle based on L.Polyline
|
222 | */
|
223 | declare class GeodesicCircleClass extends Polyline {
|
224 | defaultOptions: GeodesicOptions;
|
225 | readonly geom: GeodesicGeometry;
|
226 | center: LatLng;
|
227 | radius: number;
|
228 | statistics: Statistics;
|
229 | constructor(center?: LatLngExpression, options?: GeodesicOptions);
|
230 | /**
|
231 | * Updates the geometry and re-calculates some statistics
|
232 | */
|
233 | private update;
|
234 | /**
|
235 | * Calculate the distance between the current center and an arbitrary position.
|
236 | * @param latlng geo-position to calculate distance to
|
237 | * @return distance in meters
|
238 | */
|
239 | distanceTo(latlng: LatLngExpression): number;
|
240 | /**
|
241 | * Set a new center for the geodesic circle and update the geometry. Radius may also be set.
|
242 | * @param center the new center
|
243 | * @param radius the new radius
|
244 | */
|
245 | setLatLng(center: LatLngExpression, radius?: number): void;
|
246 | /**
|
247 | * Set a new radius for the geodesic circle and update the geometry. Center may also be set.
|
248 | * @param radius the new radius
|
249 | * @param center the new center
|
250 | */
|
251 | setRadius(radius: number, center?: LatLngExpression): void;
|
252 | }
|
253 |
|
254 | declare module "leaflet" {
|
255 | type Geodesic = GeodesicLine;
|
256 | let Geodesic: typeof GeodesicLine;
|
257 | let geodesic: (...args: ConstructorParameters<typeof GeodesicLine>) => GeodesicLine;
|
258 | type GeodesicCircle = GeodesicCircleClass;
|
259 | let GeodesicCircle: typeof GeodesicCircleClass;
|
260 | let geodesiccircle: (...args: ConstructorParameters<typeof GeodesicCircleClass>) => GeodesicCircleClass;
|
261 | }
|
262 |
|
263 | export { GeodesicCircleClass, GeodesicLine };
|
264 |
|
\ | No newline at end of file |