-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11-16interactivemap.html
executable file
·139 lines (119 loc) · 4.14 KB
/
11-16interactivemap.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
135
136
137
138
139
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>D3 Interactions & Transitions</title>
<script src="https://d3js.org/d3.v5.min.js"></script>
<script src="https://d3js.org/topojson.v2.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/js/bootstrap.min.js"></script>
<style>
.zipcode:hover {
z-index: 1000;
fill: rgb(111, 111, 255);
transition: .3s;
}
#tooltip.hidden {
display: none;
}
#tooltip {
position: absolute;
padding: 5px;
background-color: white;
border: solid gray 1px;
z-index: 10;
pointer-events: none;
}
#map-zoomer {
position: absolute;
writing-mode: bt-lr;
-webkit-appearance: slider-vertical;
width: 8px;
height: 100px;
padding: 0 5px;
position: absolute;
top: 110px;
left: 22px;
}
#float-button-group {
position: fixed;
left: 10px;
opacity: 0.5;
}
#float-button-group:hover {
opacity: 1;
}
</style>
</head>
<body>
<div id="tooltip" class="hidden">
<p><span id="value">100</span></p>
</div>
<div id="main">
<div class="btn-group-vertical" role="group" aria-label="..." id="float-button-group">
<button type="button" class="btn btn-default" id="zoom-in"><span class="glyphicon glyphicon-zoom-in"
aria-hidden="true"></span></button>
<button type="button" class="btn btn-default" id="zoom-out"><span class="glyphicon glyphicon-zoom-out"
aria-hidden="true"></span></button>
<button type="button" class="btn btn-default" id="reset"><span class="glyphicon glyphicon-screenshot"
aria-hidden="true"></span></button>
</div>
<input type="range" value="1" min="1" max="8" orient="vertical" id="map-zoomer" />
</div>
<script type="text/javascript">
// Percent of Households with No Internet Access
// Total households
var nycgeourl = 'datas/00-tractTOzcta/Modified Zip Code Tabulation Areas (MODZCTA).geojson';
var interneturl = 'datas/2-InternetConnectivity.csv';
var height = 800, width = 800;
var svg = d3.select('#main').append('svg').attr('height', height).attr('width', width).attr('style', 'border: solid 1px black');
var projection = d3.geoMercator()
.center([-73.94, 40.70])
.scale(70000)
.translate([width / 2, height / 2]);
var path = d3.geoPath().projection(projection);
// var zoom = d3.zoom().scaleExtent([1, 8]).on('zoom', zoomed);
// svg.call(zoom);
var nycgrp = svg.append('g');
var internet = d3.map();
var promises = [d3.json(nycgeourl), d3.csv(interneturl, function(d) {
internet.set(d.modzcta, [+d['Percent of Households with No Internet Access'], +d['Total households']]);
})];
Promise.all(promises).then(ready);
d3.json(nycgeourl).then(ready);
function ready(nyc) {
nyc.features.pop();
var colors = d3.scaleThreshold().domain(d3.extent(nyc.features, d => d.properties.pop_est)).range(d3.schemeBlues[5]);
nycgrp.selectAll('path').data(nyc.features).enter()
.append('path').attr('class', 'zipcode')
.attr('fill', d => colors(d.properties.pop_est)).attr('stroke', 'gray').attr('d', path)
.on('mouseover', function (d) {
d3.select('#tooltip')
.style('left', d3.event.pageX + 'px')
.style('top', d3.event.pageY + 'px')
.select('#value')
.html('<p>' + String(d.properties.modzcta) + ':<br>' + String(d.properties.pop_est) + '</p>');
d3.select('#tooltip')
.classed('hidden', false);
})
.on('mousemove', function (d) {
d3.select('#tooltip')
.style('left', d3.event.pageX + 'px')
.style('top', d3.event.pageY + 'px')
.select('#value')
.html('<p>' + String(d.properties.modzcta) + ':<br>' + String(d.properties.pop_est) + '</p>');
d3.select('#tooltip')
.classed('hidden', false);
})
.on('mouseout', function () {
d3.select('#tooltip').classed('hidden', true);
});;
};
// function zoomed() {
// svg.selectAll('path').attr('transform', d3.event.transform);
// };
</script>
</body>
</html>