A first attempt at panning and zooming with Orthographic projection. See also Orthographic Zoom II.
Uses world-110m geographic shapes from TOPOJSON World Atlas.
Inspired by
| license: mit |
A first attempt at panning and zooming with Orthographic projection. See also Orthographic Zoom II.
Uses world-110m geographic shapes from TOPOJSON World Atlas.
Inspired by
| <!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> |