midpoint函数计算两点之间线段的中点。函数的语法如下:
turf.midpoint(from, to[, options])
函数接受三个参数:
from: 代表起点的Feature或者Geometry
to: 代表终点的Feature或者Geometry
options(可选): 一个包含midpoint函数选项的对象。可选的选项包括:
properties: 一个新生成的中点Feature的属性。函数返回一个新的中点Feature对象。
| 参数 | 数据类型 | 描述 |
|---|---|---|
from |
Feature | Geometry |
代表起点的Feature或者Geometry |
to |
Feature | Geometry |
代表终点的Feature或者Geometry |
options |
Object |
一个包含midpoint函数选项的对象。 |
properties |
Object |
新生成的中点Feature对象的属性 |
每个生成的Feature对象都有以下属性:
| 名称 | 数据类型 | 描述 |
|---|---|---|
type |
"Feature" |
表示一个GeoJSON Feature对象 |
geometry |
Geometry |
中点的几何形状 |
properties |
Object |
新生成的中点Feature对象的属性 |
var from = turf.point([-75.343, 39.984]);
var to = turf.point([-75.534, 39.123]);
var midpoint = turf.midpoint(from, to);
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
-75.43845401583723,
39.55364371424839
]
}
}