Public
Edited
Oct 26, 2023
9 forks
27 stars
Also listed in…
Gallery
d3-geo
Insert cell
Insert cell
Insert cell
Insert cell
projection1 = d3.geoMercator()
.center([0, 0])
.translate([256, 256])
.scale(512 / (2 * Math.PI))
Insert cell
html`<svg width="512" height="512">
<path d="${d3.geoPath(projection1)(land)}" />
</svg>`
Insert cell
Insert cell
mercatorSize = scale => scale * (2 * Math.PI)
Insert cell
mercatorScale = size => size / (2 * Math.PI)
Insert cell
Insert cell
html`<img src="${url(0, 0, 0)}" width="256" height="256">`
Insert cell
Insert cell
html`<div style="position: relative; width: 512px; height: 512px;">
<img src="${url(0, 0, 1)}" style="position: absolute; top: 0px; left: 0px;" width="256" height="256">
<img src="${url(1, 0, 1)}" style="position: absolute; top: 0px; left: 256px;" width="256" height="256">
<img src="${url(0, 1, 1)}" style="position: absolute; top: 256px; left: 0px;" width="256" height="256">
<img src="${url(1, 1, 1)}" style="position: absolute; top: 256px; left: 256px;" width="256" height="256">
</div>`
Insert cell
Insert cell
html`<div style="position: relative; width: 512px; height: 512px;">
<img src="${url(0, 0, 1)}" style="position: absolute; top: 0px; left: 0px;" width="256" height="256">
<img src="${url(1, 0, 1)}" style="position: absolute; top: 0px; left: 256px;" width="256" height="256">
<img src="${url(0, 1, 1)}" style="position: absolute; top: 256px; left: 0px;" width="256" height="256">
<img src="${url(1, 1, 1)}" style="position: absolute; top: 256px; left: 256px;" width="256" height="256">
<svg width="512" height="512" style="position: relative;">
<path fill="none" stroke="red" d="${d3.geoPath(projection1)(land)}" />
</svg>
</div>`
Insert cell
Insert cell
Insert cell
tile1 = d3.tile()
.translate([256, 256])
.scale(512)
.extent([[0, 0], [512, 512]])
Insert cell
Insert cell
tile1()
Insert cell
Insert cell
detroit
Insert cell
projection = d3.geoMercator()
.fitSize([width, height], detroit)
Insert cell
path = d3.geoPath(projection)
Insert cell
tile = d3.tile()
.size([width, height])
.scale(projection.scale() * 2 * Math.PI)
.translate(projection([0, 0]))
Insert cell
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="${(x + tx) * k}" y="${(y + ty) * k}" width="${k}" height="${k}">
`)}
<path fill="none" stroke="red" d="${path(detroit)}"/>
</svg>`
Insert cell
Insert cell
Insert cell
height = Math.min(width, 720)
Insert cell
url = (x, y, z) => `https://api.mapbox.com/styles/v1/mapbox/light-v10/tiles/256/${z}/${x}/${y}${devicePixelRatio > 1 ? "@2x" : ""}?access_token=pk.eyJ1IjoibWJvc3RvY2siLCJhIjoiY2s5ZWRlbTM4MDE0eDNocWJ2aXR2amNmeiJ9.LEyjnNDr_BrxRmI4UDyJAQ`
Insert cell
land = FileAttachment("land-50m.json").json()
.then(topology => topojson.feature(topology, topology.objects.land))
Insert cell
detroit = FileAttachment("detroit.json").json()
.then(topology => topojson.feature(topology, topology.objects.detroit))
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