Skip to content

Instantly share code, notes, and snippets.

@Fil
Last active February 24, 2017 17:44
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/26e008c8da04f9577dca7d5899f58528 to your computer and use it in GitHub Desktop.
Save Fil/26e008c8da04f9577dca7d5899f58528 to your computer and use it in GitHub Desktop.
topojson tests [UNLISTED]
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-client@2"></script>
<script src="https://unpkg.com/topojson-simplify@2"></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});
topojson.presimplify(topo);
topojson.simplify(topo, 120);
console.log(topo.arcs[0].length);
// 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