Skip to content

Instantly share code, notes, and snippets.

@Fil
Last active November 23, 2016 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fil/db1d5b7abf91bfe1ff6b2c3e078276d1 to your computer and use it in GitHub Desktop.
Save Fil/db1d5b7abf91bfe1ff6b2c3e078276d1 to your computer and use it in GitHub Desktop.
topojson.topology + topojson.mesh
license: mit
<!DOCTYPE html>
<canvas width="960" height="600"></canvas>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://d3js.org/d3-geo-projection.v1.min.js"></script>
<script src="https://d3js.org/topojson.v2.min.js"></script>
<script src="https://unpkg.com/topojson"></script>
<script>
var context = d3.select("canvas").node().getContext("2d"),
path = d3.geoPath()
.projection(d3.geoAitoff())
.context(context);
d3.json("USA.json", function(error, geo) {
if (error) throw error;
// convert geojson to topojson with unpkg.com/topojson
// for performance reasons, should rather be off browser
const topo = topojson.topology({foo: geo});
// draw topojson with d3js.org/topojson.v2
context.beginPath();
context.fillStyle = '#fee'
context.strokeStyle = '#caa'
path(topojson.mesh(topo));
context.stroke();
context.fill();
});
</script>
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