Public
Edited
Mar 6, 2024
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="${(x + tx) * k}" y="${(y + ty) * k}" width="${k}" height="${k}">
`)}
<path fill="none" stroke="#fff8" d="${path(boundaries)}"/>
${circles}
</svg>`
Insert cell
circles = countries.map(p => {
const [x,y] = projection([p.lon,p.lat]);
const circle = svg`<circle cx=${x} cy=${y} r=40 fill='#fff0' stroke='#fff4' />`
const label = svg`<text x=${x} y=${y} text-anchor='middle' alignment-baseline='central' fill='#fff'>${p.iso2}</text>`
return [circle, label];
}).flat()
Insert cell
url = (_x, _y, _z) => {
const [x, y, z] = d3.tileWrap([_x, _y, _z])
return `https://api.mapbox.com/styles/v1/brody1/cltfjsd5100gw01r577hg2eo0/tiles/${tileSize}/${z}/${x}/${y}${devicePixelRatio > 1 ? "@2x" : ""}?access_token=pk.eyJ1IjoiYnJvZHkxIiwiYSI6ImNrbTQ1d2oweTAxZ3cyb3J0d3MydDN0cmsifQ.SP2rehihX6dZ_h5rqVjdOA`
}
Insert cell
tile = d3.tile()
.size([width, height])
.scale(projection.scale() * 2 * Math.PI)
.translate(projection([0, 0]))
.tileSize(tileSize)
.clampX(false)
Insert cell
tileSize = 256
Insert cell
Insert cell
path = d3.geoPath(projection)
Insert cell
projection = d3.geoMercator().rotate([-180, 0]).fitExtent([[padding, padding],[width - padding, height - padding]],points)
Insert cell
padding = 50
Insert cell
boundaries = topojson.feature(boundaries_topo, boundaries_topo.objects["Pacific countries"])
Insert cell
boundaries_topo = FileAttachment("pacific-boundaries.json").json()
Insert cell
points = FileAttachment("countries@2.geojson").json()
Insert cell
countries = FileAttachment("countries.json").json()
Insert cell
d3 = require("d3-geo@3", "d3-tile@1")
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