Class GridLayer
A layer that renders a reference grid in the map's native coordinate system (CRS). Useful as a background when no tile layer is present — the grid gives visual feedback when panning or zooming because the lines scroll and spread with the map. No projection is performed; grid intervals are computed directly from Resolution and world units.
Inherited Members
Namespace: Mapsui.Layers
Assembly: Mapsui.dll
Syntax
public class GridLayer : BaseLayer, ILayer, IAnimatable, INotifyPropertyChanged, IDisposable
Remarks
The grid covers the entire viewport at all zoom levels. Use MinVisible and MaxVisible to restrict the resolution range where the grid is visible.
Constructors
| Edit this page View SourceGridLayer()
Creates a grid layer with the default name "Grid".
Declaration
public GridLayer()
GridLayer(string)
Creates a grid layer with the given name.
Declaration
public GridLayer(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name |
Fields
| Edit this page View SourceLayerRendererName
Name used to register the grid renderer with MapRenderer.RegisterLayerRenderer.
Declaration
public const string LayerRendererName = "grid-layer"
Field Value
| Type | Description |
|---|---|
| string |
Properties
| Edit this page View SourceExtent
Returns the envelope of all available data in the layer
Declaration
public override MRect? Extent { get; }
Property Value
| Type | Description |
|---|---|
| MRect |
Overrides
| Edit this page View SourceLabelColor
Color of the coordinate labels. Default: semi-transparent dark grey.
Declaration
public Color LabelColor { get; set; }
Property Value
| Type | Description |
|---|---|
| Color |
LabelFont
Optional font to use for coordinate labels. When set, Size overrides LabelSize and FontSource allows loading a custom typeface. When null, the renderer falls back to LabelSize with the system default typeface.
Declaration
public Font? LabelFont { get; set; }
Property Value
| Type | Description |
|---|---|
| Font |
LabelSize
Font size of the coordinate labels in screen pixels. Default: 12.
Declaration
public float LabelSize { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
LineColor
Color of the grid lines. Default: semi-transparent grey.
Declaration
public Color LineColor { get; set; }
Property Value
| Type | Description |
|---|---|
| Color |
LineWidth
Width of the grid lines in screen pixels. Default: 1.
Declaration
public float LineWidth { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
ShowCoordinateLabels
Whether to draw coordinate labels alongside the grid lines. Default: false. Labels show raw world coordinates in the map's CRS (e.g. EPSG:3857 metres by default), not longitude/latitude. Keep this in mind when the map uses a projected coordinate system.
Declaration
public bool ShowCoordinateLabels { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
TargetLineCount
Target number of grid lines to show across the wider viewport dimension. The actual count will vary because intervals snap to "nice" values (1, 2, 5 × 10^n). Default: 6.
Declaration
public int TargetLineCount { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
| Edit this page View SourceGetFeatures(MRect?, double)
Get all features in a given MRect for a given resolution
Declaration
public override IEnumerable<IFeature> GetFeatures(MRect? rect, double resolution)
Parameters
| Type | Name | Description |
|---|---|---|
| MRect | rect | |
| double | resolution | Resolution of viewport |
Returns
| Type | Description |
|---|---|
| IEnumerable<IFeature> |