-
Notifications
You must be signed in to change notification settings - Fork 10
/
community_lines.php
230 lines (184 loc) · 7.66 KB
/
community_lines.php
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<?php
/*
* This file is part of enviroCar.
*
* enviroCar is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* enviroCar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with enviroCar. If not, see <http://www.gnu.org/licenses/>.
*/
require_once('./assets/includes/authentification.php');
$logged_in = false;
if(!is_logged_in()){
$logged_in = false;
include('header-start.php');
}else{
$logged_in = true;
include('header.php');
}
?>
<style href="./assets/OpenLayers/theme/default/style.css" type="text/css"></style>
<script src="./assets/OpenLayers/OpenLayers.js"></script>
<script src="assets/OpenLayers/Renderer/Heatmap.js"></script>
<div id="loadingIndicator" class="loadingIndicator">
<div style="background:url(./assets/img/ajax-loader.gif) no-repeat center center; height:100px;"></div>
</div>
<div class="container rightband" style="padding-right: 0px">
<div id="sensor_headline" style="float:left"></div>
<div>
<div class="btn-group" style="float:right">
<button class="btn btn-small dropdown-toggle" data-toggle="dropdown"><? echo $choosesensor ?>
<span class="caret"></span>
</button>
<ul id="sensorsDropdown" class="dropdown-menu">
</ul>
</div>
</div>
<div id="map" style="width: 100%; height: 512px; padding-top:20px !important" class="smallmap">
</div>
<p style="float:right; z-index:5000;"><a class="btn" href="routes.php"><? echo $routeoverview ?></a></p>
<div class="row-fluid" id="legend"></div>
</div>
<style type="text/css">
.olControlAttribution{
bottom:0px;
}
#map img{max-width:none;}
</style>
<script type="text/javascript">
var statistics = null;
var chosenSensor = null;
(function(){
var s = window.location.search.substring(1).split('&');
if(!s.length) return;
var c = {};
for(var i = 0; i < s.length; i++) {
var parts = s[i].split('=');
c[unescape(parts[0])] = unescape(parts[1]);
}
window.$_GET = function(name){return name ? c[name] : c;}
}())
function onFeatureUnselect(feature){
popup.destroy();
popup = null;
}
var map = new OpenLayers.Map('map');
//var mapnik = new OpenLayers.Layer.OSM();
//map.addLayer(mapnik);
var grey = new OpenLayers.Layer.OSM('Simple OSM Map', null, {
eventListeners: {
tileloaded: function(evt) {
var ctx = evt.tile.getCanvasContext();
if (ctx) {
var imgd = ctx.getImageData(0, 0, evt.tile.size.w, evt.tile.size.h);
var pix = imgd.data;
for (var i = 0, n = pix.length; i < n; i += 4) {
pix[i] = pix[i + 1] = pix[i + 2] = (3 * pix[i] + 4 * pix[i + 1] + pix[i + 2]) / 8;
}
ctx.putImageData(imgd, 0, 0);
evt.tile.imgDiv.removeAttribute("crossorigin");
evt.tile.imgDiv.src = ctx.canvas.toDataURL();
}
}
}
});
map.addLayer(grey);
map.setCenter(new OpenLayers.LonLat(7.9,51,9),8);
var routes = new OpenLayers.Layer.Vector("Routes");
map.addLayer(routes);
function changeSensor(property){
for(i = 0; i < statistics.length; i++){
if(property == statistics[i].phenomenon.name) chosenSensor = statistics[i];
}
for(i = 0; i < routes.features.length; i++){
var style = {
strokeColor: getColor(routes.features[i].attributes[chosenSensor.phenomenon.name]),
strokeOpacity: 0.8,
strokeWidth: 5
};
routes.features[i].style = style;
}
routes.redraw();
$('#sensor_headline').html(property);
drawLegend(property, chosenSensor.phenomenon.unit);
}
function createThematicRoutes(track){
features = track.features;
for(i = 0; i < features.length-1; i++){
if(features[i].properties.osm_id == features[i+1].properties.osm_id){
var points = new Array(
new OpenLayers.Geometry.Point(features[i].geometry.coordinates[0], features[i].geometry.coordinates[1]).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()),
new OpenLayers.Geometry.Point(features[i+1].geometry.coordinates[0],features[i+1].geometry.coordinates[1]).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject())
);
var line = new OpenLayers.Geometry.LineString(points);
var style = {
strokeColor: '#0008FF',
strokeOpacity: 0.5,
strokeWidth: 5
};
//}
var lineFeature = new OpenLayers.Feature.Vector(line, null, style);
lineFeature.attributes['Speed'] = (features[i].properties.Speed+features[i+1].properties.Speed)/2;
lineFeature.attributes['CO2'] = (features[i].properties.CO2+features[i+1].properties.CO2)/2;
routes.addFeatures([lineFeature]);
}
}
map.zoomToExtent(routes.getDataExtent());
}
function getColor(property){
var range = chosenSensor.max - chosenSensor.min;
var steps = range/5;
if(property < chosenSensor.min + steps) return "#1BE01B";
else if(property < chosenSensor.min + steps * 2) return "#B5E01B";
else if(property < chosenSensor.min + steps * 3) return "#E0C61B";
else if(property < chosenSensor.min + steps * 4) return "#E08B1B";
else return "#E01B1B";
}
function drawLegend(property, unit){
var range = chosenSensor.max - chosenSensor.min;
var steps = range/5;
var step1 = Math.round(chosenSensor.min + steps);
var step2 = Math.round(chosenSensor.min + steps * 2);
var step3 = Math.round(chosenSensor.min + steps * 3);
var step4 = Math.round(chosenSensor.min + steps * 4);
document.getElementById('legend').innerHTML='<div class="span2"><img src="assets/img/legend/legend1.png">'+' 0 - ' + step1 + ' ' + unit +'</div>'+
'<div class="span2"><img src="assets/img/legend/legend2.png">'+ ' ' + step1 + ' - '+ step2 + ' ' + unit +'</div>'+
'<div class="span2"><img src="assets/img/legend/legend3.png">'+ ' ' + step2 + ' - '+ step3 + ' ' + unit +'</div>'+
'<div class="span2"><img src="assets/img/legend/legend4.png">'+ ' ' + step3 + ' - '+ step4 + ' ' + unit +'</div>'+
'<div class="span2"><img src="assets/img/legend/legend5.png">'+ ' ' + step4 + ' - '+ Math.round(chosenSensor.max) + ' ' + unit +'</div>';
}
$.get('../data-aggregation/statistics.php', function(data) {
if(data >= 400){
console.log('error in getting statistics');
error_msg("Route couldn't be loaded successfully.");
}else{
data = JSON.parse(data);
statistics = data.statistics;
}
});
//GET the information about the specific track
$.get('../data-aggregation/tracks.php', function(data) {
if(data == 400 || data == 401 || data == 402 || data == 403 || data == 404){
console.log('error in getting tracks');
error_msg("Route couldn't be loaded successfully.");
$('#loadingIndicator').hide();
}else{
data = JSON.parse(data);
createThematicRoutes(data);
$('#sensorsDropdown').append('<li><a href="javascript:changeSensor(\'Speed\')">Speed</a></li>');
$('#sensorsDropdown').append('<li><a href="javascript:changeSensor(\'CO2\')">CO2</a></li>');
$('#loadingIndicator').hide();
}
});
</script>
<?
include('footer.php');
?>