forked from gerrymandr/ap-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor.html
77 lines (63 loc) · 1.81 KB
/
color.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.map path {
stroke: rgb(0, 0, 0);
fill: white;
stroke-width: 0.1;
}
.map2 path {
stroke: #fff;
stroke-width: 0.1;
}
</style>
<body>
Michael's test page
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js"></script>
<svg id="mapGoesHere" width="600px" height="600px">
<g class="map"></g>
</svg>
<script>
// Colors for each user-assigned district
var districtColors = ["green","yellow", "purple"]
var width =600,
height = 600;
var svg = d3.select("#mapGoesHere")
.attr("width", width)
.attr("height", height);
function load(geojson, classname) {
var projection = d3.geoAlbers()
.fitSize([width, height], geojson);
// Manually assign a few areas to districts
geojson.features[0].properties.district = 2
geojson.features[4].properties.district = 2
geojson.features[1].properties.district = 0
geojson.features[2].properties.district = 0
geojson.features[3].properties.district = 1
var geoGenerator = d3.geoPath()
.projection(projection);
d3.select(classname)
.selectAll('path')
.data(geojson.features)
.enter()
.append('path')
.attr('d', geoGenerator)
.style("fill",function(d,i){
// Get the district that has been assigned by the user
// Should be a zero-based number
// or missing for unassigned areas
var district = d.properties.district
return districtColors[district];
})
.on('click', function(d) {
d3.select(this)
.style('fill', districtColors[1])
d.properties.district = 1
})
}
/* JavaScript goes here. */
d3.json("data/Penn MCDS Data/Chester/Chester.geojson", function(error, geojson) {
console.log(geojson)
load(geojson, '.map');
});
</script>