Public
Edited
Jul 18, 2023
4 forks
8 stars
Also listed in…
d3-tile
Insert cell
Insert cell
map = svg`<svg viewBox="0 0 ${width} ${height}">
${tile().map(([x, y, z], i, {translate: [tx, ty], scale: k}) => svg`
<image xlink:href="${url(x, y, z)}" x="${Math.round((x + tx) * k)}" y="${Math.round((y + ty) * k)}" width="${k}" height="${k}">
`)}
<path fill="none" stroke="red" d="${path(vectors)}"/>
</svg>`
Insert cell
url = (x, y, z) => `https://api.mapbox.com/styles/v1/mapbox/light-v10/tiles/${z}/${x}/${y}${devicePixelRatio > 1 ? "@2x" : ""}?access_token=pk.eyJ1IjoibWJvc3RvY2siLCJhIjoiY2s5ZWRlbTM4MDE0eDNocWJ2aXR2amNmeiJ9.LEyjnNDr_BrxRmI4UDyJAQ`
Insert cell
projection = {
const projection = d3.geoMercator().fitSize([width, height], vectors);
const zoom = Math.floor(Math.log2(projection.scale() * (2 * Math.PI)));
const scale = Math.pow(2, zoom) / (2 * Math.PI);
projection.center(projection.invert([width / 2, height / 2]));
projection.scale(scale);
projection.translate([width / 2, height / 2]);
return projection;
}
Insert cell
path = d3.geoPath(projection)
Insert cell
tile = d3.tile()
.size([width, height])
.scale(projection.scale() * 2 * Math.PI)
.translate(projection([0, 0]))
.tileSize(512)
Insert cell
height = 600
Insert cell
vectors = topojson.feature(topology, topology.objects.detroit)
Insert cell
topology = FileAttachment("detroit.json").json()
Insert cell
d3 = require("d3-geo@3", "d3-tile@1")
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more