34 lines
1.6 KiB
TypeScript
Executable File
34 lines
1.6 KiB
TypeScript
Executable File
import { Feature, FeatureCollection, Units, Properties, Polygon, BBox } from "@turf/helpers";
|
|
/**
|
|
* Takes a bounding box and the diameter of the cell and returns a {@link FeatureCollection} of flat-topped
|
|
* hexagons or triangles ({@link Polygon} features) aligned in an "odd-q" vertical grid as
|
|
* described in [Hexagonal Grids](http://www.redblobgames.com/grids/hexagons/).
|
|
*
|
|
* @name hexGrid
|
|
* @param {BBox} bbox extent in [minX, minY, maxX, maxY] order
|
|
* @param {number} cellSide length of the side of the the hexagons or triangles, in units. It will also coincide with the
|
|
* radius of the circumcircle of the hexagons.
|
|
* @param {Object} [options={}] Optional parameters
|
|
* @param {string} [options.units='kilometers'] used in calculating cell size, can be degrees, radians, miles, or kilometers
|
|
* @param {Object} [options.properties={}] passed to each hexagon or triangle of the grid
|
|
* @param {Feature<Polygon>} [options.mask] if passed a Polygon or MultiPolygon, the grid Points will be created only inside it
|
|
* @param {boolean} [options.triangles=false] whether to return as triangles instead of hexagons
|
|
* @returns {FeatureCollection<Polygon>} a hexagonal grid
|
|
* @example
|
|
* var bbox = [-96,31,-84,40];
|
|
* var cellSide = 50;
|
|
* var options = {units: 'miles'};
|
|
*
|
|
* var hexgrid = turf.hexGrid(bbox, cellSide, options);
|
|
*
|
|
* //addToMap
|
|
* var addToMap = [hexgrid];
|
|
*/
|
|
declare function hexGrid<P = Properties>(bbox: BBox, cellSide: number, options?: {
|
|
units?: Units;
|
|
triangles?: boolean;
|
|
properties?: P;
|
|
mask?: Feature<Polygon> | Polygon;
|
|
}): FeatureCollection<Polygon, P>;
|
|
export default hexGrid;
|