Atlaslog
Atlaslog / Leaflet / API reference / GridLayer
Leaflet · API reference

GridLayer

Quick answer

L.GridLayer is the abstract tiled layer base that TileLayer and WMS build on. Subclass it and implement createTile when tile content must be generated, such as canvas drawings, custom text or procedural grids. It also manages loading state, buffering and redraw events.

Last verified 2026-11-03 · Leaflet 1.9.4 · Cite this page
L.gridLayer( options ) → GridLayer
Key points
Example
var LabelGrid = L.GridLayer.extend({
  createTile: function (coords) {
    var tile = L.DomUtil.create('canvas', 'leaflet-tile');
    var size = this.getTileSize();
    tile.width = size.x;
    tile.height = size.y;

    var ctx = tile.getContext('2d');
    ctx.fillStyle = '#f4f6f8';
    ctx.fillRect(0, 0, size.x, size.y);
    ctx.strokeStyle = '#d5dae1';
    ctx.strokeRect(0.5, 0.5, size.x - 1, size.y - 1);

    ctx.fillStyle = '#58606e';
    ctx.font = '12px sans-serif';
    ctx.fillText(coords.z + '/' + coords.x + '/' + coords.y, 10, 20);

    return tile;
  }
});

var labels = new LabelGrid({ tileSize: 256, opacity: 0.9 }).addTo(map);
labels.on('tileerror', function (e) { console.warn(e.coords, e.error); });
Notes
Runnable examplesChinese originalAll API references
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Cite this page

Atlaslog (2026). GridLayer. https://www.jingweizhi.com/en/leaflet/api/grid-layer.html (accessed 2026-11-03).