1 | // Last module patch version validated against: 3.0.1
|
2 |
|
3 | import * as GeoJSON from "geojson";
|
4 |
|
5 | // ----------------------------------------------------------------------
|
6 | // Shared Interfaces and Types
|
7 | // ----------------------------------------------------------------------
|
8 |
|
9 | /**
|
10 | * A basic geometry for a sphere, which is supported by d3-geo
|
11 | * beyond the GeoJSON geometries.
|
12 | */
|
13 | export interface GeoSphere {
|
14 | /**
|
15 | * Sphere geometry type
|
16 | */
|
17 | type: "Sphere";
|
18 | }
|
19 |
|
20 | /**
|
21 | * Type Alias for GeoJSON Geometry Object and GeoSphere additional
|
22 | * geometry supported by d3-geo
|
23 | */
|
24 | export type GeoGeometryObjects = GeoJSON.GeometryObject | GeoSphere;
|
25 |
|
26 | /**
|
27 | * A GeoJSON-style GeometryCollection which supports GeoJSON geometry objects
|
28 | * and additionally GeoSphere.
|
29 | *
|
30 | * The generic refers to the type(s) of d3-geo geometry objects contained in the collection.
|
31 | */
|
32 | export interface ExtendedGeometryCollection<GeometryType extends GeoGeometryObjects = GeoGeometryObjects> {
|
33 | type: string;
|
34 | bbox?: number[] | undefined;
|
35 | crs?: {
|
36 | type: string;
|
37 | properties: any;
|
38 | } | undefined;
|
39 | geometries: GeometryType[];
|
40 | }
|
41 |
|
42 | /**
|
43 | * A GeoJSON-style Feature which support features built on GeoJSON GeometryObjects
|
44 | * or GeoSphere.
|
45 | *
|
46 | * The first generic refers to the type(s) of d3-geo geometry objects underlying the ExtendedFeature.
|
47 | * Unless explicitly ruled out, the geometry value is nullable.
|
48 | *
|
49 | * The second generic refers to the data type of the properties of the ExtendedFeature. Unless explicitly ruled out,
|
50 | * the properties value is nullable.
|
51 | */
|
52 | export interface ExtendedFeature<
|
53 | GeometryType extends GeoGeometryObjects | null = GeoGeometryObjects | null,
|
54 | Properties extends GeoJSON.GeoJsonProperties = GeoJSON.GeoJsonProperties,
|
55 | > extends GeoJSON.GeoJsonObject {
|
56 | geometry: GeometryType;
|
57 | properties: Properties;
|
58 | id?: string | number | undefined;
|
59 | }
|
60 |
|
61 | /**
|
62 | * A GeoJSON-style FeatureCollection which supports GeoJSON features
|
63 | * and features built on GeoSphere
|
64 | *
|
65 | * The generic refers to the type of ExtendedFeature contained in the ExtendedFeatureCollection.
|
66 | */
|
67 | export interface ExtendedFeatureCollection<FeatureType extends ExtendedFeature = ExtendedFeature>
|
68 | extends GeoJSON.GeoJsonObject
|
69 | {
|
70 | features: FeatureType[];
|
71 | }
|
72 |
|
73 | /**
|
74 | * Type Alias for permissible objects which can be used with d3-geo
|
75 | * methods
|
76 | */
|
77 | export type GeoPermissibleObjects =
|
78 | | GeoGeometryObjects
|
79 | | ExtendedGeometryCollection
|
80 | | ExtendedFeature
|
81 | | ExtendedFeatureCollection;
|
82 |
|
83 | // ----------------------------------------------------------------------
|
84 | // Spherical Math
|
85 | // ----------------------------------------------------------------------
|
86 |
|
87 | /**
|
88 | * Returns the spherical area of the specified GeoJSON object in steradians.
|
89 | * This is the spherical equivalent of path.area.
|
90 | */
|
91 | export function geoArea(
|
92 | object: ExtendedFeature | ExtendedFeatureCollection | GeoGeometryObjects | ExtendedGeometryCollection,
|
93 | ): number;
|
94 |
|
95 | /**
|
96 | * Returns the spherical bounding box for the specified GeoJSON object.
|
97 | * The bounding box is represented by a two-dimensional array: [[left, bottom], [right, top]],
|
98 | * where left is the minimum longitude, bottom is the minimum latitude, right is maximum longitude, and top is the maximum latitude.
|
99 | * All coordinates are given in degrees.
|
100 | * (Note that in projected planar coordinates, the minimum latitude is typically the maximum y-value, and the maximum latitude is typically the minimum y-value.)
|
101 | * This is the spherical equivalent of path.bounds.
|
102 | */
|
103 | export function geoBounds(
|
104 | object: ExtendedFeature | ExtendedFeatureCollection | GeoGeometryObjects | ExtendedGeometryCollection,
|
105 | ): [[number, number], [number, number]];
|
106 |
|
107 | /**
|
108 | * Returns the spherical centroid of the specified GeoJSON object.
|
109 | * This is the spherical equivalent of path.centroid.
|
110 | */
|
111 | export function geoCentroid(
|
112 | object: ExtendedFeature | ExtendedFeatureCollection | GeoGeometryObjects | ExtendedGeometryCollection,
|
113 | ): [number, number];
|
114 |
|
115 | /**
|
116 | * Returns true if and only if the specified GeoJSON object contains the specified point, or false if the object does not contain the point.
|
117 | * The point must be specified as a two-element array [longitude, latitude] in degrees.
|
118 | * For Point and MultiPoint geometries, an exact test is used; for a Sphere, true is always returned; for other geometries, an epsilon threshold is applied.
|
119 | */
|
120 | export function geoContains(
|
121 | object: ExtendedFeature | ExtendedFeatureCollection | GeoGeometryObjects | ExtendedGeometryCollection,
|
122 | point: [number, number],
|
123 | ): boolean;
|
124 |
|
125 | /**
|
126 | * Returns the great-arc distance in radians between the two points a and b.
|
127 | * Each point must be specified as a two-element array [longitude, latitude] in degrees.
|
128 | *
|
129 | * @param a Point specified as a two-element array [longitude, latitude] in degrees.
|
130 | * @param b Point specified as a two-element array [longitude, latitude] in degrees.
|
131 | */
|
132 | export function geoDistance(a: [number, number], b: [number, number]): number;
|
133 |
|
134 | /**
|
135 | * Returns the great-arc length of the specified GeoJSON object in radians.
|
136 | * For polygons, returns the perimeter of the exterior ring plus that of any interior rings.
|
137 | * This is the spherical equivalent of path.measure.
|
138 | */
|
139 | export function geoLength(
|
140 | object: ExtendedFeature | ExtendedFeatureCollection | GeoGeometryObjects | ExtendedGeometryCollection,
|
141 | ): number;
|
142 |
|
143 | /**
|
144 | * Returns an interpolator function given two points a and b.
|
145 | * Each point must be specified as a two-element array [longitude, latitude] in degrees.
|
146 | *
|
147 | * @param a Point specified as a two-element array [longitude, latitude] in degrees.
|
148 | * @param b Point specified as a two-element array [longitude, latitude] in degrees.
|
149 | */
|
150 | export function geoInterpolate(a: [number, number], b: [number, number]): (t: number) => [number, number];
|
151 |
|
152 | /**
|
153 | * A Geo Rotation
|
154 | */
|
155 | export interface GeoRotation {
|
156 | /**
|
157 | * Returns a new array [longitude, latitude] in degrees representing the rotated point of the given point.
|
158 | *
|
159 | * @param point The point must be specified as a two-element array [longitude, latitude] in degrees.
|
160 | */
|
161 | (point: [number, number]): [number, number];
|
162 |
|
163 | /**
|
164 | * Returns a new array [longitude, latitude] in degrees representing the point of the given rotated point; the inverse of rotation.
|
165 | *
|
166 | * @param point The rotated point must be specified as a two-element array [longitude, latitude] in degrees.
|
167 | */
|
168 | invert(point: [number, number]): [number, number];
|
169 | }
|
170 |
|
171 | /**
|
172 | * Returns a rotation function for the given angles.
|
173 | *
|
174 | * @param angles A two- or three-element array of numbers [lambda, phi, gamma] specifying the rotation angles in degrees about each spherical axis.
|
175 | * (These correspond to yaw, pitch and roll.) If the rotation angle gamma is omitted, it defaults to 0.
|
176 | */
|
177 | export function geoRotation(angles: [number, number] | [number, number, number]): GeoRotation;
|
178 |
|
179 | // ----------------------------------------------------------------------
|
180 | // Spherical Shapes
|
181 | // ----------------------------------------------------------------------
|
182 |
|
183 | // geoCircle ============================================================
|
184 |
|
185 | /**
|
186 | * A new circle generator
|
187 | *
|
188 | * The first generic corresponds to the "this"-context within which the geo circle generator will be invoked.
|
189 | *
|
190 | * The second generic corresponds to the type of the Datum which will be passed into the geo circle generator.
|
191 | */
|
192 | export interface GeoCircleGenerator<This = any, Datum = any> {
|
193 | /**
|
194 | * Returns a new GeoJSON geometry object of type “Polygon” approximating a circle on the surface of a sphere,
|
195 | * with the current center, radius and precision. Any arguments are passed to the accessors.
|
196 | */
|
197 | (this: This, d?: Datum, ...args: any[]): GeoJSON.Polygon;
|
198 |
|
199 | /**
|
200 | * Returns the current center accessor, which defaults to a function returning [0, 0].
|
201 | */
|
202 | center(): (this: This, d: Datum, ...args: any[]) => [number, number];
|
203 | /**
|
204 | * Sets the circle center to the specified point [longitude, latitude] in degrees, and returns this circle generator.
|
205 | * The center may also be specified as a function; this function will be invoked whenever a circle is generated, being passed any arguments passed to the circle generator.
|
206 | */
|
207 | center(center: [number, number] | ((this: This, d: Datum, ...args: any[]) => [number, number])): this;
|
208 |
|
209 | /**
|
210 | * Returns the current radius accessor, which defaults to a function returning 90.
|
211 | */
|
212 | radius(): (this: This, d: Datum, ...args: any[]) => number;
|
213 | /**
|
214 | * Sets the circle radius to the specified angle in degrees, and returns this circle generator.
|
215 | * The radius may also be specified as a function; this function will be invoked whenever a circle is generated, being passed any arguments passed to the circle generator.
|
216 | */
|
217 | radius(radius: number | ((this: This, d: Datum, ...args: any[]) => number)): this;
|
218 |
|
219 | /**
|
220 | * Returns the current precision accessor, which defaults to a function returning 6.
|
221 | */
|
222 | precision(): (this: This, d: Datum, ...args: any[]) => number;
|
223 | /**
|
224 | * Sets the circle precision to the specified angle in degrees, and returns this circle generator.
|
225 | * The precision may also be specified as a function; this function will be invoked whenever a circle is generated, being passed any arguments passed to the circle generator.
|
226 | */
|
227 | precision(precision: number | ((this: This, d: Datum, ...args: any[]) => number)): this;
|
228 | }
|
229 |
|
230 | /**
|
231 | * Returns a new geo circle generator
|
232 | */
|
233 | export function geoCircle(): GeoCircleGenerator;
|
234 | /**
|
235 | * Returns a new geo circle generator
|
236 | *
|
237 | * The generic corresponds to the data type of the first argument passed into the geo circle generator and its accessor functions.
|
238 | */
|
239 | // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
|
240 | export function geoCircle<Datum>(): GeoCircleGenerator<any, Datum>;
|
241 | /**
|
242 | * Returns a new geo circle generator
|
243 | *
|
244 | * The first generic corresponds to the "this" context within which the geo circle generator and its accessors will be invoked.
|
245 | *
|
246 | * The second generic corresponds to the data type of the first argument passed into the geo circle generator and its accessor functions.
|
247 | */
|
248 | // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
|
249 | export function geoCircle<This, Datum>(): GeoCircleGenerator<This, Datum>;
|
250 |
|
251 | // geoGraticule ============================================================
|
252 |
|
253 | /**
|
254 | * A Feature generator for graticules: a uniform grid of meridians and parallels for showing projection distortion.
|
255 | * The default graticule has meridians and parallels every 10° between ±80° latitude; for the polar regions, there are meridians every 90°.
|
256 | */
|
257 | export interface GeoGraticuleGenerator {
|
258 | /**
|
259 | * Returns a GeoJSON MultiLineString geometry object representing all meridians and parallels for this graticule.
|
260 | */
|
261 | (): GeoJSON.MultiLineString;
|
262 |
|
263 | /**
|
264 | * Returns an array of GeoJSON LineString geometry objects, one for each meridian or parallel for this graticule.
|
265 | */
|
266 | lines(): GeoJSON.LineString[];
|
267 |
|
268 | /**
|
269 | * Returns a GeoJSON Polygon geometry object representing the outline of this graticule, i.e. along the meridians and parallels defining its extent.
|
270 | */
|
271 | outline(): GeoJSON.Polygon;
|
272 |
|
273 | /**
|
274 | * Returns the current minor extent, which defaults to ⟨⟨-180°, -80° - ε⟩, ⟨180°, 80° + ε⟩⟩.
|
275 | */
|
276 | extent(): [[number, number], [number, number]];
|
277 | /**
|
278 | * Sets the major and minor extents of this graticule.
|
279 | *
|
280 | * @param extent Extent to use for major and minor extent of graticule.
|
281 | */
|
282 | extent(extent: [[number, number], [number, number]]): this;
|
283 |
|
284 | /**
|
285 | * Returns the current major extent, which defaults to ⟨⟨-180°, -90° + ε⟩, ⟨180°, 90° - ε⟩⟩.
|
286 | */
|
287 | extentMajor(): [[number, number], [number, number]];
|
288 | /**
|
289 | * Sets the major extent of this graticule.
|
290 | *
|
291 | * @param extent Major extent of graticule.
|
292 | */
|
293 | extentMajor(extent: [[number, number], [number, number]]): this;
|
294 |
|
295 | /**
|
296 | * Returns the current minor extent, which defaults to ⟨⟨-180°, -80° - ε⟩, ⟨180°, 80° + ε⟩⟩.
|
297 | */
|
298 | extentMinor(): [[number, number], [number, number]];
|
299 | /**
|
300 | * Sets the minor extent of this graticule.
|
301 | *
|
302 | * @param extent Minor extent of graticule.
|
303 | */
|
304 | extentMinor(extent: [[number, number], [number, number]]): this;
|
305 |
|
306 | /**
|
307 | * Returns the current minor step, which defaults to ⟨10°, 10°⟩.
|
308 | */
|
309 | step(): [number, number];
|
310 | /**
|
311 | * Sets the major and minor step for this graticule
|
312 | *
|
313 | * @param step Major and minor step to use for this graticule.
|
314 | */
|
315 | step(step: [number, number]): this;
|
316 |
|
317 | /**
|
318 | * Returns the current major step, which defaults to ⟨90°, 360°⟩.
|
319 | */
|
320 | stepMajor(): [number, number];
|
321 | /**
|
322 | * Sets the major step for this graticule.
|
323 | *
|
324 | * @param step Major step.
|
325 | */
|
326 | stepMajor(step: [number, number]): this;
|
327 |
|
328 | /**
|
329 | * Returns the current major step, which defaults to ⟨10°, 10°⟩.
|
330 | */
|
331 | stepMinor(): [number, number];
|
332 | /**
|
333 | * Sets the minor step for this graticule.
|
334 | *
|
335 | * @param step Minor step.
|
336 | */
|
337 | stepMinor(step: [number, number]): this;
|
338 |
|
339 | /**
|
340 | * Returns the current precision, which defaults to 2.5°.
|
341 | */
|
342 | precision(): number;
|
343 | /**
|
344 | * Sets the precision for this graticule, in degrees.
|
345 | *
|
346 | * @param angle Precision in degrees.
|
347 | */
|
348 | precision(angle: number): this;
|
349 | }
|
350 |
|
351 | /**
|
352 | * Constructs a feature generator for creating graticules: a uniform grid of meridians and parallels for showing projection distortion.
|
353 | * The default graticule has meridians and parallels every 10° between ±80° latitude; for the polar regions, there are meridians every 90°.
|
354 | */
|
355 | export function geoGraticule(): GeoGraticuleGenerator;
|
356 |
|
357 | /**
|
358 | * A convenience method for directly generating the default 10° global graticule as a GeoJSON MultiLineString geometry object.
|
359 | */
|
360 | export function geoGraticule10(): GeoJSON.MultiLineString;
|
361 |
|
362 | // ----------------------------------------------------------------------
|
363 | // Projections
|
364 | // ----------------------------------------------------------------------
|
365 |
|
366 | /**
|
367 | * A D3 geo stream. D3 transforms geometry using a sequence of function calls, rather than materializing intermediate representations, to minimize overhead.
|
368 | * Streams must implement several methods to receive input geometry. Streams are inherently stateful; the meaning of a point depends on whether the point is inside of a line,
|
369 | * and likewise a line is distinguished from a ring by a polygon. Despite the name “stream”, these method calls are currently synchronous.
|
370 | */
|
371 | export interface GeoStream {
|
372 | /**
|
373 | * Indicates the end of a line or ring. Within a polygon, indicates the end of a ring.
|
374 | * Unlike GeoJSON, the redundant closing coordinate of a ring is not indicated via point, and instead is implied via lineEnd within a polygon.
|
375 | */
|
376 | lineEnd(): void;
|
377 |
|
378 | /**
|
379 | * Indicates the start of a line or ring. Within a polygon, indicates the start of a ring. The first ring of a polygon is the exterior ring, and is typically clockwise.
|
380 | * Any subsequent rings indicate holes in the polygon, and are typically counterclockwise.
|
381 | */
|
382 | lineStart(): void;
|
383 |
|
384 | /**
|
385 | * Indicates a point with the specified coordinates x and y (and optionally z). The coordinate system is unspecified and implementation-dependent;
|
386 | * for example, projection streams require spherical coordinates in degrees as input. Outside the context of a polygon or line,
|
387 | * a point indicates a point geometry object (Point or MultiPoint). Within a line or polygon ring, the point indicates a control point.
|
388 | *
|
389 | * @param x x-coordinate of point.
|
390 | * @param y y-coordinate of point.
|
391 | * @param z Optional z-coordinate of point.
|
392 | */
|
393 | point(x: number, y: number, z?: number): void;
|
394 |
|
395 | /**
|
396 | * Indicates the end of a polygon.
|
397 | */
|
398 | polygonEnd(): void;
|
399 |
|
400 | /**
|
401 | * Indicates the start of a polygon. The first line of a polygon indicates the exterior ring, and any subsequent lines indicate interior holes.
|
402 | */
|
403 | polygonStart(): void;
|
404 |
|
405 | /**
|
406 | * Indicates the sphere (the globe; the unit sphere centered at ⟨0,0,0⟩).
|
407 | */
|
408 | sphere?(): void;
|
409 | }
|
410 |
|
411 | // geoStream(...) =======================================================
|
412 |
|
413 | /**
|
414 | * Streams the specified GeoJSON object to the specified projection stream.
|
415 | * While both features and geometry objects are supported as input, the stream interface only describes the geometry, and thus additional feature properties are not visible to streams.
|
416 | */
|
417 | export function geoStream(
|
418 | object: ExtendedFeature | ExtendedFeatureCollection | GeoGeometryObjects | ExtendedGeometryCollection,
|
419 | stream: GeoStream,
|
420 | ): void;
|
421 |
|
422 | // ----------------------------------------------------------------------
|
423 | // Projections
|
424 | // ----------------------------------------------------------------------
|
425 |
|
426 | /**
|
427 | * Raw projections are point transformation functions that are used to implement custom projections; they typically passed to d3.geoProjection or d3.geoProjectionMutator.
|
428 | * They are exposed here to facilitate the derivation of related projections.
|
429 | * Raw projections take spherical coordinates [lambda, phi] in radians (not degrees!) and return a point [x, y], typically in the unit square centered around the origin.
|
430 | */
|
431 | export interface GeoRawProjection {
|
432 | /**
|
433 | * Projects the specified point [lambda, phi] in radians, returning a new point [x, y] in unitless coordinates.
|
434 | * @param lambda Spherical lambda coordinate in radians.
|
435 | * @param phi Spherical phi coordinate in radians.
|
436 | */
|
437 | (lambda: number, phi: number): [number, number];
|
438 |
|
439 | /**
|
440 | * Inverts the projected point [x, y] in unitless coordinates, returning an unprojected point in spherical coordinates [lambda, phi] in radians.
|
441 | * @param x x-coordinate (unitless).
|
442 | * @param y y-coordinate (unitless).
|
443 | */
|
444 | invert?(x: number, y: number): [number, number];
|
445 | }
|
446 |
|
447 | /**
|
448 | * An object implementing a stream method
|
449 | */
|
450 | export interface GeoStreamWrapper {
|
451 | /**
|
452 | * Returns a projection stream for the specified output stream. Any input geometry is projected before being streamed to the output stream.
|
453 | * A typical projection involves several geometry transformations: the input geometry is first converted to radians, rotated on three axes,
|
454 | * clipped to the small circle or cut along the antimeridian, and lastly projected to the plane with adaptive resampling, scale and translation.
|
455 | *
|
456 | * @param stream An input stream
|
457 | */
|
458 | stream(stream: GeoStream): GeoStream;
|
459 | }
|
460 |
|
461 | /**
|
462 | * A Geographic Projection to transform spherical polygonal geometry to planar polygonal geometry.
|
463 | * D3 provides implementations of several classes of standard projections:
|
464 | *
|
465 | * - Azimuthal
|
466 | * - Composite
|
467 | * - Conic
|
468 | * - Cylindrical
|
469 | *
|
470 | * For many more projections, see d3-geo-projection. You can implement custom projections using d3.geoProjection or d3.geoProjectionMutator.
|
471 | */
|
472 | export interface GeoProjection extends GeoStreamWrapper {
|
473 | /**
|
474 | * Returns a new array [x, y] (typically in pixels) representing the projected point of the given point.
|
475 | * The point must be specified as a two-element array [longitude, latitude] in degrees.
|
476 | * May return null if the specified point has no defined projected position, such as when the point is outside the clipping bounds of the projection.
|
477 | *
|
478 | * @param point A point specified as a two-dimensional array [longitude, latitude] in degrees.
|
479 | */
|
480 | (point: [number, number]): [number, number] | null;
|
481 |
|
482 | /**
|
483 | * Returns a new array [longitude, latitude] in degrees representing the unprojected point of the given projected point.
|
484 | * May return null if the specified point has no defined projected position, such as when the point is outside the clipping bounds of the projection.
|
485 | *
|
486 | * @param point The projected point, specified as a two-element array [x, y] (typically in pixels).
|
487 | */
|
488 | invert?(point: [number, number]): [number, number] | null;
|
489 |
|
490 | /**
|
491 | * Returns the current spherical clipping function.
|
492 | * Pre-clipping occurs in geographic coordinates. Cutting along the antimeridian line,
|
493 | * or clipping along a small circle are the most common strategies.
|
494 | */
|
495 | preclip(): (stream: GeoStream) => GeoStream;
|
496 | /**
|
497 | * Sets the projection’s spherical clipping to the specified function and returns the projection.
|
498 | * Pre-clipping occurs in geographic coordinates. Cutting along the antimeridian line, or clipping along a small circle are the most common strategies.
|
499 | *
|
500 | * @param preclip A spherical clipping function. Clipping functions are implemented as transformations of a projection stream.
|
501 | * Pre-clipping operates on spherical coordinates, in radians.
|
502 | */
|
503 | preclip(preclip: (stream: GeoStream) => GeoStream): this;
|
504 |
|
505 | /**
|
506 | * Returns the current cartesian clipping function.
|
507 | * Post-clipping occurs on the plane, when a projection is bounded to a certain extent such as a rectangle.
|
508 | */
|
509 | postclip(): (stream: GeoStream) => GeoStream;
|
510 | /**
|
511 | * Sets the projection’s cartesian clipping to the specified function and returns the projection.
|
512 | *
|
513 | * @param postclip A cartesian clipping function. Clipping functions are implemented as transformations of a projection stream.
|
514 | * Post-clipping operates on planar coordinates, in pixels.
|
515 | */
|
516 | postclip(postclip: (stream: GeoStream) => GeoStream): this;
|
517 |
|
518 | /**
|
519 | * Returns the current clip angle which defaults to null.
|
520 | *
|
521 | * null switches to antimeridian cutting rather than small-circle clipping.
|
522 | */
|
523 | clipAngle(): number | null;
|
524 | /**
|
525 | * Sets the projection’s clipping circle radius to the specified angle in degrees and returns the projection.
|
526 | * If angle is null, switches to antimeridian cutting rather than small-circle clipping.
|
527 | */
|
528 | clipAngle(angle: null | number): this;
|
529 |
|
530 | /**
|
531 | * Returns the current viewport clip extent which defaults to null.
|
532 | */
|
533 | clipExtent(): [[number, number], [number, number]] | null;
|
534 | /**
|
535 | * Sets the projection’s viewport clip extent to the specified bounds in pixels and returns the projection.
|
536 | * The extent bounds are specified as an array [[x₀, y₀], [x₁, y₁]], where x₀ is the left-side of the viewport, y₀ is the top, x₁ is the right and y₁ is the bottom.
|
537 | * If extent is null, no viewport clipping is performed.
|
538 | */
|
539 | clipExtent(extent: null | [[number, number], [number, number]]): this;
|
540 |
|
541 | /**
|
542 | * Returns the current scale factor; the default scale is projection-specific.
|
543 | *
|
544 | * The scale factor corresponds linearly to the distance between projected points; however, absolute scale factors are not equivalent across projections.
|
545 | */
|
546 | scale(): number;
|
547 | /**
|
548 | * Sets the projection’s scale factor to the specified value and returns the projection.
|
549 | * The scale factor corresponds linearly to the distance between projected points; however, absolute scale factors are not equivalent across projections.
|
550 | *
|
551 | * @param scale Scale factor to be used for the projection; the default scale is projection-specific.
|
552 | */
|
553 | scale(scale: number): this;
|
554 |
|
555 | /**
|
556 | * Returns the current translation offset which defaults to [480, 250] and places ⟨0°,0°⟩ at the center of a 960×500 area.
|
557 | * The translation offset determines the pixel coordinates of the projection’s center.
|
558 | */
|
559 | translate(): [number, number];
|
560 | /**
|
561 | * Sets the projection’s translation offset to the specified two-element array [tx, ty] and returns the projection.
|
562 | * The translation offset determines the pixel coordinates of the projection’s center. The default translation offset places ⟨0°,0°⟩ at the center of a 960×500 area.
|
563 | *
|
564 | * @param point A two-element array [tx, ty] specifying the translation offset. The default translation offset of defaults to [480, 250] places ⟨0°,0°⟩ at the center of a 960×500 area.
|
565 | */
|
566 | translate(point: [number, number]): this;
|
567 |
|
568 | /**
|
569 | * Returns the current center of the projection, which defaults to ⟨0°,0°⟩.
|
570 | */
|
571 | center(): [number, number];
|
572 | /**
|
573 | * Sets the projection’s center to the specified center,
|
574 | * a two-element array of longitude and latitude in degrees and returns the projection.
|
575 | * The default is ⟨0°,0°⟩.
|
576 | *
|
577 | * @param point A point specified as a two-dimensional array [longitude, latitude] in degrees.
|
578 | */
|
579 | center(point: [number, number]): this;
|
580 |
|
581 | /**
|
582 | * Returns the projection’s current angle, which defaults to 0°.
|
583 | */
|
584 | angle(): number;
|
585 | /**
|
586 | * Sets the projection’s post-projection planar rotation angle to the specified angle in degrees and returns the projection.
|
587 | * @param angle The new rotation angle of the projection.
|
588 | */
|
589 | angle(angle: number): this;
|
590 |
|
591 | /**
|
592 | * Returns true if x-reflection is enabled, which defaults to false.
|
593 | */
|
594 | reflectX(): boolean;
|
595 | /**
|
596 | * Sets whether or not the x-dimension is reflected (negated) in the output.
|
597 | * @param reflect Whether or not the x-dimension is reflected (negated) in the output.
|
598 | */
|
599 | reflectX(reflect: boolean): this;
|
600 |
|
601 | /**
|
602 | * Returns true if y-reflection is enabled, which defaults to false.
|
603 | */
|
604 | reflectY(): boolean;
|
605 | /**
|
606 | * Sets whether or not the y-dimension is reflected (negated) in the output.
|
607 | * @param reflect Whether or not the y-dimension is reflected (negated) in the output.
|
608 | */
|
609 | reflectY(reflect: boolean): this;
|
610 |
|
611 | /**
|
612 | * Returns the current rotation [lambda, phi, gamma] specifying the rotation angles in degrees about each spherical axis.
|
613 | * (These correspond to yaw, pitch and roll.) which defaults [0, 0, 0].
|
614 | */
|
615 | rotate(): [number, number, number];
|
616 |
|
617 | /**
|
618 | * Sets the projection’s three-axis rotation to the specified angles, which must be a two- or three-element array of numbers.
|
619 | *
|
620 | * @param angles A two- or three-element array of numbers [lambda, phi, gamma] specifying the rotation angles in degrees about each spherical axis.
|
621 | * (These correspond to yaw, pitch and roll.) If the rotation angle gamma is omitted, it defaults to 0.
|
622 | */
|
623 | rotate(angles: [number, number] | [number, number, number]): this;
|
624 |
|
625 | /**
|
626 | * Returns the projection’s current resampling precision which defaults to square root of 0.5.
|
627 | * This value corresponds to the Douglas–Peucker distance.
|
628 | */
|
629 | precision(): number;
|
630 | /**
|
631 | * Sets the threshold for the projection’s adaptive resampling to the specified value in pixels and returns the projection.
|
632 | * This value corresponds to the Douglas–Peucker distance.
|
633 | *
|
634 | * @param precision A numeric value in pixels to use as the threshold for the projection’s adaptive resampling.
|
635 | */
|
636 | precision(precision: number): this;
|
637 |
|
638 | /**
|
639 | * Sets the projection’s scale and translate to fit the specified GeoJSON object in the center of the given extent.
|
640 | * The extent is specified as an array [[x₀, y₀], [x₁, y₁]], where x₀ is the left side of the bounding box, y₀ is the top, x₁ is the right and y₁ is the bottom.
|
641 | * Returns the projection.
|
642 | */
|
643 | fitExtent(
|
644 | extent: [[number, number], [number, number]],
|
645 | object: ExtendedFeature | ExtendedFeatureCollection | GeoGeometryObjects | ExtendedGeometryCollection,
|
646 | ): this;
|
647 |
|
648 | /**
|
649 | * A convenience method for projection.fitExtent where the top-left corner of the extent is [0, 0].
|
650 | */
|
651 | fitSize(
|
652 | size: [number, number],
|
653 | object: ExtendedFeature | ExtendedFeatureCollection | GeoGeometryObjects | ExtendedGeometryCollection,
|
654 | ): this;
|
655 |
|
656 | /**
|
657 | * A convenience method for projection.fitSize where the height is automatically chosen from the aspect ratio of object and the given constraint on width.
|
658 | */
|
659 | fitWidth(
|
660 | width: number,
|
661 | object: ExtendedFeature | ExtendedFeatureCollection | GeoGeometryObjects | ExtendedGeometryCollection,
|
662 | ): this;
|
663 |
|
664 | /**
|
665 | * A convenience method for projection.fitSize where the width is automatically chosen from the aspect ratio of object and the given constraint on height.
|
666 | */
|
667 | fitHeight(
|
668 | height: number,
|
669 | object: ExtendedFeature | ExtendedFeatureCollection | GeoGeometryObjects | ExtendedGeometryCollection,
|
670 | ): this;
|
671 | }
|
672 |
|
673 | /**
|
674 | * A Conic Projection
|
675 | */
|
676 | export interface GeoConicProjection extends GeoProjection {
|
677 | /**
|
678 | * Return the standard parallels for the conic projection in degrees.
|
679 | */
|
680 | parallels(): [number, number];
|
681 | /**
|
682 | * Set the standard parallels for the conic projection in degrees and return the projection.
|
683 | *
|
684 | * @param value A two-dimensional array representing the standard parallels in degrees.
|
685 | */
|
686 | parallels(value: [number, number]): this;
|
687 | }
|
688 |
|
689 | // geoPath ==============================================================
|
690 |
|
691 | /**
|
692 | * A minimal rendering context for a GeoPath generator. The minimum implemented
|
693 | * methods are a subset of the CanvasRenderingContext2D API.
|
694 | *
|
695 | * For reference to the CanvasRenderingContext2D see https://developer.mozilla.org/en/docs/Web/API/CanvasRenderingContext2D
|
696 | */
|
697 | export interface GeoContext {
|
698 | /**
|
699 | * Adds an arc to the path with center point (x, y) and radius r starting at startAngle and ending at endAngle.
|
700 | * The arc is drawn in clockwise direction by default.
|
701 | *
|
702 | * @param x x-coordinate of arc center point.
|
703 | * @param y y-coordinate of arc center point.
|
704 | * @param radius Radius of arc.
|
705 | * @param startAngle The starting angle of the arc, measured clockwise from the positive x axis and expressed in radians.
|
706 | * @param endAngle The end angle of the arc, measured clockwise from the positive x axis and expressed in radians.
|
707 | * @param anticlockwise Optional boolean flag, if true the arc is drawn counter-clockwise between the two angles.
|
708 | */
|
709 | arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void;
|
710 |
|
711 | /**
|
712 | * Start a new path by emptying the list of sub-paths.
|
713 | */
|
714 | beginPath(): void;
|
715 |
|
716 | /**
|
717 | * Causes the point of the pen to move back to the start of the current sub-path.
|
718 | * It tries to draw a straight line from the current point to the start.
|
719 | * If the shape has already been closed or has only one point, this function does nothing.
|
720 | */
|
721 | closePath(): void;
|
722 |
|
723 | /**
|
724 | * Connects the last point in the sub-path to the x, y coordinates with a straight line (but does not actually draw it).
|
725 | *
|
726 | * @param x The x-coordinate for the end of the line.
|
727 | * @param y The y-coordinate for the end of the line.
|
728 | */
|
729 | lineTo(x: number, y: number): void;
|
730 |
|
731 | /**
|
732 | * Move the starting point of a new sub-path to the (x, y) coordinates.
|
733 | *
|
734 | * @param x The x-coordinate for the new starting point.
|
735 | * @param y The y-coordinate for the new starting point.
|
736 | */
|
737 | moveTo(x: number, y: number): void;
|
738 | }
|
739 |
|
740 | /**
|
741 | * A Geo Path generator
|
742 | *
|
743 | * The first generic corresponds to the "this"-context within which the geo path generator will be invoked.
|
744 | * This could be e.g. the DOMElement bound to "this" when using selection.attr("d", ...) with the path generator.
|
745 | *
|
746 | * The second generic corresponds to the type of the DatumObject which will be passed into the geo path generator for rendering.
|
747 | */
|
748 | export interface GeoPath<This = any, DatumObject extends GeoPermissibleObjects = GeoPermissibleObjects> {
|
749 | /**
|
750 | * Renders the given object, which may be any GeoJSON feature or geometry object:
|
751 | *
|
752 | * + Point - a single position.
|
753 | * + MultiPoint - an array of positions.
|
754 | * + LineString - an array of positions forming a continuous line.
|
755 | * + MultiLineString - an array of arrays of positions forming several lines.
|
756 | * + Polygon - an array of arrays of positions forming a polygon (possibly with holes).
|
757 | * + MultiPolygon - a multidimensional array of positions forming multiple polygons.
|
758 | * + GeometryCollection - an array of geometry objects.
|
759 | * + Feature - a feature containing one of the above geometry objects.
|
760 | * + FeatureCollection - an array of feature objects.
|
761 | *
|
762 | * The type Sphere is also supported, which is useful for rendering the outline of the globe; a sphere has no coordinates.
|
763 | *
|
764 | * Any additional arguments are passed along to the pointRadius accessor.
|
765 | *
|
766 | * IMPORTANT: If the rendering context of the geoPath generator is null,
|
767 | * then the geoPath is returned as an SVG path data string.
|
768 | *
|
769 | * Separate path elements are typically slower than a single path element. However, distinct path elements are useful for styling and interaction (e.g., click or mouseover).
|
770 | * Canvas rendering (see path.context) is typically faster than SVG, but requires more effort to implement styling and interaction.
|
771 | *
|
772 | * The first generic type of the GeoPath generator used, must correspond to the "this" context bound to the function upon invocation.
|
773 | *
|
774 | * @param object An object to be rendered.
|
775 | */
|
776 | (this: This, object: DatumObject, ...args: any[]): string | null;
|
777 | /**
|
778 | * Renders the given object, which may be any GeoJSON feature or geometry object:
|
779 | *
|
780 | * + Point - a single position.
|
781 | * + MultiPoint - an array of positions.
|
782 | * + LineString - an array of positions forming a continuous line.
|
783 | * + MultiLineString - an array of arrays of positions forming several lines.
|
784 | * + Polygon - an array of arrays of positions forming a polygon (possibly with holes).
|
785 | * + MultiPolygon - a multidimensional array of positions forming multiple polygons.
|
786 | * + GeometryCollection - an array of geometry objects.
|
787 | * + Feature - a feature containing one of the above geometry objects.
|
788 | * + FeatureCollection - an array of feature objects.
|
789 | *
|
790 | * The type Sphere is also supported, which is useful for rendering the outline of the globe; a sphere has no coordinates.
|
791 | *
|
792 | * Any additional arguments are passed along to the pointRadius accessor.
|
793 | *
|
794 | * IMPORTANT: If the geoPath generator has been configured with a rendering context,
|
795 | * then the geoPath is rendered to this context as a sequence of path method calls and this function returns void.
|
796 | *
|
797 | * Separate path elements are typically slower than a single path element. However, distinct path elements are useful for styling and interaction (e.g., click or mouseover).
|
798 | * Canvas rendering (see path.context) is typically faster than SVG, but requires more effort to implement styling and interaction.
|
799 | *
|
800 | * The first generic type of the GeoPath generator used, must correspond to the "this" context bound to the function upon invocation.
|
801 | *
|
802 | * @param object An object to be rendered.
|
803 | */
|
804 | (this: This, object: DatumObject, ...args: any[]): void;
|
805 |
|
806 | /**
|
807 | * Returns the projected planar area (typically in square pixels) for the specified GeoJSON object.
|
808 | * Point, MultiPoint, LineString and MultiLineString geometries have zero area. For Polygon and MultiPolygon geometries,
|
809 | * this method first computes the area of the exterior ring, and then subtracts the area of any interior holes.
|
810 | * This method observes any clipping performed by the projection; see projection.clipAngle and projection.clipExtent. This is the planar equivalent of d3.geoArea.
|
811 | *
|
812 | * @param object An object for which the area is to be calculated.
|
813 | */
|
814 | area(object: DatumObject): number;
|
815 |
|
816 | /**
|
817 | * Returns the projected planar bounding box (typically in pixels) for the specified GeoJSON object.
|
818 | * The bounding box is represented by a two-dimensional array: [[x₀, y₀], [x₁, y₁]], where x₀ is the minimum x-coordinate, y₀ is the minimum y-coordinate,
|
819 | * x₁ is maximum x-coordinate, and y₁ is the maximum y-coordinate.
|
820 | *
|
821 | * This is handy for, say, zooming in to a particular feature. (Note that in projected planar coordinates,
|
822 | * the minimum latitude is typically the maximum y-value, and the maximum latitude is typically the minimum y-value.)
|
823 | * This method observes any clipping performed by the projection; see projection.clipAngle and projection.clipExtent. This is the planar equivalent of d3.geoBounds.
|
824 | *
|
825 | * @param object An object for which the bounds are to be calculated.
|
826 | */
|
827 | bounds(object: DatumObject): [[number, number], [number, number]];
|
828 |
|
829 | /**
|
830 | * Returns the projected planar centroid (typically in pixels) for the specified GeoJSON object.
|
831 | * This is handy for, say, labeling state or county boundaries, or displaying a symbol map.
|
832 | * For example, a noncontiguous cartogram might scale each state around its centroid.
|
833 | * This method observes any clipping performed by the projection; see projection.clipAngle and projection.clipExtent. This is the planar equivalent of d3.geoCentroid.
|
834 | *
|
835 | * @param object An object for which the centroid is to be calculated.
|
836 | */
|
837 | centroid(object: DatumObject): [number, number];
|
838 |
|
839 | /**
|
840 | * Returns the projected planar length (typically in pixels) for the specified GeoJSON object.
|
841 | * Point and MultiPoint geometries have zero length. For Polygon and MultiPolygon geometries, this method computes the summed length of all rings.
|
842 | *
|
843 | * This method observes any clipping performed by the projection; see projection.clipAngle and projection.clipExtent. This is the planar equivalent of d3.geoLength.
|
844 | *
|
845 | * @param object An object for which the measure is to be calculated.
|
846 | */
|
847 | measure(object: DatumObject): number;
|
848 |
|
849 | /**
|
850 | * Returns the current render context which defaults to null.
|
851 | *
|
852 | * Use the generic to cast the return type of the rendering context, if it is known for a specific application.
|
853 | */
|
854 | // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
|
855 | context<C extends GeoContext | null>(): C;
|
856 |
|
857 | /**
|
858 | * sets the current render context and returns the path generator.
|
859 | * If the context is null, then the path generator will return an SVG path string;
|
860 | * if the context is non-null, the path generator will instead call methods on the specified context to render geometry.
|
861 | */
|
862 | context(context: null | GeoContext): this;
|
863 |
|
864 | /**
|
865 | * Get the current projection. The generic parameter can be used to cast the result to the
|
866 | * correct, known type of the projection, e.g. GeoProjection or GeoConicProjection. Otherwise,
|
867 | * the return type defaults to the minimum type requirement for a projection which
|
868 | * can be passed into a GeoPath.
|
869 | *
|
870 | * Use the generic to cast the return type of the projection, if it is known for a specific application.
|
871 | */
|
872 | // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
|
873 | projection<P extends GeoConicProjection | GeoProjection | GeoStreamWrapper | null>(): P;
|
874 |
|
875 | /**
|
876 | * Sets the current projection to the specified projection.
|
877 | * The null projection represents the identity transformation: the input geometry is not projected and is instead rendered directly in raw coordinates.
|
878 | * This can be useful for fast rendering of pre-projected geometry, or for fast rendering of the equirectangular projection.
|
879 | */
|
880 | projection(projection: null | GeoProjection | GeoStreamWrapper): this;
|
881 |
|
882 | /**
|
883 | * Returns the current radius or radius accessor used to determine the radius for the display of Point and MultiPoint geometries.
|
884 | * The default is a constant radius of 4.5.
|
885 | */
|
886 | pointRadius(): ((this: This, object: DatumObject, ...args: any[]) => number) | number;
|
887 |
|
888 | /**
|
889 | * Sets the radius used to display Point and MultiPoint geometries to the specified number.
|
890 | * While the radius is commonly specified as a number constant, it may also be specified as a function which is computed per feature, being passed the any arguments passed to the path generator.
|
891 | * For example, if your GeoJSON data has additional properties, you might access those properties inside the radius function to vary the point size;
|
892 | * alternatively, you could d3.symbol and a projection for greater flexibility.
|
893 | */
|
894 | pointRadius(value: number | ((this: This, object: DatumObject, ...args: any[]) => number)): this;
|
895 |
|
896 | /**
|
897 | * Returns the current number of digits, which defaults to 3.
|
898 | */
|
899 | digits(): number;
|
900 | /**
|
901 | * Sets the number of fractional digits for coordinates generated in SVG path strings.
|
902 | * @param digits New amount of digits
|
903 | */
|
904 | digits(digits: number): this;
|
905 | }
|
906 |
|
907 | /**
|
908 | * Creates a new geographic path generator.
|
909 | *
|
910 | * The default projection is the null projection. The null projection represents the identity transformation, i.e.
|
911 | * the input geometry is not projected and is instead rendered directly in raw coordinates.
|
912 | * This can be useful for fast rendering of pre-projected geometry, or for fast rendering of the equirectangular projection.
|
913 | *
|
914 | * The default context is null, which implies that the path generator will return an SVG path string.
|
915 | *
|
916 | * @param projection An (optional) current projection to be used. Typically this is one of D3’s built-in geographic projections;
|
917 | * however, any object that exposes a projection.stream function can be used, enabling the use of custom projections.
|
918 | * See D3’s transforms for more examples of arbitrary geometric transformations. Setting the projection to "null" uses the identity projection. The default value is "null", the identity projection.
|
919 | * @param context An (optional) rendering context to be used. If a context is provided, it must at least implement the interface described by GeoContext, a subset of the CanvasRenderingContext2D API.
|
920 | * Setting the context to "null" means that the path generator will return an SVG path string representing the to be rendered object. The default is "null".
|
921 | */
|
922 | export function geoPath(projection?: GeoProjection | GeoStreamWrapper | null, context?: GeoContext | null): GeoPath;
|
923 | /**
|
924 | * Creates a new geographic path generator with the default settings.
|
925 | *
|
926 | * The default projection is the null projection. The null projection represents the identity transformation:
|
927 | * the input geometry is not projected and is instead rendered directly in raw coordinates.
|
928 | * This can be useful for fast rendering of pre-projected geometry, or for fast rendering of the equirectangular projection.
|
929 | *
|
930 | * The default context is null, which implies that the path generator will return an SVG path string.
|
931 | *
|
932 | * The generic corresponds to the type of the DatumObject which will be passed into the geo path generator for rendering
|
933 | *
|
934 | * @param projection An (optional) current projection to be used. Typically this is one of D3’s built-in geographic projections;
|
935 | * however, any object that exposes a projection.stream function can be used, enabling the use of custom projections.
|
936 | * See D3’s transforms for more examples of arbitrary geometric transformations. Setting the projection to "null" uses the identity projection. The default value is "null", the identity projection.
|
937 | * @param context An (optional) rendering context to be used. If a context is provided, it must at least implement the interface described by GeoContext, a subset of the CanvasRenderingContext2D API.
|
938 | * Setting the context to "null" means that the path generator will return an SVG path string representing the to be rendered object. The default is "null".
|
939 | */
|
940 | // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
|
941 | export function geoPath<DatumObject extends GeoPermissibleObjects>(
|
942 | projection?: GeoProjection | GeoStreamWrapper | null,
|
943 | context?: GeoContext | null,
|
944 | ): GeoPath<any, DatumObject>;
|
945 | /**
|
946 | * Creates a new geographic path generator with the default settings.
|
947 | *
|
948 | * The default projection is the null projection. The null projection represents the identity transformation:
|
949 | * the input geometry is not projected and is instead rendered directly in raw coordinates.
|
950 | * This can be useful for fast rendering of pre-projected geometry, or for fast rendering of the equirectangular projection.
|
951 | *
|
952 | * The default context is null, which implies that the path generator will return an SVG path string.
|
953 | *
|
954 | * The first generic corresponds to the "this"-context within which the geo path generator will be invoked.
|
955 | * This could be e.g. the DOMElement bound to "this" when using selection.attr("d", ...) with the path generator.
|
956 | *
|
957 | * The second generic corresponds to the type of the DatumObject which will be passed into the geo path generator for rendering.
|
958 | *
|
959 | * @param projection An (optional) current projection to be used. Typically this is one of D3’s built-in geographic projections;
|
960 | * however, any object that exposes a projection.stream function can be used, enabling the use of custom projections.
|
961 | * See D3’s transforms for more examples of arbitrary geometric transformations. Setting the projection to "null" uses the identity projection. The default value is "null", the identity projection.
|
962 | * @param context An (optional) rendering context to be used. If a context is provided, it must at least implement the interface described by GeoContext, a subset of the CanvasRenderingContext2D API.
|
963 | * Setting the context to "null" means that the path generator will return an SVG path string representing the to be rendered object. The default is "null".
|
964 | */
|
965 | // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
|
966 | export function geoPath<This, DatumObject extends GeoPermissibleObjects>(
|
967 | projection?: GeoProjection | GeoStreamWrapper | null,
|
968 | context?: GeoContext | null,
|
969 | ): GeoPath<This, DatumObject>;
|
970 |
|
971 | // geoProjection ==========================================================
|
972 |
|
973 | /**
|
974 | * Constructs a new projection from the specified raw projection, project.
|
975 | * The project function takes the longitude and latitude of a given point in radians,
|
976 | * often referred to as lambda (λ) and phi (φ), and returns a two-element array [x, y] representing its unit projection.
|
977 | * The project function does not need to scale or translate the point, as these are applied automatically by projection.scale, projection.translate, and projection.center.
|
978 | * Likewise, the project function does not need to perform any spherical rotation, as projection.rotate is applied prior to projection.
|
979 | *
|
980 | * If the project function exposes an invert method, the returned projection will also expose projection.invert.
|
981 | */
|
982 | export function geoProjection(project: GeoRawProjection): GeoProjection;
|
983 |
|
984 | // geoProjectionMutator ====================================================
|
985 |
|
986 | /**
|
987 | * Constructs a new projection from the specified raw projection factory and returns a mutate function to call whenever the raw projection changes.
|
988 | * The factory must return a raw projection. The returned mutate function returns the wrapped projection.
|
989 | *
|
990 | * When creating a mutable projection, the mutate function is typically not exposed.
|
991 | */
|
992 | export function geoProjectionMutator(factory: (...args: any[]) => GeoRawProjection): () => GeoProjection;
|
993 |
|
994 | // Pre-Defined Projections and Raw Projections =============================
|
995 |
|
996 | // Azimuthal Projections ---------------------------------------------------
|
997 |
|
998 | /**
|
999 | * The azimuthal equal-area projection.
|
1000 | */
|
1001 | export function geoAzimuthalEqualArea(): GeoProjection;
|
1002 |
|
1003 | /**
|
1004 | * The raw azimuthal equal-area projection.
|
1005 | */
|
1006 | export function geoAzimuthalEqualAreaRaw(): GeoRawProjection;
|
1007 |
|
1008 | /**
|
1009 | * The azimuthal equidistant projection.
|
1010 | */
|
1011 | export function geoAzimuthalEquidistant(): GeoProjection;
|
1012 | /**
|
1013 | * The raw azimuthal equidistant projection.
|
1014 | */
|
1015 | export function geoAzimuthalEquidistantRaw(): GeoRawProjection;
|
1016 |
|
1017 | /**
|
1018 | * The gnomonic projection.
|
1019 | */
|
1020 | export function geoGnomonic(): GeoProjection;
|
1021 |
|
1022 | /**
|
1023 | * The raw gnomonic projection.
|
1024 | */
|
1025 | export function geoGnomonicRaw(): GeoRawProjection;
|
1026 |
|
1027 | /**
|
1028 | * The orthographic projection.
|
1029 | */
|
1030 | export function geoOrthographic(): GeoProjection;
|
1031 |
|
1032 | /**
|
1033 | * The raw orthographic projection.
|
1034 | */
|
1035 | export function geoOrthographicRaw(): GeoRawProjection;
|
1036 |
|
1037 | /**
|
1038 | * The stereographic projection.
|
1039 | */
|
1040 | export function geoStereographic(): GeoProjection;
|
1041 |
|
1042 | /**
|
1043 | * The raw stereographic projection.
|
1044 | */
|
1045 | export function geoStereographicRaw(): GeoRawProjection;
|
1046 |
|
1047 | /**
|
1048 | * The Equal Eartch projection, by Bojan Šavrič et al., 2018.
|
1049 | */
|
1050 | export function geoEqualEarth(): GeoProjection;
|
1051 |
|
1052 | /**
|
1053 | * The raw Equal Earth projection, by Bojan Šavrič et al., 2018.
|
1054 | */
|
1055 | export function geoEqualEarthRaw(): GeoRawProjection;
|
1056 |
|
1057 | // Composite Projections ---------------------------------------------------
|
1058 |
|
1059 | /**
|
1060 | * A U.S.-centric composite projection of three d3.geoConicEqualArea projections: d3.geoAlbers is used for the lower forty-eight states,
|
1061 | * and separate conic equal-area projections are used for Alaska and Hawaii. Note that the scale for Alaska is diminished: it is projected at 0.35× its true relative area.
|
1062 | *
|
1063 | * Composite consist of several projections that are composed into a single display. The constituent projections have fixed clip, center and rotation,
|
1064 | * and thus composite projections do not support projection.center, projection.rotate, projection.clipAngle, or projection.clipExtent.
|
1065 | */
|
1066 | export function geoAlbersUsa(): GeoProjection;
|
1067 |
|
1068 | // Conic Projections -------------------------------------------------------
|
1069 |
|
1070 | /**
|
1071 | * The Albers’ equal area-conic projection. This is a U.S.-centric configuration of d3.geoConicEqualArea.
|
1072 | */
|
1073 | export function geoAlbers(): GeoConicProjection;
|
1074 |
|
1075 | /**
|
1076 | * The conic conformal projection. The parallels default to [30°, 30°] resulting in flat top.
|
1077 | */
|
1078 | export function geoConicConformal(): GeoConicProjection;
|
1079 |
|
1080 | /**
|
1081 | * The raw conic conformal projection.
|
1082 | */
|
1083 | export function geoConicConformalRaw(phi0: number, phi1: number): GeoRawProjection;
|
1084 |
|
1085 | /**
|
1086 | * The Albers’ equal-area conic projection.
|
1087 | */
|
1088 | export function geoConicEqualArea(): GeoConicProjection;
|
1089 |
|
1090 | /**
|
1091 | * The raw Albers’ equal-area conic projection.
|
1092 | */
|
1093 | export function geoConicEqualAreaRaw(phi0: number, phi1: number): GeoRawProjection;
|
1094 |
|
1095 | /**
|
1096 | * The conic equidistant projection.
|
1097 | */
|
1098 | export function geoConicEquidistant(): GeoConicProjection;
|
1099 |
|
1100 | /**
|
1101 | * The raw conic equidistant projection.
|
1102 | */
|
1103 | export function geoConicEquidistantRaw(phi0: number, phi1: number): GeoRawProjection;
|
1104 |
|
1105 | // Cylindrical Projections ------------------------------------------------
|
1106 |
|
1107 | /**
|
1108 | * The equirectangular (plate carrée) projection.
|
1109 | */
|
1110 | export function geoEquirectangular(): GeoProjection;
|
1111 |
|
1112 | /**
|
1113 | * The raw equirectangular (plate carrée) projection.
|
1114 | */
|
1115 | export function geoEquirectangularRaw(): GeoRawProjection;
|
1116 |
|
1117 | /**
|
1118 | * The spherical Mercator projection.
|
1119 | * Defines a default projection.clipExtent such that the world is projected to a square, clipped to approximately ±85° latitude.
|
1120 | */
|
1121 | export function geoMercator(): GeoProjection;
|
1122 | /**
|
1123 | * The raw spherical Mercator projection.
|
1124 | */
|
1125 | export function geoMercatorRaw(): GeoRawProjection;
|
1126 |
|
1127 | /**
|
1128 | * The transverse spherical Mercator projection.
|
1129 | * Defines a default projection.clipExtent such that the world is projected to a square, clipped to approximately ±85° latitude.
|
1130 | */
|
1131 | export function geoTransverseMercator(): GeoProjection;
|
1132 |
|
1133 | /**
|
1134 | * The raw transverse spherical Mercator projection.
|
1135 | */
|
1136 | export function geoTransverseMercatorRaw(): GeoRawProjection;
|
1137 |
|
1138 | /**
|
1139 | * The Natural Earth projection is a pseudocylindrical projection designed by Tom Patterson. It is neither conformal nor equal-area, but appealing to the eye for small-scale maps of the whole world.
|
1140 | */
|
1141 | export function geoNaturalEarth1(): GeoProjection;
|
1142 |
|
1143 | /**
|
1144 | * The raw pseudo-cylindircal Natural Earth projection.
|
1145 | */
|
1146 | export function geoNaturalEarth1Raw(): GeoRawProjection;
|
1147 |
|
1148 | // ----------------------------------------------------------------------
|
1149 | // Projection Transforms
|
1150 | // ----------------------------------------------------------------------
|
1151 |
|
1152 | // geoTransform(...) ====================================================
|
1153 |
|
1154 | /**
|
1155 | * A Prototype interface which serves as a template for the implementation of a geometric transform using geoTransform(...)
|
1156 | * It serves as a reference for the custom methods which can be passed into geoTransform as argument to crete a generalized
|
1157 | * transform projection.
|
1158 | */
|
1159 | export interface GeoTransformPrototype {
|
1160 | /**
|
1161 | * Indicates the end of a line or ring. Within a polygon, indicates the end of a ring.
|
1162 | * Unlike GeoJSON, the redundant closing coordinate of a ring is not indicated via point, and instead is implied via lineEnd within a polygon.
|
1163 | */
|
1164 | lineEnd?(this: this & { stream: GeoStream }): void;
|
1165 | /**
|
1166 | * Indicates the start of a line or ring. Within a polygon, indicates the start of a ring. The first ring of a polygon is the exterior ring, and is typically clockwise.
|
1167 | * Any subsequent rings indicate holes in the polygon, and are typically counterclockwise.
|
1168 | */
|
1169 | lineStart?(this: this & { stream: GeoStream }): void;
|
1170 | /**
|
1171 | * Indicates a point with the specified coordinates x and y (and optionally z). The coordinate system is unspecified and implementation-dependent;
|
1172 | * for example, projection streams require spherical coordinates in degrees as input. Outside the context of a polygon or line,
|
1173 | * a point indicates a point geometry object (Point or MultiPoint). Within a line or polygon ring, the point indicates a control point.
|
1174 | *
|
1175 | * @param x x-coordinate of point.
|
1176 | * @param y y-coordinate of point.
|
1177 | * @param z Optional z-coordinate of point.
|
1178 | */
|
1179 | point?(this: this & { stream: GeoStream }, x: number, y: number, z?: number): void;
|
1180 | /**
|
1181 | * Indicates the end of a polygon.
|
1182 | */
|
1183 | polygonEnd?(this: this & { stream: GeoStream }): void;
|
1184 | /**
|
1185 | * Indicates the start of a polygon. The first line of a polygon indicates the exterior ring, and any subsequent lines indicate interior holes.
|
1186 | */
|
1187 | polygonStart?(this: this & { stream: GeoStream }): void;
|
1188 | /**
|
1189 | * Indicates the sphere (the globe; the unit sphere centered at ⟨0,0,0⟩).
|
1190 | */
|
1191 | sphere?(this: this & { stream: GeoStream }): void;
|
1192 | }
|
1193 |
|
1194 | // TODO: Review whether GeoStreamWrapper should be included into return value union type, i.e. ({ stream: (s: GeoStream) => (T & GeoStream & GeoStreamWrapper)})?
|
1195 | // It probably should be omitted for purposes of this API. The stream method added to (T & GeoStream) is more of a private member used internally to
|
1196 | // implement the Transform factory
|
1197 |
|
1198 | /**
|
1199 | * Defines an arbitrary transform using the methods defined on the specified methods object.
|
1200 | * Any undefined methods will use pass-through methods that propagate inputs to the output stream.
|
1201 | *
|
1202 | * @param methods An object with custom method implementations, which are used to create a transform projection.
|
1203 | */
|
1204 | export function geoTransform<T extends GeoTransformPrototype>(methods: T): { stream(s: GeoStream): T & GeoStream };
|
1205 |
|
1206 | // geoIdentity() =================================================================
|
1207 |
|
1208 | /**
|
1209 | * @deprecated Misspelled name. Use GeoIdentityTransform.
|
1210 | */
|
1211 | export type GeoIdentityTranform = GeoIdentityTransform;
|
1212 |
|
1213 | /**
|
1214 | * Geo Identity Transform
|
1215 | */
|
1216 | export interface GeoIdentityTransform extends GeoStreamWrapper {
|
1217 | /**
|
1218 | * Returns a new array [x, y] (typically in pixels) representing the projected point of the given point.
|
1219 | * The point must be specified as a two-element array [longitude, latitude] in degrees.
|
1220 | * May return null if the specified point has no defined projected position, such as when the point is outside the clipping bounds of the projection.
|
1221 | *
|
1222 | * @param point A point specified as a two-dimensional array [longitude, latitude] in degrees.
|
1223 | */
|
1224 | (point: [number, number]): [number, number] | null;
|
1225 |
|
1226 | /**
|
1227 | * Returns a new array [longitude, latitude] in degrees representing the unprojected point of the given projected point.
|
1228 | * May return null if the specified point has no defined projected position, such as when the point is outside the clipping bounds of the projection.
|
1229 | *
|
1230 | * @param point The projected point, specified as a two-element array [x, y] (typically in pixels).
|
1231 | */
|
1232 | invert(point: [number, number]): [number, number] | null;
|
1233 |
|
1234 | /**
|
1235 | * Returns the current cartesian clipping function.
|
1236 | * Post-clipping occurs on the plane, when a projection is bounded to a certain extent such as a rectangle.
|
1237 | */
|
1238 | postclip(): (stream: GeoStream) => GeoStream;
|
1239 | /**
|
1240 | * Sets the projection’s cartesian clipping to the specified function and returns the projection.
|
1241 | *
|
1242 | * @param postclip A cartesian clipping function. Clipping functions are implemented as transformations of a projection stream.
|
1243 | * Post-clipping operates on planar coordinates, in pixels.
|
1244 | */
|
1245 | postclip(postclip: (stream: GeoStream) => GeoStream): this;
|
1246 |
|
1247 | /**
|
1248 | * Returns the current scale factor.
|
1249 | *
|
1250 | * The scale factor corresponds linearly to the distance between projected points; however, absolute scale factors are not equivalent across projections.
|
1251 | */
|
1252 | scale(): number;
|
1253 | /**
|
1254 | * Sets the projection’s scale factor to the specified value and returns the projection.
|
1255 | * The scale factor corresponds linearly to the distance between projected points; however, absolute scale factors are not equivalent across projections.
|
1256 | *
|
1257 | * @param scale Scale factor to be used for the projection.
|
1258 | */
|
1259 | scale(scale: number): this;
|
1260 |
|
1261 | /**
|
1262 | * Returns the current translation offset.
|
1263 | * The translation offset determines the pixel coordinates of the projection’s center.
|
1264 | */
|
1265 | translate(): [number, number];
|
1266 | /**
|
1267 | * Sets the projection’s translation offset to the specified two-element array [tx, ty] and returns the projection.
|
1268 | * The translation offset determines the pixel coordinates of the projection’s center.
|
1269 | *
|
1270 | * @param point A two-element array [tx, ty] specifying the translation offset.
|
1271 | */
|
1272 | translate(point: [number, number]): this;
|
1273 |
|
1274 | /**
|
1275 | * Returns the projection’s current angle, which defaults to 0°.
|
1276 | */
|
1277 | angle(): number;
|
1278 | /**
|
1279 | * Sets the projection’s post-projection planar rotation angle to the specified angle in degrees and returns the projection.
|
1280 | * @param angle The new rotation angle of the projection.
|
1281 | */
|
1282 | angle(angle: number): this;
|
1283 |
|
1284 | /**
|
1285 | * Sets the projection’s scale and translate to fit the specified GeoJSON object in the center of the given extent.
|
1286 | * The extent is specified as an array [[x₀, y₀], [x₁, y₁]], where x₀ is the left side of the bounding box, y₀ is the top, x₁ is the right and y₁ is the bottom. Returns the projection.
|
1287 | */
|
1288 | fitExtent(
|
1289 | extent: [[number, number], [number, number]],
|
1290 | object: ExtendedFeature | ExtendedFeatureCollection | GeoGeometryObjects | ExtendedGeometryCollection,
|
1291 | ): this;
|
1292 |
|
1293 | /**
|
1294 | * A convenience method for projection.fitExtent where the top-left corner of the extent is [0, 0].
|
1295 | */
|
1296 | fitSize(
|
1297 | size: [number, number],
|
1298 | object: ExtendedFeature | ExtendedFeatureCollection | GeoGeometryObjects | ExtendedGeometryCollection,
|
1299 | ): this;
|
1300 |
|
1301 | /**
|
1302 | * Returns the current viewport clip extent which defaults to null.
|
1303 | */
|
1304 | clipExtent(): [[number, number], [number, number]] | null;
|
1305 | /**
|
1306 | * Sets the projection’s viewport clip extent to the specified bounds in pixels and returns the projection.
|
1307 | * The extent bounds are specified as an array [[x₀, y₀], [x₁, y₁]], where x₀ is the left-side of the viewport, y₀ is the top, x₁ is the right and y₁ is the bottom.
|
1308 | * If extent is null, no viewport clipping is performed.
|
1309 | */
|
1310 | clipExtent(extent: null | [[number, number], [number, number]]): this;
|
1311 |
|
1312 | /**
|
1313 | * Returns true if x-reflection is enabled, which defaults to false.
|
1314 | */
|
1315 | reflectX(): boolean;
|
1316 | /**
|
1317 | * Sets whether or not the x-dimension is reflected (negated) in the output.
|
1318 | *
|
1319 | * @param reflect true = reflect x-dimension, false = do not reflect x-dimension.
|
1320 | */
|
1321 | reflectX(reflect: boolean): this;
|
1322 |
|
1323 | /**
|
1324 | * Returns true if y-reflection is enabled, which defaults to false.
|
1325 | */
|
1326 | reflectY(): boolean;
|
1327 | /**
|
1328 | * Sets whether or not the y-dimension is reflected (negated) in the output.
|
1329 | *
|
1330 | * This is especially useful for transforming from standard spatial reference systems,
|
1331 | * which treat positive y as pointing up, to display coordinate systems such as Canvas and SVG,
|
1332 | * which treat positive y as pointing down.
|
1333 | *
|
1334 | * @param reflect true = reflect y-dimension, false = do not reflect y-dimension.
|
1335 | */
|
1336 | reflectY(reflect: boolean): this;
|
1337 | }
|
1338 |
|
1339 | /**
|
1340 | * Returns the identity transform which can be used to scale, translate and clip planar geometry.
|
1341 | */
|
1342 | export function geoIdentity(): GeoIdentityTransform;
|
1343 |
|
1344 | // ----------------------------------------------------------------------
|
1345 | // Clipping Functions
|
1346 | // ----------------------------------------------------------------------
|
1347 |
|
1348 | /**
|
1349 | * A clipping function transforming a stream such that geometries (lines or polygons) that cross the antimeridian line are cut in two, one on each side.
|
1350 | * Typically used for pre-clipping.
|
1351 | */
|
1352 | export function geoClipAntimeridian(stream: GeoStream): GeoStream;
|
1353 |
|
1354 | /**
|
1355 | * Generates a clipping function transforming a stream such that geometries are bounded by a small circle of radius angle around the projection’s center.
|
1356 | * Typically used for pre-clipping.
|
1357 | *
|
1358 | * @param angle A clipping angle.
|
1359 | */
|
1360 | export function geoClipCircle(angle: number): (stream: GeoStream) => GeoStream;
|
1361 |
|
1362 | /**
|
1363 | * Generates a clipping function transforming a stream such that geometries are bounded by a rectangle of coordinates [[x0, y0], [x1, y1]].
|
1364 | * Typically used for post-clipping.
|
1365 | *
|
1366 | * @param x0 x0 coordinate.
|
1367 | * @param y0 y0 coordinate.
|
1368 | * @param x1 x1 coordinate.
|
1369 | * @param y1 y1 coordinate.
|
1370 | */
|
1371 | export function geoClipRectangle(x0: number, y0: number, x1: number, y1: number): (stream: GeoStream) => GeoStream;
|