-
Notifications
You must be signed in to change notification settings - Fork 0
/
index2.html
192 lines (171 loc) · 5.34 KB
/
index2.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<!DOCTYPE html>
<meta charset="utf-8">
<title>spatialsankey.js - sankey diagrams on a map</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ==" crossorigin=""/><style>
body {
position: absolute;
width:100%;
height: 100%;
margin: 0px;
font-family: sans-serif;
}
#map {
top:0px;
left:0px;
right:0px;
height: 100%;
}
path {
fill: none;
stroke: #4682B4;
stroke-opacity: 0.6;
stroke-linecap: round;
cursor: pointer;
}
path:hover {
stroke-opacity: 0.8;
stroke: #315B7E;
}
.curvesettings {
position: absolute;
right: 10px;
top:6px;
}
.box {
border: 1px solid #EEE;
margin: 3px;
padding: 5px;
background-color: white;
font-family: sans-serif;
font-size: 12px;
}
.title {
font-weight: 600;
}
.source {
position: absolute;
width: 50%;
top: 6px;
left: 50px;
}
</style>
<body>
<div id="map"></div>
<form class="curvesettings">
<div class="box">
<div class="title">Hover</div>
<div>Hover over nodes<br> to see links.</div>
</div>
</form>
</body>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha512-/Nsx9X4HebavoBvEBuyp3I7od5tA0UzAxs+j83KgC8PU0kgB4XiK4Lfe4y4cgBtaRJQEIFCW+oC506aPT2L1zw==" crossorigin=""></script>
<script src="http://d3js.org/d3.v4.min.js"></script>
<!--script src="http://rawgit.com/geodesign/spatialsankey/master/spatialsankey.js"></script-->
<script src="../spatialsankey/spatialsankey.js"></script>
<script type="text/javascript">
// Set leaflet map
var map = new L.map('map', {
center: new L.LatLng(45.555555, -73.647647),
zoom: 12,
layers: [
new L.tileLayer('http://{s}tile.stamen.com/toner-lite/{z}/{x}/{y}.png', {
subdomains: ['','a.','b.','c.','d.'],
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>'
})
]
});
// Initialize the SVG layer
//map._initPathRoot()
var svgLayer = L.svg();
svgLayer.addTo(map);
var svg = d3.select("#map").select("svg");
g = svg.append("g");
/*
d3.json("data_out/circles.json", function(collection) {
// Add a LatLng object to each item in the dataset
collection.objects.forEach(function(d) {
d.LatLng = new L.LatLng(d.circle.coordinates[0],
d.circle.coordinates[1])
})
var feature = g.selectAll("circle")
.data(collection.objects)
.enter().append("circle")
.style("stroke", "black")
.style("opacity", .6)
.style("fill", "red")
.attr("r", 20);
map.on("viewreset", update);
update();
function update() {
feature.attr("transform",
function(d) {
return "translate("+
map.latLngToLayerPoint(d.LatLng).x +","+
map.latLngToLayerPoint(d.LatLng).y +")";
}
)
}
})
*/
d3.json("data_out/Stations_2017.geojson", function(mapData) {
d3.csv("data_out/bixi_flow.csv", function(flows) {
console.log(flows[0]);
var the_total = 0;
var the_station = 7005;
var the_biggest = null;
var dictionary = {};
flows.forEach(function(d) {
d.flow = +d.flow; //convert string to number
d.start_station_code = +d.start_station_code; //convert string to number
d.end_station_code = +d.end_station_code; //convert string to number
if (d.start_station_code == the_station) {
dictionary[d.end_station_code]=d.flow;
the_total += d.flow;
//console.log(d);
if (the_biggest == null) {
the_biggest = d;
console.log("############################");
console.log(d);
}
else {
if (the_biggest.flow < d.flow) {
the_biggest = d;
console.log("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
console.log(d);
}
}
}
});
console.log(flows[0]);
console.log("The station #" + the_station + " total is: " + the_total);
console.log("The station #" + the_station + " biggest flow is: " + the_biggest.flow + " from station#" + the_biggest.end_station_code);
var the_features = mapData.features;
//console.log(the_features);
// Add a LatLng object to each item in the dataset (invert them since coming from geojson)
the_features.forEach(function(d) {
d.LatLng = new L.LatLng(d.geometry.coordinates[1],
d.geometry.coordinates[0])
})
var feature = g.selectAll("geometry")
.data(the_features)
.enter()
.append("circle")
.style("stroke", "black")
.style("opacity", .6)
.style("fill", "blue")
.attr("r", 10);//(((32-2)*(dictionary[]/the_biggest.flow))+2));
map.on("viewreset", update);
map.on("zoomend", update);
update();
function update() {
feature.attr("transform",
function(d) {
return "translate("+
map.latLngToLayerPoint(d.LatLng).x +","+
map.latLngToLayerPoint(d.LatLng).y +")";
}
)
}
})
})
</script>