使用Turf的triangleGrid函数可以创建一个由等边三角形组成的网格覆盖区域。
turf.triangleGrid(bbox, cellSize, options?)
函数参数:
bbox (Array<number>):由四个数字组成的表示地理范围的数组,格式为[西经,南纬,东经,北纬]。cellSize (number):三角形的边长(单位:度)。options (Object):一个可选的对象,用于自定义输出。输出的结果为一个多边形GeoJSON对象。
var bbox = [-122.681885, 45.523062, -122.654274, 45.541012];
var triangleGrid = turf.triangleGrid(bbox, 0.1);
输出结果:
{
    "type": "Feature",
    "properties": {},
    "geometry": {
        "type": "MultiPolygon",
        "coordinates": [[[
            [-122.67411999999999, 45.52889876731145],
            [-122.67931999999998, 45.53335102506253],
            [-122.67411999999999, 45.53780328281361],
            [-122.66892, 45.53335102506253],
            [-122.67411999999999, 45.52889876731145]
        ]],[[
            [-122.66372, 45.532225]
            [-122.66892, 45.53667725775107],
            [-122.66372, 45.54112951550215],
            [-122.65851999999999, 45.53667725775107],
            [-122.66372, 45.532225]
        ]],[...]]
    }
}
可以通过options参数进一步自定义输出。
options.properties (Object):对象属性集。options.mask (Feature):用于标记网格覆盖范围的GeoJSON对象。option.units (string):可选的距离单位,默认为“度”。option.properties:自定义输出的GeoJSON对象的属性。