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