Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created July 27, 2015 21:51
Show Gist options
  • Save tmcw/0be17dbe3ef94df31886 to your computer and use it in GitHub Desktop.
Save tmcw/0be17dbe3ef94df31886 to your computer and use it in GitHub Desktop.
var xhr = require('xhr');
var Pbf = require('pbf');
var VectorTile = require('vector-tile').VectorTile;
var queryURL='https://a.tiles.mapbox.com/v4/enf.i4lvj9k9/14/2821/6541.vector.pbf?access_token=pk.eyJ1IjoicGV0ZXJxbGl1IiwiYSI6ImpvZmV0UEEifQ._D4bRmVcGfJvo1wjuOpA1g'
xhr({uri:queryURL,responseType:'arraybuffer'}, function (error, response, buffer) {
console.log(arguments);
var tile = new VectorTile(new Pbf(buffer));
console.log(tile);
//populate geoJSON
// for (var i=0; i<tile.layers.population.length; i++){
// //convert each feature (within #population) into a geoJSON polygon, and push it into our variable
// var feature = tile.layers.population.feature(i).toGeoJSON(tile[0], tile[1],tile[2]);
// geojson.features.push(feature);
// }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment