Skip to content

Instantly share code, notes, and snippets.

@arkut
Last active March 4, 2019 23:21
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 arkut/13b6fa6b67a7e320194bec44c544d894 to your computer and use it in GitHub Desktop.
Save arkut/13b6fa6b67a7e320194bec44c544d894 to your computer and use it in GitHub Desktop.
Mapping Nebraska school districts with D3 v4
<!DOCTYPE html>
<style>
.districts {
fill: steelblue;
}
.districts :hover {
fill: red;
}
.district-borders {
fill: none;
stroke: #fff;
stroke-width: 0.5px;
stroke-linejoin: round;
stroke-linecap: round;
pointer-events: none;
}
</style>
<svg width="960" height="600"></svg>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://d3js.org/topojson.v2.min.js"></script>
<script src="https://d3js.org/d3-queue.v3.min.js"></script>
<script>
var svg = d3.select('svg');
var projection = d3.geoConicConformal()
.parallels([40, 43])
.rotate([100, 0]);
var path = d3.geoPath()
.projection(projection);
d3.json("ne-district-id-topo.json", function(error, ne) {
if (error) throw error;
var featureCollection = topojson.feature(ne, ne.objects.districts);
projection.fitSize([960,580],featureCollection);
svg.append("g")
.attr("class", "districts")
.selectAll("path")
.data(featureCollection.features)
.enter().append("path")
.attr("d", path);
svg.append("path")
.attr("class", "district-borders")
.attr("d", path(topojson.mesh(ne, ne.objects.districts, function(a, b) { return a !== b; })));
});
function round(value, precision) {
var multiplier = Math.pow(10, precision || 0);
return Math.round(value * multiplier) / multiplier;
}
</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