Class: HexGrid

ol. HexGrid

ol.HexGrid is a class to compute hexagonal grids


new HexGrid( [options])

Hexagonal grids

Parameters:
Name Type Argument Description
options olx.HexGrid <optional>
Properties
Name Type Description
size Number

size of the exagon in map units, default 80000

origin _ol_coordinate_

orgin of the grid, default [0,0]

layout pointy | flat

grid layout, default pointy

See:

Extends

  • ol.Object

Members


layout

Layout

Methods


coord2hex(coord)

Convert coord to hex

Parameters:
Name Type Description
coord ol.coord
Returns:
Type
ol.hex

cube2hex(c)

Convert cube to axial coords

Parameters:
Name Type Description
c ol.coordinate

cube coordinate

Returns:

axial coordinate

Type
ol.coordinate

cube_distance(a, a)

Calculate distance between to hexagon (number of cube)

Parameters:
Name Type Description
a ol.coordinate

first cube coord

a ol.coordinate

second cube coord

Returns:

distance

Type
Number

cube_line(a, b)

Calculate line between to hexagon

Parameters:
Name Type Description
a ol.coordinate

first cube coord

b ol.coordinate

second cube coord

Returns:

array of cube coordinates

Type
Array.<ol.coordinate>

cube_neighbors(c, direction)

Get the neighbors for an hexagon

Parameters:
Name Type Description
c ol.coordinate

cube coord

direction Number
Returns:

neighbor || array of neighbors

Type
ol.coordinate | Array.<ol.coordinates>

cube_round(c, o, h)

Convert offset to cube coords

Parameters:
Name Type Description
c ol.coordinate

cube coordinate

o ol.coordinate

offset coordinate

h ol.coordinate

cube coordinate

Returns:
  • offset coordinate / ol.HexGrid.prototype.cube2offset = function(c) { return hex2offset(cube2hex(c)); }; /** Convert cube to offset coords

    Type
    ol.coordinate
  • cube coordinate / ol.HexGrid.prototype.offset2cube = function (o) { return hex2cube(offset2Hex(o)); }; /** Round cube coords

    Type
    ol.coordinate
  • rounded cube coordinate

    Type
    ol.coordinate

getHexagon(hex)

Get hexagon coordinates at hex

Parameters:
Name Type Description
hex ol.coord
Returns:
Type
Arrary.<ol.coord>

getHexagonAtCoord(coord)

Get hexagon coordinates at a coordinate

Parameters:
Name Type Description
coord ol.coord
Returns:
Type
Arrary.<ol.coord>

getLayout()

Get layout

Returns:

layout name

Type
pointy | flat

getOrigin()

Get hexagon origin

Returns:

coord origin

Type
ol.coordinate

getSize()

Get hexagon size

Returns:

hexagon size

Type
Number

hex2coord(hex)

Convert hex to coord

Parameters:
Name Type Description
hex ol.hex
Returns:
Type
ol.coord

hex2cube(h)

Convert axial to cube coords

Parameters:
Name Type Description
h ol.coordinate

axial coordinate

Returns:

cube coordinate

Type
ol.coordinate

hex2offset(h)

Convert offset to axial coords

Parameters:
Name Type Description
h ol.coordinate

axial coordinate

Returns:

offset coordinate

Type
ol.coordinate

hex_corner()

Get hexagon corners


hex_neighbors(h, direction)

Get the neighbors for an hexagon

Parameters:
Name Type Description
h ol.coordinate

axial coord

direction Number
Returns:

neighbor || array of neighbors

Type
ol.coordinate | Array.<ol.coordinates>

hex_round(h)

Round axial coords

Parameters:
Name Type Description
h ol.coordinate

axial coordinate

Returns:

rounded axial coordinate

Type
ol.coordinate

offset2hex(o)

Convert axial to offset coords

Parameters:
Name Type Description
o ol.coordinate

offset coordinate

Returns:

axial coordinate

Type
ol.coordinate

setLayout(layout)

Set layout

Parameters:
Name Type Description
layout pointy | flat | undefined

name, default pointy


setOrigin(coord)

Set hexagon origin

Parameters:
Name Type Description
coord ol.coordinate

origin


setSize(hexagon)

Set hexagon size

Parameters:
Name Type Description
hexagon Number

size