-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
154 lines (136 loc) · 4.64 KB
/
index.html
File metadata and controls
154 lines (136 loc) · 4.64 KB
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
<!doctype html>
<html lang="en">
<head>
<title>Rijkswaterstaat Strooit</title>
<meta charset="utf-8">
<meta name="viewport"content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<style>
* {
margin: 0;
padding: 0;
}
#map {
position: absolute;
width: 100%;
height: 100%;
}
#info {
font-size: 18px;
color: black;
position: absolute;
bottom: 20px;
left: 20px;
background-color: white;
border-radius: 4px;
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.65);
padding: 8px;
width: 850px;
}
#info h4 {
display: inline;
font-size: 25px;
}
#info p {
padding-top: 3px;
}
#maptime {
float: right;
padding-left: 20px;
}
a, a:visited {
color: black;
}
</style>
</head>
<body>
</header>
<div id="map"></div>
<div id="info">
<p>
<h4>
<a href="http://www.rijkswaterstaatstrooit.nl/">Rijkswaterstaat Strooit</a>, but using <a href="http://leafletjs.com/">Leaflet</a> and <a href="https://www.mapbox.com/blog/winter-wonderland/">OpenStreetMap</a>.
</h4>
<a id="maptime" href="http://maptime-ams.github.io/"><img src="maptime.png" /></a>
</p>
<p>
This map shows the real-time positions of Rijkswaterstaat's winter service vehicles, and refreshes every 20 seconds. <img src="tractor.png" height="17px" /> are trucks on duty; <img src="tractor-gray.png" height="17px" /> are waiting for snow in their depot. Come to <a href="http://maptime-ams.github.io/">Maptime Amsterdam</a>'s next Meetup to learn how to make interactive maps yourself!
</p>
</div>
<script>
// Rijkswaterstaat Strooit, with Google Maps...
// http://www.rijkswaterstaatstrooit.nl/
// Let's use Leaflet and OpenStreetMap!
// Stolen from https://www.mapbox.com/blog/winter-wonderland/ ...
var mapId = "andreasviglakis.76e0cee7",
accessToken = 'pk.eyJ1IjoiYW5kcmVhc3ZpZ2xha2lzIiwiYSI6IlVremRqN0kifQ.CFFJsLuWWyuhgsZTb51jWg',
tileUrl = "https://{s}.tiles.mapbox.com/v4/" + mapId + "/{z}/{x}/{y}.png?access_token=" + accessToken,
map = L.map('map', {maxZoom: 17}),
tractor = L.icon({
iconUrl: 'tractor.png',
iconSize: [32, 32],
iconAnchor: [16, 16],
popupAnchor: [32, 0]
}),
tractorGray = L.icon({
iconUrl: 'tractor-gray.png',
iconSize: [32, 32],
iconAnchor: [16, 16],
popupAnchor: [32, 0]
});
// URL with JSON containing real-time position of Rijkswaterstaat's winter service vehicles:
var rwsUrl = "http://www.rijkswaterstaatstrooit.nl/include/query.php";
// Rijkswaterstaat does not have CORS enabled...
// Luckily, there is https://jsonp.nodejitsu.com/
var url = "https://jsonp.nodejitsu.com/?url=" + rwsUrl;
L.tileLayer(tileUrl).addTo(map);
var geojsonLayer = L.geoJson(null, {
pointToLayer: function (feature, latlng) {
if (feature.properties.status == 34) {
return L.marker(latlng, {icon: tractorGray});
} else {
return L.marker(latlng, {icon: tractor});
}
}
}).addTo(map);
map.setView([52.3728, 4.9002], 10);
function update () {
d3.json(url, function(json) {
// json is object containing vehicle positions:
// "218320013": [
// [
// "52.72648700",
// "5.75918000",
// "34",
// "2015-02-24 14:51:31"
// ]
// ]
var features = [];
Object.keys(json).forEach(function(key) {
var item = json[key][0];
features.push({
type: "Feature",
properties: {
status: parseInt(item[2]),
timestamp: item[3]
},
geometry: {
type: "Point",
coordinates: [parseFloat(item[1]), parseFloat(item[0])]
}
});
});
geojsonLayer.clearLayers();
geojsonLayer.addData({
type: "FeatureCollection",
features: features
});
});
}
setInterval(update, 20000);
update();
</script>
</body>
</html>