3

I am new to this and trying to add a grid layer, using Mapbox GL. Would appreciate some help.

var bbox = [-95, 30 ,-85, 40];
var cellSide = 50;
var options = {units: 'miles'};

var squareGrid = turf.squareGrid(bbox, cellSide, options);
Jasmine
  • 41
  • 3

1 Answers1

4

What you have so far gives you a GeoJSON object that you can add to your map. Assuming you have a created a map (follow the getting started example), you now need to add a GeoJSON source, then a layer that renders it.

Something like

map.on('load', function() {
    map.addSource('grid', {
        'type': "geojson",
        'data': squareGrid
    });
    map.addLayer({
        'id': 'grid',
        'type': 'line',
        'source': 'grid',
        'paint': {
            'line-color': 'red',
        }
    });
});
Steve Bennett
  • 114,604
  • 39
  • 168
  • 219