Public
Edited
Apr 17
1 star
Insert cell
Insert cell
Insert cell
tiles = Promise.all(
tile().map(async (d) => {
const tileData = await getTileData(...d);
d.layers = new VectorTile(new Protobuf(tileData)).layers;
return d;
})
)
Insert cell
geojson(tiles[1], tiles[1].layers.transportation_name)
Insert cell
tile = d3.tile()
.size([width, height])
.scale(projection.scale() * 2 * Math.PI)
.translate(projection([0, 0]))
Insert cell
projection = d3
.geoMercator()
.center([4.3517, 50.85])
.scale(Math.pow(2, 21) / (2 * Math.PI))
.translate([width / 2, height / 2])
.precision(0)
Insert cell
path = d3.geoPath(projection)
Insert cell
function geojson([x, y, z], layer, filter = () => true) {
if (!layer) return;
const features = [];
for (let i = 0; i < layer.length; ++i) {
const f = layer.feature(i).toGeoJSON(x, y, z);
if (filter.call(null, f, i, features)) features.push(f);
}
return { type: "FeatureCollection", features };
}
Insert cell
height = 600
Insert cell
VectorTile = (
await import("https://unpkg.com/@mapbox/vector-tile@2.0.3/index.js?module")
).VectorTile
Insert cell
Protobuf = require("pbf@4/dist/pbf.js")
Insert cell
d3 = require("d3-geo@3", "d3-fetch@3", "d3-tile@1")
Insert cell
pmtiles = import("https://cdn.skypack.dev/pmtiles@2.7.0")
Insert cell
Insert cell
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