Skip to content

Instantly share code, notes, and snippets.

@diggetybo
Created March 26, 2017 14:04
Show Gist options
  • Save diggetybo/aac0758110dadd352ed730887d348ec0 to your computer and use it in GitHub Desktop.
Save diggetybo/aac0758110dadd352ed730887d348ec0 to your computer and use it in GitHub Desktop.
Geo Circles
<html><head><meta charset="utf-8">
<title>Geo Circle</title>
<style>
.button {
font-family: Play;
color: #ffffff;
font-size: 16px;
text-align: center;
display: inline-block;
-webkit-user-select: none;
width: 3.2%;
background: #303030;
padding: 10px 20px 10px 20px;
}
.button:hover {
background: #4c4d4d;
cursor:default;
}
</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');
var geo_path = d3.geo.path().projection(projection);
var circle = d3.geo.circle().radius(100/3959*90).center([-114.52,33.75]);
countiesG.selectAll('.circle')
.enter().append('path')
.datum(circle)
.attr('class','circle')
.attr('d',geo_path);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment