Skip to content

球面形状

¥Spherical shapes

这些形状生成器返回球形 GeoJSON 以供 geoPath 使用。

¥These shape generators return spherical GeoJSON for use with geoPath.

提示

要生成 大弧线(大圆的一部分),请将 GeoJSON LineString 几何对象传递给 geoPath。D3 的投影使用测地线插值来表示中间点。

¥To generate a great arc (a segment of a great circle), pass a GeoJSON LineString geometry object to a geoPath. D3’s projections use geodesic interpolation for intermediate points.

geoGraticule()

源代码 · 构造一个用于创建经纬网的几何生成器:用于显示投影畸变的均匀 meridiansparallels 网格。默认经纬网在±80°纬度之间每 10°有一条经线和纬线;对于极地区域,每 90° 有一个子午线。

¥Source · Constructs a geometry generator for creating graticules: a uniform grid of meridians and parallels for showing projection distortion. The default graticule has meridians and parallels every 10° between ±80° latitude; for the polar regions, there are meridians every 90°.

graticule() {#_graticule}

源代码 · 返回一个 GeoJSON MultiLineString 几何对象,表示此经纬网的所有经线和纬线。

¥Source · Returns a GeoJSON MultiLineString geometry object representing all meridians and parallels for this graticule.

graticule.lines() {#graticule_lines}

源代码 · 返回一个 GeoJSON LineString 几何对象数组,每个对象对应此经纬网的一条经线或纬线。

¥Source · Returns an array of GeoJSON LineString geometry objects, one for each meridian or parallel for this graticule.

graticule.outline() {#graticule_outline}

源代码 · 返回一个 GeoJSON 多边形几何对象,表示此经纬网的轮廓,即沿着定义其范围的经线和纬线。

¥Source · Returns a GeoJSON Polygon geometry object representing the outline of this graticule, i.e. along the meridians and parallels defining its extent.

graticule.extent(extent) {#graticule_extent}

源代码 · 如果指定了范围,则设置此经纬线的主要范围和次要范围。如果未指定范围,则返回当前次范围,默认为⟨⟨-180°, -80° - ε⟩, ⟨180°, 80° + ε⟩⟩.

¥Source · If extent is specified, sets the major and minor extents of this graticule. If extent is not specified, returns the current minor extent, which defaults to ⟨⟨-180°, -80° - ε⟩, ⟨180°, 80° + ε⟩⟩.

graticule.extentMajor(extent) {#graticule_extentMajor}

源代码 · 如果指定了范围,则设置此经纬线的主要范围。如果未指定范围,则返回当前主范围,默认为⟨⟨-180°, -90° + ε⟩, ⟨180°, 90° - ε⟩⟩.

¥Source · If extent is specified, sets the major extent of this graticule. If extent is not specified, returns the current major extent, which defaults to ⟨⟨-180°, -90° + ε⟩, ⟨180°, 90° - ε⟩⟩.

graticule.extentMinor(extent) {#graticule_extentMinor}

源代码 · 如果指定了范围,则设置此经纬线的次要范围。如果未指定范围,则返回当前次范围,默认为⟨⟨-180°, -80° - ε⟩, ⟨180°, 80° + ε⟩⟩.

¥Source · If extent is specified, sets the minor extent of this graticule. If extent is not specified, returns the current minor extent, which defaults to ⟨⟨-180°, -80° - ε⟩, ⟨180°, 80° + ε⟩⟩.

graticule.step(step) {#graticule_step}

源代码 · 如果指定了 step,则设置此网格的主要步长和次要步长。如果未指定 step,则返回当前次步长,默认为⟨10°, 10°⟩。

¥Source · If step is specified, sets the major and minor step for this graticule. If step is not specified, returns the current minor step, which defaults to ⟨10°, 10°⟩.

graticule.stepMajor(step) {#graticule_stepMajor}

源代码 · 如果指定了 step,则设置此网格的主要步长。如果未指定 step,则返回当前主步长,默认为⟨90°, 360°⟩。

¥Source · If step is specified, sets the major step for this graticule. If step is not specified, returns the current major step, which defaults to ⟨90°, 360°⟩.

graticule.stepMinor(step) {#graticule_stepMinor}

源代码 · 如果指定了 step,则设置此网格的次要步长。如果未指定 step,则返回当前次步长,默认为⟨10°, 10°⟩。

¥Source · If step is specified, sets the minor step for this graticule. If step is not specified, returns the current minor step, which defaults to ⟨10°, 10°⟩.

graticule.precision(angle) {#graticule_precision}

源代码 · 如果指定了 precision,则设置此格网的精度(以度为单位)。如果未指定精度,则返回当前精度,默认为 2.5°。

¥Source · If precision is specified, sets the precision for this graticule, in degrees. If precision is not specified, returns the current precision, which defaults to 2.5°.

geoGraticule10()

源代码 · 一个便捷的方法,用于直接生成默认的 10° 全局经纬网作为 GeoJSON MultiLineString 几何对象。等同于:

¥Source · A convenience method for directly generating the default 10° global graticule as a GeoJSON MultiLineString geometry object. Equivalent to:

js
function geoGraticule10() {
  return d3.geoGraticule()();
}

geoCircle()

源代码 · 返回一个新的数组,该数组按顺序包含来自 iterable 的值,给定的测试函数返回 true。

¥Source · Returns a new circle generator.

circle(...arguments) {#_circle}

源代码 · 返回一个新的 GeoJSON 几何对象,该对象类型为“Polygon”,近似于球体表面上的一个圆,包含当前的 centerradiusprecision 方法。所有参数都会传递给访问器。

¥Source · Returns a new GeoJSON geometry object of type “Polygon” approximating a circle on the surface of a sphere, with the current center, radius and precision. Any arguments are passed to the accessors.

circle.center(center) {#circle_center}

源代码 · 如果指定了 center,则将圆心设置为指定的点 [经度, 纬度](以度为单位),并返回此圆生成器。中心也可以指定为函数;每当圆为 generated 时,都会调用此函数,并将传递给圆生成器的所有参数传递给该函数。如果未指定 center,则返回当前中心访问器,默认为:

¥Source · If center is specified, sets the circle center to the specified point [longitude, latitude] in degrees, and returns this circle generator. 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. If center is not specified, returns the current center accessor, which defaults to:

js
function center() {
  return [0, 0];
}

circle.radius(radius) {#circle_radius}

源代码 · 如果指定了半径,则将圆半径设置为指定的角度(以度为单位),并返回此圆生成器。半径也可以指定为函数;每当圆为 generated 时,都会调用此函数,并将传递给圆生成器的所有参数传递给该函数。如果未指定半径,则返回当前半径访问器,默认为:

¥Source · If radius is specified, sets the circle radius to the specified angle in degrees, and returns this circle generator. 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. If radius is not specified, returns the current radius accessor, which defaults to:

js
function radius() {
  return 90;
}

circle.precision(angle) {#circle_precision}

源代码 · 如果指定了 precision,则将圆的精度设置为指定的角度(以度为单位),并返回此圆生成器。精度也可以指定为函数;每当圆为 generated 时,都会调用此函数,并将传递给圆生成器的所有参数传递给该函数。如果未指定精度,则返回当前精度访问器,默认为:

¥Source · If precision is specified, sets the circle precision to the specified angle in degrees, and returns this circle generator. 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. If precision is not specified, returns the current precision accessor, which defaults to:

js
function precision() {
  return 2;
}

小圆不遵循大圆弧,因此生成的多边形只是近似值。指定较小的精度角度可以提高近似多边形的精度,但也会增加生成和渲染的成本。

¥Small circles do not follow great arcs and thus the generated polygon is only an approximation. Specifying a smaller precision angle improves the accuracy of the approximate polygon, but also increase the cost to generate and render it.