-
Notifications
You must be signed in to change notification settings - Fork 1
/
nonagg-googleMaps.html
134 lines (116 loc) · 3.53 KB
/
nonagg-googleMaps.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?1.29.1"></script>
<style type="text/css">
html, body, #map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.crashes, .crashes svg {
position: absolute;
}
.crashes svg {
width: 60px;
height: 20px;
padding-right: 100px;
font: 10px sans-serif;
}
.crashes circle {
stroke: black;
stroke-width: 1.5px;
}
</style>
</head>
<body>
<div id="map"></div>
<script type="text/javascript">
// Create the Google Map…
var map = new google.maps.Map(d3.select("#map").node(), {
zoom: 12,
center: new google.maps.LatLng(44.9763201,-93.2708829),
mapTypeId: google.maps.MapTypeId.TERRAIN
});
d3.csv("bicycle-data.csv", function(data) {
//data = data.filter(function(d, i) { return d.Level == "Fatalities"; });
var overlay = new google.maps.OverlayView();
// Add the container when the overlay is added to the map.
overlay.onAdd = function() {
var layer = d3.select(this.getPanes().overlayLayer).append("div")
.attr("class", "crashes");
// Draw each marker as a separate SVG element.
// We could use a single SVG, but what size would it have?
overlay.draw = function() {
var projection = this.getProjection(),
padding = 10;
console.log(data);
var marker = layer.selectAll("svg")
.data(d3.entries(data))
.each(transform) // update existing markers
.enter().append("svg:svg")
.each(transform)
.attr("class", "marker");
// Add a circle.
marker.append("svg:circle")
.attr("r", function(d){
if (d.value.Level == "Possible Injury (C)"){
return "2";
}
else if (d.value.Level == "Fatalities"){
return "5";
}
else if (d.value.Level == "Property Damage Only"){
return "1";
}
else if (d.value.Level == "Non-Incap. Injury (B)"){
return "3";
}
else if (d.value.Level == "Incap. Injury (A)"){
return "4";
}
})
.attr("opacity", 0.6)
.attr("cx", padding)
.attr("cy", padding)
.attr("fill", function(d){
if (d.value.Level == "Possible Injury (C)"){
return "purple";
}
else if (d.value.Level == "Fatalities"){
return "red";
}
else if (d.value.Level == "Property Damage Only"){
return "green";
}
else if (d.value.Level == "Non-Incap. Injury (B)"){
return "yellow";
}
else if (d.value.Level == "Incap. Injury (A)"){
return "orange";
}
});
// Add a label.
/* marker.append("svg:text")
.attr("x", padding + 7)
.attr("y", padding)
.attr("dy", ".31em")
.text(function(d) { return d.Level; });*/
function transform(d) {
d = new google.maps.LatLng(d.value.lat, d.value.long);
d = projection.fromLatLngToDivPixel(d);
return d3.select(this)
.style("left", (d.x - padding) + "px")
.style("top", (d.y - padding) + "px");
}
};
};
// Bind our overlay to the map…
overlay.setMap(map);
});
</script>
</body>
</html>