forked from gerrymandr/ap-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchester.html
62 lines (51 loc) · 1.24 KB
/
chester.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>2017 General Election</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js"></script>
</head>
<style>
.county path {
stroke: #f00;
stroke-width: 0.1;
fill: #f00;
}
</style>
<body>
<div id="Chester County">
<svg width="600px" height="500px">
<g class="county">
</g>
</svg>
</div>
<script>
var width = 500, height = 400;
function load(geojson, classname) {
// determines how geo coords are translated to graphics
var projection = d3.geoAlbersUsa()
.fitSize([width, height], geojson);
// object that takes geoJson data and makes
// an SVG path
var geoGenerator = d3.geoPath()
.projection(projection);
// Classic D3 activity
// Attaches a path to each object
d3.select(classname)
.selectAll('path')
.data(geojson.features)
.enter()
.append('path')
.attr('d', geoGenerator) // d here is the svg object data attribute
.on('click', function() {
d3.select(this)
.style('fill', '#00f')
})
}
d3.json('data/Penn County/Chester.geojson', function(err, geojson) {
console.log(geojson.features[0].geometry.coordinates)
load(geojson, '.county');
});
</script>
</body>
</html>