Skip to content

Instantly share code, notes, and snippets.

@curran
Last active May 6, 2020 20:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save curran/4f4c6ef5dde876fca80906d5e5c13344 to your computer and use it in GitHub Desktop.
Save curran/4f4c6ef5dde876fca80906d5e5c13344 to your computer and use it in GitHub Desktop.
Orthographic Zoom I
license: mit
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://d3js.org/topojson.v1.min.js"></script>
</head>
<body>
<svg width="960" height="500"></svg>
<script>
const svg = d3.select('svg');
const path = svg.append('path');
const projection = d3.geoOrthographic();
const initialScale = projection.scale();
const geoPath = d3.geoPath().projection(projection);
const sensitivity = 58;
d3.json('world-110m.json', (error, world) => {
const land = topojson.feature(world, world.objects.land);
const render = () => path.attr('d', geoPath(land));
render();
svg
.call(d3.drag().on('drag', () => {
const rotate = projection.rotate();
const k = sensitivity / projection.scale();
projection.rotate([
rotate[0] + d3.event.dx * k,
rotate[1] - d3.event.dy * k
])
render();
}))
.call(d3.zoom().on('zoom', () => {
projection.scale(initialScale * d3.event.transform.k);
render();
}));
});
</script>
</body>
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment