-
Notifications
You must be signed in to change notification settings - Fork 4
/
index_heatmap.html
129 lines (104 loc) · 4.31 KB
/
index_heatmap.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
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8" />
<script src="jquery-3.4.1.min.js"></script>
<link rel="stylesheet" href="node_modules/leaflet/dist/leaflet.css" />
<script src="node_modules/leaflet/dist/leaflet.js"></script>
<script src="node_modules/heatmap.js/build/heatmap.js"></script>
<script src="node_modules/heatmap.js/plugins/leaflet-heatmap/leaflet-heatmap.js"></script>
</head>
<body>
<div>
<div id="vehiclelist" style="height: 90%; width: 380px;float: left; position: absolute; overflow: auto"></div>
<div id="mapid" style="height: 100px; float: left; position: absolute; left: 390px"></div>
</div>
<script type="text/javascript">
var map = null;
var positions = [];
var baseLayer = L.tileLayer(
'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: 'Kartendaten © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> Mitwirkende',
useCache: true,
maxZoom: 18
}
);
var cfg = {
// radius should be small ONLY if scaleRadius is true (or small radius is intended)
// if scaleRadius is false it will be the constant radius used in pixels
"radius": 10,
"maxOpacity": .8,
// scales the radius based on map zoom
"scaleRadius": false,
// if set to false the heatmap uses the global maximum for colorization
// if activated: uses the data maximum within the current map boundaries
// (there will always be a red spot with useLocalExtremas true)
"useLocalExtrema": false,
// which field name in your data represents the latitude - default "lat"
latField: 'lat',
// which field name in your data represents the longitude - default "lng"
lngField: 'lng',
// which field name in your data represents the data value - default "value"
valueField: 'count'
};
var heatmapLayer = new HeatmapOverlay(cfg);
map = new L.Map('mapid', {
center: new L.LatLng(51.7251, 8.7762),
zoom: 13,
layers: [baseLayer, heatmapLayer]
});
$("#mapid").height($(window).height()-50).width($(window).width()-$("#vehiclelist").width());
map.invalidateSize();
$.getJSON("http://localhost:3000/log", function(json) {
if (json && json['rows']) {
var rows = json['rows'];
for (var i = 0; i < rows.length; i++) {
var scooterData = rows[i];
if (scooterData) {
positions.push({
lng: scooterData['lng'],
lat: scooterData['lat'],
count: 1
});
}
}
drawHeatMap(positions);
}
});
var vehicles = [];
$.getJSON("http://localhost:3000/vehicles", function(json) {
if (json && json['rows']) {
var rows = json['rows'];
for (var i = 0; i < rows.length; i++) {
var scooterData = rows[i];
if (scooterData) {
vehicles.push(scooterData);
}
}
createVehicleList(vehicles);
}
});
function drawHeatMap(positions) {
var data = {
data: positions
};
heatmapLayer.setData(data);
}
function createVehicleList(vehicles) {
var content = "<h2>Fahrzeuge (" + vehicles.length + ")</h2>";
content += '<table><th>vin</th><th>licence</th><th>lastLocationUpdate</th><th>logCounter</th>';
for (var i = 0; i < vehicles.length; i++) {
var v = vehicles[i];
content += "<tr>";
content += "<td>" + v["vin"] + "</td>";
content += "<td>" + v["licencePlate"] + "</td>";
content += "<td>" + v["lastLocationUpdate"] + "</td>";
content += "<td>" + v["logCounter"] + "</td>";
content += "</tr>";
}
content += "</table>";
$("#vehiclelist").html(content);
}
</script>
</body>
</html>