[GIS] How to get data from TileMill tileLayer properties in Mapbox for click/hover

geojsonjavascriptleafletmapboxtilemill

I've successfully used Leaflet to load a geoJSON polygon-shapefile with data, and added click and hover interactivity to the layer. For a large dataset, I switched to mapbox.js 1.6.1, used TileMill to export a tiles, used infostream's mbtiles-php (https://github.com/infostreams/mbtiles-php) to serve the data.

I'm very confused, now, how to use mapbox.js to access show the polygon attributes in the tile layer? I have successfully loaded the tiles onto a page using mapbox.js – but don't know where to start to pull in the attribute table.

I did not find an appropriate Mapbox example on the example page, and the Mapbox support links are all directed to their contact page. Did I misunderstand how the purpose of Mapbox/TileMill?

Best Answer

Use a UTFGrid - https://www.mapbox.com/developers/utfgrid/

Your tiles no longer contain the attribute table data that you seek.

Map tiles are used for displaying data that is too complex for vector (geojson) display; however, converting your data to map tiles is actually converting your data to image files, and these image files lack any information from your attribute table.

The solution is to add another, non-visible, tiled layer that contains the feature specific information on top of your map tiles.

You can then use the UTFGrid to trigger the desired hover and click interactivity.

Here's a link to the Leaflet UTFGrid plugin - https://github.com/danzel/Leaflet.utfgrid

And a link to an example from that same page - http://danzel.github.io/Leaflet.utfgrid/example/map.html