--- layout: api title: "v1.6.0 API: L.mapbox.gridLayer(id|url|tilejson, options)" categories: api version: v1.6.0 permalink: /api/v1.6.0/l-mapbox-gridlayer --- {% raw %}

L.mapbox.gridLayer(id|url|tilejson, options)

An L.mapbox.gridLayer loads UTFGrid tiles of interactivity into your map, which you can easily access with L.mapbox.gridControl.

Options Value Description
id or url or tilejson (required) string if id or url object if tilejson
  • An id string examples.map-foo
  • A URL to TileJSON, like http://a.tiles.mapbox.com/v3/examples.map-0l53fhk2.json
  • A TileJSON object, from your own Javascript code

Example:

// the second argument is optional
var layer = L.mapbox.gridLayer('examples.map-20v6611k');

Returns a L.mapbox.gridLayer object.

gridLayer.getTileJSON()

Returns this layer's TileJSON object which determines its tile source, zoom bounds and other metadata.

Example:

var layer = L.mapbox.gridLayer('examples.map-20v6611k')
    // since layers load asynchronously through AJAX, use the
    // `.on` function to listen for them to be loaded before
    // calling `getTileJSON()`
    .on('load', function() {
    // get TileJSON data from the loaded layer
    var TileJSON = layer.getTileJSON();
});

Returns: the TileJSON object

gridLayer.getData(latlng, callback)

Load data for a given latitude, longitude point on the map, and call the callback function with that data, if any.

Options Value Description
latlng object latlng a http://leafletjs.com/reference.html#latlng
callback function callback a function that is called with the grid data as an argument

Returns: the L.mapbox.gridLayer object

{% endraw %}