-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.html
executable file
·130 lines (101 loc) · 3.8 KB
/
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
124
125
126
127
128
129
130
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My map</title>
<script type="text/javascript" src="https://d3js.org/d3.v5.min.js"></script>
<script src="https://d3js.org/d3-geo-projection.v2.min.js"></script>
<script src="https://d3js.org/topojson.v1.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=IBM+Plex+Sans&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="map.css">
<style></style>
</head>
<body>
<div class="container-fluid title">
<div class="row">
<div class="col-lg-12">
<h1>le 630 fontanelle di toronto</h1>
<h2>per avere sempre acqua fresca</h2>
</div>
</div>
</div>
<p class="container-fluid title"><a href="https://www.reddit.com/r/running/comments/3eaxsp/toronto_runners_i_made_a_map_of_water_fountains/">
Qua puoi trovare la fonte ufficiosa</a>
<br><br>In realtà, come ben saprai, ci sono molte altre fontanelle a Toronto, ma sono riuscita a scaricare i dati solo di queste 630.
<br> Se vuoi più fontanelle vai sul tuo amato <a href="https://www.fontanelle.org/">fontanelle.org</a>.
<br>Dammi tempo e avrai tutte le 3000 fontanelle di Toronto anche qua.
<br><br> 🍄 Fatto con affetto, Bea 🍄</p>
<div class="container-fluid">
<div class="row">
<div class="image col-lg-12">
<h2>Guardalo da Desktop</h2>
<img src="assets/pic.png">
</div>
</div>
</div>
<div id="container"></div>
<script type="text/javascript">
var w = 1400;
var h = 650;
var svg = d3.select("div#container")
.append("svg")
.attr("preserveAspectRatio", "xMinYMin meet")
.attr("viewBox", "0 0 " + w + " " + h)
.classed("svg-content", true);
var projection = d3.geoMercator()
.translate([0, 0])
.scale(1);
var path = d3.geoPath()
.projection(projection);
// load data
var toronto = d3.json("toronto.geojson");
var fountains = d3.csv("fountains.csv");
Promise.all([toronto, fountains]).then(function(values) {
console.log(values[0]);
var b = path.bounds(values[0]),
s = .95 / Math.max((b[1][0] - b[0][0]) / w, (b[1][1] - b[0][1]) / h),
t = [(w - s * (b[1][0] + b[0][0])) / 2, (h - s * (b[1][1] + b[0][1])) / 2];
projection
.scale(s)
.translate(t);
// draw map
svg.selectAll("path")
.data(values[0].features)
.enter()
.append("path")
.attr("class", "continent")
.attr("d", path);
svg.selectAll("circle")
.data(values[1])
.enter()
.append("circle")
.attr("class", "circles")
.attr("cx", function(d) {
return projection([d.Longitude, d.Latitude])[0];
})
.attr("cy", function(d) {
return projection([d.Longitude, d.Latitude])[1];
})
.attr("r", "1px");
// add labels
d3.selectAll(".circles")
.on("click", function(d) {
svg.selectAll("text")
.remove();
svg.append("svg:a").attr("xlink:href", "http://www.google.com/maps/place/" + d.Latitude + "," + d.Longitude)
.attr("target", "_blank")
.append("svg:text")
.text(d.name)
.attr("x", projection([d.Longitude, d.Latitude])[0])
.attr("y", projection([d.Longitude, d.Latitude])[1])
.attr("class", "labels")
.attr("text-anchor", "middle")
.attr("dy", 15)
.attr("dx", 5.5);
});
});
</script>
</body>
</html>