Grid / graticule plugin for MapLibre GL JS / Mapbox GL JS
npm install maplibre-gridGrid / graticule plugin for MapLibre GL JS / Mapbox GL JS

```
npm install maplibre-gl maplibre-grid
or
``
``
import Maplibre from 'maplibre-gl';
import * as MaplibreGrid from 'maplibre-grid';
`
export interface GridConfig {
gridWidth: number;
gridHeight: number;
units: Units;
minZoom?: number;
maxZoom?: number;
paint?: maplibregl.LinePaint;
}
const grid = new MaplibreGrid.Grid(config: GridConfig);
`
- gridWidth - number, requiredgridHeight
- - number, requiredunits
- - 'degrees' | 'radians' | 'miles' | 'kilometers', grid width/height units, requiredminZoom
- - number, min zoom to display the gridmaxZoom
- - number, max zoom to display the gridpaint
- - maplibregl.LinePaint, layer line paint properties
Multiple grids can be added to display major and minor grid together, or different grids depending on zoom level.
``
const grid = new MaplibreGrid.Grid({
gridWidth: 10,
gridHeight: 10,
units: 'degrees',
paint: {
'line-opacity': 0.2
}
});
map.addControl(grid);
`
const grid1 = new MaplibreGrid.Grid({
gridWidth: 10,
gridHeight: 10,
units: 'degrees',
paint: {
'line-opacity': 0.2
}
});
map.addControl(grid1);
const grid2 = new MaplibreGrid.Grid({
gridWidth: 5,
gridHeight: 5,
units: 'degrees',
paint: {
'line-opacity': 0.2
}
});
map.addControl(grid2);
`$3
``
map.on(MaplibreGrid.GRID_CLICK_EVENT, event => {
console.log(event.bbox);
});
Click event can be used to implement grid cell selection. Create a polygon feature from event.bbox, and add it to your custom layer. See demo for details.
```
map.removeControl(grid);