D3’s d3.geoPath can be used with Canvas, not just SVG! This geometry is from us-atlas.
d3.geoPath + Canvas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: gpl-3.0 | |
height: 600 | |
border: no | |
redirect: https://observablehq.com/@d3/u-s-map-canvas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<canvas width="960" height="600"></canvas> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script src="https://unpkg.com/topojson-client@3"></script> | |
<script> | |
var context = d3.select("canvas").node().getContext("2d"), | |
path = d3.geoPath().context(context); | |
d3.json("https://unpkg.com/us-atlas@1/us/10m.json", function(error, us) { | |
if (error) throw error; | |
context.beginPath(); | |
path(topojson.mesh(us)); | |
context.stroke(); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It should be noted that beginPath() should be called manually if you want to redraw after panning or zooming.