-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.html
174 lines (148 loc) · 7.66 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
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
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Projek D3JS</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/style/style.css">
<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">
</head>
<body>
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<style>
path {
fill: none;
stroke: #000;
stroke-linejoin: round;
stroke-linecap: round;
}
canvas{
width: 100%;
height: auto;
}
/* svg{
background-color:blueviolet;
stroke: aliceblue;
} */
</style>
<nav class="navbar navbar-expand-sm navbar-dark bg-primary">
<a class="navbar-brand" href="#">Projek D3js</a>
<button class="navbar-toggler d-lg-none" type="button" data-toggle="collapse" data-target="#collapsibleNavId" aria-controls="collapsibleNavId"
aria-expanded="false" aria-label="Toggle navigation"></button>
<div class="collapse navbar-collapse" id="collapsibleNavId">
<ul class="navbar-nav mr-auto mt-2 mt-lg-0">
<li class="nav-item">
<a class="nav-link" href="index.html">Home - Calendar View <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item active">
<a class="nav-link" href="map.html">Bubble Map</a>
</li>
<li class="nav-item">
<a class="nav-link" href="index1.html">Bar Chart</a>
</li>
<li class="nav-item">
<a class="nav-link" href="donut.html">Donat Chart</a>
</li>
<li class="nav-item">
<a class="nav-link" href="streamgraph.html">Streamgraph</a>
</li>
<li class="nav-item">
<a class="nav-link" href="heatmap.html">HeatMap</a>
</li>
</ul>
</div>
</nav>
<script src="http://d3js.org/d3.v4.js"></script>
<script src="https://d3js.org/d3-geo-projection.v2.min.js"></script>
<!-- Load Leaflet -->
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.4/dist/leaflet.css" integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA==" crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.3.4/dist/leaflet.js" integrity="sha512-nMMmRyTVoLYqjP9hrbed9S+FzjZHW5gY1TWCHA5ckwXZBadntCNs8kEqAWdrb9O7rxbCaA4lKTIWjDXZxflOcA==" crossorigin=""></script>
<!-- Create an element where the map will take place -->
<div class="container-fluid shadow p-3 mb-5 bg-white rounded">
<div id="mapid" ></div>
</div>
<style>
#mapid { height: 650px; }
</style>
<script>
var map = L
.map('mapid')
.setView([47, 2], 4 ); // center position + zoom
// Add a tile to the map = a background. Comes from OpenStreetmap
L.tileLayer(
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a>',
maxZoom: 6,
}).addTo(map);
// Add a svg layer to the map
L.svg().addTo(map);
d3.csv('data/taxi2.csv', function(data){
// Three function that change the tooltip when user hover / move / leave a cell
d3.select("#mapid")
.select("svg")
.selectAll("myCircles")
.data(data)
.enter()
.append("circle")
.attr("cx", function(d){ return map.latLngToLayerPoint([d.dropoff_latitude, d.dropoff_longitude]).x })
.attr("cy", function(d){ return map.latLngToLayerPoint([d.dropoff_latitude, d.dropoff_longitude]).y })
.attr("r", 14)
.style("fill", "blue")
.attr("stroke", "white")
.attr("stroke-width", 3)
.attr("fill-opacity", .4)
// console.log(data)
// console.log(data[0].dropoff_latitude)
for (let i = 0; i < data.length; i++) {
var marker1 = L.marker([data[i].dropoff_latitude,data[i].dropoff_longitude]).addTo(map)
.bindPopup("Vendor : " + data[i].vendor_id + "<br>Lat : "+ data[i].dropoff_latitude+ "<br>Long : "+
data[i].dropoff_longitude);
}
let isClicked = false
marker1.on({
mouseover: function() {
if(!isClicked) {
this.openPopup()
}
},
mouseout: function() {
if(!isClicked) {
this.closePopup()
}
},
click: function() {
isClicked = true
this.openPopup()
}
})
map.on ({
click: function() {
isClicked = false
},
popupclose: function () {
isClicked = false
}
});
});
// Select the svg area and add circles:
// Function that update circle position if something change
function update() {
d3.selectAll("circle")
.attr("cx", function(d){ return map.latLngToLayerPoint([d.dropoff_latitude, d.dropoff_longitude]).x })
.attr("cy", function(d){ return map.latLngToLayerPoint([d.dropoff_latitude, d.dropoff_longitude]).y })
}
// If the user change the map (zoom or drag), I update circle position:
map.on("moveend", update)
</script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>