-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbusiness_map.html
123 lines (100 loc) · 3.22 KB
/
business_map.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>D3 | Google Map | Yelp</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/d3/3.4.12/d3.min.js"></script><script src="http://labratrevenge.com/d3-tip/javascripts/d3.tip.v0.6.3.js"></script>
<style type="text/css">
html, body, #map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#panel {
padding: 5px;
width: 200px;
height: 100px;
position: absolute;
bottom: 20px;
right: 20px;
background-color: white;
margin: 20px;
}
.markers, .markers svg {
position: absolute;
}
.markers svg {
width: 60px;
height: 20px;
padding-right: 100px;
font: 10px sans-serif;
}
.markers circle {
fill: brown;
stroke: black;
stroke-width: 1.5px;
}
</style>
</head>
<body>
<div id="map">
</div>
<div id="panel">
<a href="/state/NV">Nevada</a><br>
<a href="/state/AZ">Arizona</a><br>
<a href="/state/WI">Wisconsin</a><br>
</div>
<script type="text/javascript">
var dataset = <%- JSON.stringify(data) %>;
// Set the center location (lat/lng) to be the location of the first business
var first = dataset[0];
var centerLatLng = new google.maps.LatLng(first.latitude, first.longitude);
// Create the Google Map…
var map = new google.maps.Map(d3.select("#map").node(), {
zoom: 12,
center: centerLatLng,
mapTypeId: google.maps.MapTypeId.TERRAIN
});
// Create an overlay
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", "markers");
// Draw each marker as a separate SVG element
overlay.draw = function() {
var projection = this.getProjection(),
padding = 10;
var marker = layer.selectAll("svg")
.data(dataset)
.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.name; });
function transform(d) {
d = new google.maps.LatLng(d.latitude, d.longitude);
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>