-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstats.js
68 lines (49 loc) · 1.63 KB
/
stats.js
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
//var Firebase = require("firebase");
$(document).ready(function(){
var map = initializeMap();
});
function initializeMap() {
var map = new google.maps.Map(d3.select("#map-canvas").node(), {
zoom: 13,
center: new google.maps.LatLng(37.762111, -122.439488),
mapTypeId: google.maps.MapTypeId.TERRAIN
});
return map;
};
d3.xhr('https://sfcrime.firebaseio.com/-JdyczTmHqiiMaU0uVqX', function(data) {
var overlay = new google.maps.OverlayView();
overlay.onAdd = function() {
var layer = d3.select(this.getPanes().overlayLayer).append("div")
.attr("class", "crimes");
overlay.draw = function() {
var projection = this.getProjection(),
padding = 10;
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", 4.5)
.attr("cx", padding)
.attr("cy", padding);
// Add a label.
marker.append("svg:text")
.attr("x", padding + 7)
.attr("y", padding)
.attr("dy", ".31em")
.text(function(d) { return d.key; });
function transform(d) {
d = new google.maps.LatLng(d.value[1], d.value[0]);
d = projection.fromLatLngToDivPixel(d);
return d3.select(this)
.style("left", (d.x - padding) + "px")
.style("top", (d.y - padding) + "px");
}
};
};
});
overlay.setMap(map);
});