-
Notifications
You must be signed in to change notification settings - Fork 0
/
citibike.html
201 lines (186 loc) · 6.7 KB
/
citibike.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
193
194
195
196
197
198
199
200
201
<!DOCTYPE html>
<html>
<head>
<script src="https://api.mapbox.com/mapbox-gl-js/v2.2.0/mapbox-gl.js"></script>
<script src="https://unpkg.com/@mapbox/mapbox-sdk/umd/mapbox-sdk.min.js"></script>
<script src="https://mapbox.github.io/mapbox-gl-language/index.js"></script>
<script src="https://unpkg.com/@rtirl/api@latest/lib/index.min.js"></script>
<link
href="https://api.mapbox.com/mapbox-gl-js/v2.2.0/mapbox-gl.css"
rel="stylesheet"
/>
<style>
.mapboxgl-popup-content {
font-size: 16px;
font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Cantarell, Ubuntu, roboto, noto, arial, sans-serif;
}
</style>
</head>
<body>
<div style="position: relative; width: 100%; height: 100%">
<div id="map" style="width: 100%; height: 100%"></div>
<div
id="legend"
style="
background-color: white;
z-index: 100;
position: absolute;
top: 2%;
left: 2%;
padding: 10px;
font-size: 16px;
font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Cantarell, Ubuntu, roboto, noto, arial, sans-serif;
"
>
<p>
Terry's identifier is <strong>TB311</strong> on the
<a
href="https://account.citibikenyc.com/rewards/leaderboard"
target="”_blank”"
>Bike Angel Leaderboard</a
>
</p>
<p>
Watch Terry on
<a href="https://www.twitch.tv/terrybarentsen" target="”_blank”"
>Twitch</a
>
</p>
<p>
What each color means:
<p style="color:red;">take</p>
<p style="color:green;">give</p>
<p style="color:grey;">neutral</p>
</p>
</div>
</div>
<script>
var params = new URLSearchParams(window.location.search);
// Fullscreen
document.documentElement.setAttribute(
"style",
"margin: 0; padding: 0; width: 100%; height: 100%;"
);
document.body.setAttribute(
"style",
"margin: 0; padding: 0; width: 100%; height: 100%;"
);
document
.getElementById("map")
.setAttribute("style", "height: 100%; width: 100%;");
mapboxgl.accessToken =
"pk.eyJ1IjoiampqampqampqampqampqampqaiIsImEiOiJja290MThwMzIwNjNkMndwaHR5djlhYThqIn0.zULjRWtxmVmaWe-FDobI-A";
var zoom = params.get("zoom");
var map = new mapboxgl.Map({
container: "map",
style: "mapbox://styles/mapbox/streets-v11",
interactive: true,
attributionControl: false,
zoom: zoom ? Number(zoom) : 13,
center: [-73.97694530374439, 40.714999683782935],
});
map.addControl(
new MapboxLanguage({ defaultLanguage: params.get("lang") || "en" })
);
map.on("load", () => {
fetch("https://layer.bicyclesharing.net/map/v1/nyc/stations")
.then((response) => response.json())
.then((data) => {
map.addSource("route", {
type: "geojson",
data: {
type: "FeatureCollection",
features: data.features,
},
});
map.addLayer({
id: "stations",
type: "circle",
source: "route",
filter: ["!=", ["get", "bike_angels_action"], null],
paint: {
"circle-radius": {
stops: [[8, 1], [11, 6], [16, 40]]
},
"circle-stroke-width": 2,
"circle-color": [
"match",
["get", "bike_angels_action"],
"take",
"red",
"give",
"green",
"neutral",
"grey",
"white",
],
"circle-stroke-color": "white",
},
});
map.addLayer({
"id": "clusters-label",
"type": "symbol",
"source": "route",
"layout": {
"text-field": ["to-string", ["*",["to-number", ["get", "bike_angels_points"]],3]],
"text-font": [
"DIN Offc Pro Medium",
"Arial Unicode MS Bold"
],
"text-size": 12
}
});
// Create a popup, but don't add it to the map yet.
const popup = new mapboxgl.Popup({
closeButton: true,
closeOnClick: true,
});
map.on("click", "stations", (e) => {
// Change the cursor style as a UI indicator.
map.getCanvas().style.cursor = "pointer";
// Copy coordinates array.
const coordinates = e.features[0].geometry.coordinates.slice();
const name = `<strong>${e.features[0].properties.name}</strong>
<p>Bike Angel Action: ${
e.features[0].properties.bike_angels_action
}</p>
<p>Bike Angel Points: ${
e.features[0].properties.bike_angels_points
}</p>
<p>Bike Angel Digits: ${
e.features[0].properties.bike_angels_digits
}</p>
<p>Bikes Available: ${
e.features[0].properties.bikes_available
}</p>
<p>Last Reported: ${new Date(
e.features[0].properties.last_reported * 1000
)}</p>`;
// Ensure that if the map is zoomed out such that multiple
// copies of the feature are visible, the popup appears
// over the copy being pointed to.
while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) {
coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360;
}
// Populate the popup and set its coordinates
// based on the feature found.
popup.setLngLat(coordinates).setHTML(name).addTo(map);
});
map.on("mouseleave", "stations", () => {
map.getCanvas().style.cursor = "";
// popup.remove();
});
});
});
const marker1 = new mapboxgl.Marker({ color: "pink", scale: 1.5 })
.setLngLat([12.554729, 55.70651])
.addTo(map);
const myStreamerId = params.get("streamerId") ?? "437343696";
RealtimeIRL.forStreamer("twitch", myStreamerId).addLocationListener(
function (location) {
marker1.setLngLat([location.longitude, location.latitude]);
}
);
</script>
</body>
</html>