Public
Edited
Aug 1, 2023
28 forks
51 stars
Insert cell
Insert cell
Insert cell
deltas = [-100, -4, -1, 0]
Insert cell
map = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);

const tile = d3.tile()
.extent([[0, 0], [width, height]])
.tileSize(512)
.clampX(false);

const zoom = d3.zoom()
.scaleExtent([1 << 8, 1 << 22])
.extent([[0, 0], [width, height]])
.on("zoom", (event) => zoomed(event.transform));

const levels = svg.append("g")
.attr("pointer-events", "none")
.selectAll("g")
.data(deltas)
.join("g")
.style("opacity", showlayers ? 0.3 : null);

svg
.call(zoom)
.call(zoom.transform, mutable transform);

function zoomed(transform) {
mutable transform = transform;

levels.each(function(delta) {
const tiles = tile.zoomDelta(delta)(transform);

d3.select(this)
.selectAll("image")
.data(tiles, d => d)
.join("image")
.attr("xlink:href", d => url(...d3.tileWrap(d)))
.attr("x", ([x]) => (x + tiles.translate[0]) * tiles.scale)
.attr("y", ([, y]) => (y + tiles.translate[1]) * tiles.scale)
.attr("width", tiles.scale)
.attr("height", tiles.scale);
});
}

return svg.node();
}
Insert cell
mutable transform = d3.zoomIdentity.translate(width >> 1, height >> 1).scale(1 << 12)
Insert cell
// Kartendaten: © [OpenStreetMap](https://openstreetmap.org/copyright)-Mitwirkende, SRTM | Kartendarstellung: © [OpenTopoMap](http://opentopomap.org/) (CC-BY-SA)
url = (x, y, z) => `https://tile.opentopomap.org/${z}/${x}/${y}.png`
Insert cell
d3 = require("d3@7", "d3-tile@1")
Insert cell
height = 600 // note: observable sets a responsive *width*
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