Class: Graticule

ol/Graticule~Graticule


import Graticule from 'ol/Graticule';

Render a grid for a coordinate system on a map.

new Graticule(opt_options)

Graticule.js, line 121
Name Type Description
options

Options.

Name Type Default Description
map module:ol/PluggableMap~PluggableMap

Reference to an module:ol/Map~Map object.

maxLines number 100

The maximum number of meridians and parallels from the center of the map. The default value of 100 means that at most 200 meridians and 200 parallels will be displayed. The default value is appropriate for conformal projections like Spherical Mercator. If you increase the value, more lines will be drawn and the drawing performance will decrease.

strokeStyle module:ol/style/Stroke~Stroke 'rgba(0,0,0,0.2)'

The stroke style to use for drawing the graticule. If not provided, a not fully opaque black will be used.

targetSize number 100

The target size of the graticule cells, in pixels.

showLabels boolean false

Render a label with the respective latitude/longitude for each graticule line.

lonLabelFormatter function

Label formatter for longitudes. This function is called with the longitude as argument, and should return a formatted string representing the longitude. By default, labels are formatted as degrees, minutes, seconds and hemisphere.

latLabelFormatter function

Label formatter for latitudes. This function is called with the latitude as argument, and should return a formatted string representing the latitude. By default, labels are formatted as degrees, minutes, seconds and hemisphere.

lonLabelPosition number 0

Longitude label position in fractions (0..1) of view extent. 0 means at the bottom of the viewport, 1 means at the top.

latLabelPosition number 1

Latitude label position in fractions (0..1) of view extent. 0 means at the left of the viewport, 1 means at the right.

lonLabelStyle module:ol/style/Text~Text

Longitude label text style. If not provided, the following style will be used:

new Text({
  font: '12px Calibri,sans-serif',
  textBaseline: 'bottom',
  fill: new Fill({
    color: 'rgba(0,0,0,1)'
  }),
  stroke: new Stroke({
    color: 'rgba(255,255,255,1)',
    width: 3
  })
});

Note that the default's textBaseline configuration will not work well for lonLabelPosition configurations that position labels close to the top of the viewport.

latLabelStyle module:ol/style/Text~Text

Latitude label text style. If not provided, the following style will be used:

new Text({
  font: '12px Calibri,sans-serif',
  textAlign: 'end',
  fill: new Fill({
    color: 'rgba(0,0,0,1)'
  }),
  stroke: Stroke({
    color: 'rgba(255,255,255,1)',
    width: 3
  })
});

Note that the default's textAlign configuration will not work well for latLabelPosition configurations that position labels close to the left of the viewport.

intervals Array.<number> [90, 45, 30, 20, 10, 5, 2, 1, 0.5, 0.2, 0.1, 0.05, 0.01, 0.005, 0.002, 0.001]

Intervals (in degrees) for the graticule. Example to limit graticules to 30 and 10 degrees intervals:

[30, 10]

Methods

getMap(){module:ol/PluggableMap~PluggableMap}

Graticule.js, line 565

Get the map associated with this graticule.

Returns:
The map.

getMeridians(){Array.<module:ol/geom/LineString~LineString>}

Graticule.js, line 595

Get the list of meridians. Meridians are lines of equal longitude.

Returns:
The meridians.

getParallels(){Array.<module:ol/geom/LineString~LineString>}

Graticule.js, line 625

Get the list of parallels. Parallels are lines of equal latitude.

Returns:
The parallels.

setMap(map)

Graticule.js, line 719

Set the map for this graticule. The graticule will be rendered on the provided map.

Name Type Description
map module:ol/PluggableMap~PluggableMap

Map.