Skip to content

Instantly share code, notes, and snippets.

@diggetybo
Last active March 28, 2017 09:03
Show Gist options
  • Save diggetybo/826071f2c0757f07101defba62c8c38e to your computer and use it in GitHub Desktop.
Save diggetybo/826071f2c0757f07101defba62c8c38e to your computer and use it in GitHub Desktop.
JSON County in State Event
<html><head><meta charset="utf-8">
<title>County in State</title>
<style>
</style>
</head><body>
<script src="https://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 500;
var margins = { left: 0, top: 0, right: 0, bottom: 0 };
var projection = d3.geo.albersUsa()
.scale(1070)
.translate([width / 2, height / 2]);
var path = d3.geo.path()
.projection(projection);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr('class','main_svg')
.attr("height", height+margins.top);
var g = svg.append("g");
var countiesG = g.append("g")
.attr("id", "counties");
d3.json("https://gist.githubusercontent.com/diggetybo/6d35e5ecd17992650d0a23896e649b25/raw/0501b427f7b060a59499a11f2c2c781ecc413874/us_ap.json", function(error, us) {
countiesG
.selectAll("path")
.data(topojson.feature(us, us.objects.counties).features)
.enter().append("path")
.attr("d", path)
.attr("stroke-width",'.5px')
.attr('stroke','#fff')
.attr('fill','#aaa')
.on('click.whats_my_state', function(d) {return
var containing_state = us.objects.whatever_state_this_county_is_in;
console.log(containing_state);
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment