Class: Graticule

ol.Graticule

new ol.Graticule(opt_options)

src/ol/graticule.js, line 23

Render a grid for a coordinate system on a map.

Name Type Description
options

Options.

Name Type Description
map ol.Map | undefined

Reference to an ol.Map object.

maxLines number | undefined

The maximum number of meridians and parallels from the center of the map. The default value is 100, which 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 ol.style.Stroke | undefined

The stroke style to use for drawing the graticule. If not provided, the lines will be drawn with rgba(0,0,0,0.2), a not fully opaque black.

targetSize number | undefined

The target size of the graticule cells, in pixels. Default value is 100 pixels.

showLabels boolean | undefined

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

lonLabelFormatter undefined | 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 undefined | 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 | undefined

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

latLabelPosition number | undefined

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

lonLabelStyle ol.style.Text | undefined

Longitude label text style. The default is

new ol.style.Text({
  font: '12px Calibri,sans-serif',
  textBaseline: 'bottom',
  fill: new ol.style.Fill({
    color: 'rgba(0,0,0,1)'
  }),
  stroke: new ol.style.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 ol.style.Text | undefined

Latitude label text style. The default is

new ol.style.Text({
  font: '12px Calibri,sans-serif',
  textAlign: 'end',
  fill: new ol.style.Fill({
    color: 'rgba(0,0,0,1)'
  }),
  stroke: new ol.style.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.

Methods

getMap(){ol.Map}

src/ol/graticule.js, line 475

Get the map associated with this graticule.

Returns:
The map.

getMeridians(){Array.<ol.geom.LineString>}

src/ol/graticule.js, line 505

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

Returns:
The meridians.

getParallels(){Array.<ol.geom.LineString>}

src/ol/graticule.js, line 535

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

Returns:
The parallels.

setMap(map)

src/ol/graticule.js, line 665

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

Name Type Description
map ol.Map

Map.