Published
Edited
Apr 23, 2018
1 fork
1 star
Insert cell
Insert cell
index = ({x: 1310, y: 3165, z: 13}) // The tile we want.
Insert cell
data = fetch(`https://tile.nextzen.org/tilezen/vector/v1/256/all/${index.z}/${index.x}/${index.y}.mvt?api_key=jdPwBXkWSB-v5_CPQYDiIQ`).then(r => r.arrayBuffer()) // Sign up for an API key: https://www.nextzen.org
Insert cell
tile = new VectorTile(new Protobuf(data))
Insert cell
roads = {
const layer = tile.layers.roads;
const features = new Array(layer.length);
for (let i = 0; i < layer.length; ++i) {
features[i] = layer.feature(i).toGeoJSON(index.x, index.y, index.z);
}
return {type: "FeatureCollection", features};
}
Insert cell
VectorTile = (await require("https://bundle.run/@mapbox/vector-tile@1.3.1")).VectorTile
Insert cell
Protobuf = require("pbf@3.1.0/dist/pbf.js")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more