-
Notifications
You must be signed in to change notification settings - Fork 10
/
route.php
1060 lines (911 loc) · 35.3 KB
/
route.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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?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/>.
*/
include('header.php');
?>
<script type="text/javascript" src="./assets/OpenLayers/OpenLayers.light.js"></script>
<script src="./assets/js/geojsontools.js"></script>
<script src="./assets/js/canvasjs.js" type="text/javascript"></script>
<link href="./assets/css/jquery.share.css" rel="stylesheet">
<div class="container leftband" id="route-information-container">
<div class="row-fluid" >
<div class="span10">
<div id="routeInformation" style="margin-left: 30px;">
</div>
<ul class="inline-stats" id="statistics">
<li><p id="dist"></p><p id="time"></p><span class="muted"><?php echo $route_distance; ?></span></li>
<li><p id="avg-consum"></p><p id="total-consum"></p><span class="muted"><?php echo $route_fuelConsumption; ?></span></li>
<li><p id="avg-co2"></p><p id="total-co2"></p><span class="muted"><?php echo $route_CO2; ?></span></li>
<li><p><br></p><p id="idle-time"></p><span class="muted"><?php echo $route_idleTime; ?></span></li>
<li><p><br></p><p id="avg-speed"></p><span class="muted"><?php echo $route_avgSpeed; ?></span></li>
</ul>
</div>
<div rel="tooltip" data-placement="top" data-toggle="tooltip" data-original-title="<?php echo $route_sharing_info; ?>" class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="share-switch" onclick="toggleSharing()">
<label class="onoffswitch-label" for="share-switch">
<div class="onoffswitch-inner">
<div class="onoffswitch-active"><div class="onoffswitch-switch"><?php echo $route_sharing_on; ?></div></div>
<div class="onoffswitch-inactive"><div class="onoffswitch-switch"><?php echo $route_sharing_off; ?></div></div>
</div>
</label>
</div>
<div id="share-buttons" class="share-buttons">
<a class='pop share-square share-square-googleplus-disabled'></a><a class='pop share-square share-square-facebook-disabled'></a><a class='pop share-square share-square-twitter-disabled'></a>
</div>
</div>
</div>
<div id="loadingIndicator_route" style="background:url(./assets/img/ajax-loader.gif) no-repeat center center; height:100px;"></div>
<div class="row-fluid" id="full-map-span">
</div>
<div class="container leftband" id="map-and-chart-container">
<div class="row-fluid" id="mapAndChart">
<div class="span6" id="small-map-span">
<div class="simple-map" id="map">
<p id="enviroCar-license">Tracks ODbL by <a href="https://envirocar.org/terms.php">enviroCar</a></p>
<div class="btn-group sensorswitch">
<a class="btn btn-primary btn-full-screen" id="btn-full-screen"><?php echo $route_fullscreen ?></a>
<div class="btn btn-group dropup">
<a class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#" id="sensorswitch">
Download
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li id="download-geojson">
</li>
<li id="download-shapefile">
</li>
<li id="download-csv">
</li>
</ul>
</div>
<div class="btn btn-group dropup">
<a class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#" id="sensorswitch">
Sensor
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>
<a id="change-sensor-consumption" ><?php echo $route_dropup_fuelConsumption; ?></a>
</li>
<li>
<a id="change-sensor-rpm"><?php echo $route_dropup_rpm; ?></a>
</li>
<li>
<a id="change-sensor-speed"><?php echo $route_dropup_speed; ?></a>
</li>
<li>
<a id="change-sensor-intake-temp"><?php echo $route_dropup_intake_temp; ?></a>
</li>
<li>
<a id="change-sensor-intake-pressure"><?php echo $route_dropup_intake_pressure; ?></a>
</li>
<li>
<a id="change-sensor-co2"><?php echo $route_dropup_co2; ?></a>
</li>
<li>
<a id="change-sensor-maf"><?php echo $route_dropup_maf; ?></a>
</li>
</ul>
</div>
</div>
<div class="well" id="legend" style="display:inline">
<p><strong><?php echo $route_legend ?></strong></p>
<p id="legend-title"><?php echo $route_legend_title.$route_dropup_speed ?></p>
<table>
<tr>
<td><img src="./assets/img/legend_green.png" class="legend"></img></td>
<td id="legend1"></td>
</tr>
<tr>
<td><img src="./assets/img/legend_dark_green.png" class="legend"></img></td>
<td id="legend2"></td>
</tr>
<tr>
<td><img src="./assets/img/legend_orange.png" class="legend"></img></td>
<td id="legend3"></td>
</tr>
<tr>
<td><img src="./assets/img/legend_light_red.png" class="legend"></img></td>
<td id="legend4"></td>
</tr>
<tr>
<td><img src="./assets/img/legend_red.png" class="legend"></img></td>
<td id="legend5"></td>
</td>
</table>
</div>
</div>
</div>
<div class="span6 graph-span">
<div id="chartContainer" style="position: relative, height: 100%; width: 100%;"></div>
<div class="dropdown" id="graph-dropdown">
<a class="dropdown-toggle btn btn-primary" data-toggle="dropdown" href="#">
Select Data
<b class="caret"></b>
</a>
<div class="dropdown-menu graph-selection pull-right">
<div class="span6">
<p><strong>Primary Axis</strong></p>
<label class="radio">
<input type="radio" name="primary" checked onclick="addSeries($.extend({},chartSeries[0]), 'primary')">
<?php echo $route_dropup_speed; ?>
</label>
<label class="radio">
<input type="radio" name="primary" onclick="addSeries($.extend({},chartSeries[1]), 'primary')">
<?php echo $route_dropup_fuelConsumption; ?>
</label>
<label class="radio">
<input type="radio" name="primary" onclick="addSeries($.extend({},chartSeries[2]), 'primary')">
<?php echo $route_dropup_intake_temp; ?>
</label>
<label class="radio">
<input type="radio" name="primary" onclick="addSeries($.extend({},chartSeries[3]), 'primary')">
<?php echo $route_dropup_intake_pressure; ?>
</label>
<label class="radio">
<input type="radio" name="primary" onclick="addSeries($.extend({},chartSeries[4]), 'primary')">
<?php echo $route_dropup_co2; ?>
</label>
<label class="radio">
<input type="radio" name="primary" onclick="addSeries($.extend({},chartSeries[5]), 'primary')">
<?php echo $route_dropup_maf ?>
</label>
</div>
<div class="span6">
<p><strong>Secondary Axis</strong></p>
<label class="radio">
<input type="radio" name="secondary" onclick="addSeries($.extend({},chartSeries[0]), 'secondary')">
<?php echo $route_dropup_speed; ?>
</label>
<label class="radio">
<input type="radio" name="secondary" checked onclick="addSeries($.extend({},chartSeries[1]), 'secondary')">
<?php echo $route_dropup_fuelConsumption; ?>
</label>
<label class="radio">
<input type="radio" name="secondary" onclick="addSeries($.extend({},chartSeries[2]), 'secondary')">
<?php echo $route_dropup_intake_temp; ?>
</label>
<label class="radio">
<input type="radio" name="secondary" onclick="addSeries($.extend({},chartSeries[3]), 'secondary')">
<?php echo $route_dropup_intake_pressure; ?>
</label>
<label class="radio">
<input type="radio" name="secondary" onclick="addSeries($.extend({},chartSeries[4]), 'secondary')">
<?php echo $route_dropup_co2; ?>
</label>
<label class="radio">
<input type="radio" name="secondary" onclick="addSeries($.extend({},chartSeries[5]), 'secondary')">
<?php echo $route_dropup_maf ?>
</label>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var popup;
var lengthOfTrack = 0;
var duration;
var fuelConsumptionPerHour;
var fuelConsumptionPer100KM;
var gramsCO2PerKM;
var track;
var gon = {};
(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 convertToLocalTime(serverDate) {
var dt = new Date(Date.parse(serverDate));
var localDate = dt;
var gmt = localDate;
var min = gmt.getTime() / 1000 / 60; // convert gmt date to minutes
var localNow = new Date().getTimezoneOffset(); // get the timezone
// offset in minutes
var localTime = min - localNow; // get the local time
var dateStr = new Date(localTime * 1000 * 60);
var d = dateStr.getDate();
var m = dateStr.getMonth() + 1;
var y = dateStr.getFullYear();
var totalSec = dateStr.getTime() / 1000;
var hours = parseInt( totalSec / 3600 ) % 24;
var minutes = parseInt( totalSec / 60 ) % 60;
return '' + y + '-' + (m<=9 ? '0' + m : m) + '-' + (d <= 9 ? '0' + d : d) + ' ' + hours +':'+ (minutes <= 9 ? '0' + minutes : minutes);
}
function addRouteInformation(name){
$('#routeInformation').append('<h2>'+name+'</h2>');
$('#download-geojson').append('<a href="https://envirocar.org/api/stable/tracks/'+$_GET(['id'])+'" download="enviroCar_track_'+$_GET(['id'])+'.geojson" target="_blank">GeoJSON (*.json)</a>');
$('#download-shapefile').append('<a href="https://envirocar.org/api/stable/tracks/'+$_GET(['id'])+'.shp" download="enviroCar_track_'+$_GET(['id'])+'.shp" target="_blank">Zipped shapefile (*.shp)</a>');
$('#download-csv').append('<a href="https://envirocar.org/api/stable/tracks/'+$_GET(['id'])+'.csv" download="enviroCar_track_'+$_GET(['id'])+'.csv" target="_blank">Comma-separated values (*.csv)</a>');
}
function checkPhenomenonValue(phenomenomName, feature){
var phenomenom = feature.properties.phenomenons[phenomenomName];
if(phenomenom){
return phenomenom.value;
}else{
return 0;
}
}
function fillStatistics(){
$.get('assets/includes/users.php?trackStatistics='+$_GET(['id']), function(data) {
if(data >= 400){
console.log(data);
if(data == 400){
error_msg("<? echo $statisticsError ?>");
}else if(data == 401 || data == 403){
error_msg("<? echo $statisticsNotAllowed ?>")
}else if(data == 404){
error_msg("<? echo $statisticsNotFound ?>")
}
$('#loadingIndicator_route').hide();
}else{
data = JSON.parse(data);
var maxSpeed = 0;
var maxConsumption = 0;
var maxRPM = 0;
var maxIat = 0;
var maxMap = 0;
var maxCo2 = 0;
var maxMaf = 0;
for(i = 0; i < data.statistics.length; i++){
var phenoName = data.statistics[i].phenomenon.name;
if(phenoName == 'Speed'){
maxSpeed = data.statistics[i].max;
$('#avg-speed').append(' <p><img src="./assets/img/icon_durchschnitt.gif">' + Math.round(data.statistics[i].avg) + ' km/h</p>');
}else if(phenoName == 'Consumption'){
maxConsumption = data.statistics[i].max;
}else if(phenoName == 'Rpm'){
maxRPM = data.statistics[i].max;
}else if(phenoName == 'Intake Temperature'){
maxIat = data.statistics[i].max;
}else if(phenoName == 'Intake Pressure'){
maxMap = data.statistics[i].max;
}else if(phenoName == 'CO2'){
maxCo2 = data.statistics[i].max;
}else if(phenoName == 'Calculated MAF' || phenoName == 'MAF'){
maxMaf = data.statistics[i].max;
}
}
gon.statistics = {max_speed : maxSpeed,
max_rpm : maxRPM,
max_consumption : maxConsumption,
max_iat : maxIat,
max_map : maxMap,
max_co2 : maxCo2,
max_maf : maxMaf
};
}
initShowTrack();
$('#loadingIndicator_route').hide();
});
}
function getDistance(lat1, lng1, lat2, lng2){
var earthRadius = 6369;
var dLat = (lat2 - lat1) / 180 * Math.PI;
var dLng = (lng2 - lng1) / 180 * Math.PI;
var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(lat1 / 180 * Math.PI) * Math.cos(lat2 / 180 * Math.PI) * Math.sin(dLng / 2) * Math.sin(dLng / 2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
var dist = earthRadius * c;
return dist;
}
function getTotalCO2(){
var sum = 0;
for(var i = 0; i < gon.measurements.length-1; i++) {
var m = gon.measurements[i];
var m2 = gon.measurements[i + 1];
var seconds = new Date(m2.recorded_at).getTime() - new Date(m.recorded_at).getTime();
seconds = seconds / 1000;
if(seconds <= 10){
var co2 = (((m.maf / 14.7) / 730 )) * 2.35;
sum += seconds * co2;
}
}
return sum;
}
function getFuelPrice(totalFuelConsumption, fuelType){
$.get('assets/includes/fuelprices.php?fuelType='+fuelType, function(data) {
$('#total-consum').append('<p><i class="icon-fire"> </i>' + Math.round(totalFuelConsumption*100)/100 + ' l, circa ' + Math.round(totalFuelConsumption * data*100)/100 + ' €</p>');
});
}
function getTotalFuelConsumption(){
var sum = 0;
for(var i = 0; i < gon.measurements.length-1; i++) {
var m = gon.measurements[i];
var m2 = gon.measurements[i + 1];
var seconds = new Date(m2.recorded_at).getTime() - new Date(m.recorded_at).getTime();
seconds = seconds / 1000;
if(seconds <= 10){
var consumption = m.maf / 10731;
sum += seconds * consumption;
}
}
return sum;
}
function convertMilisecondsToTime(miliseconds) {
var totalSec = miliseconds / 1000;
var hours = parseInt( totalSec / 3600 ) % 24;
var minutes = parseInt( totalSec / 60 ) % 60;
totalSec = totalSec % 60;
return (hours > 0 ? hours + ' h' : '') + ' ' + (minutes > 0 ? minutes + " m" : "") + ' ' + (totalSec > 0 ? totalSec + " s" : "");
}
var map = new OpenLayers.Map("map");//, {controls:[]});
var marker;
//style for selected measurement
highlightStyle = {
pointRadius: 10,
'fillColor': '#0066FF',
'strokeColor': '#0000CC',
'strokeOpacity': 1.0,
'strokeWidth': 2
};
//route line style
var style = {
strokeColor: '#0000ff',
strokeOpacity: 0.8,
strokeWidth: 5
};
var style2 = {
strokeColor: '#00ff00',
strokeOpacity: 0.8,
strokeWidth: 5
};
var gonPoints = [];
var epsg4326;
var projectTo;
var feature;
var vectorLayer;
var heatmap;
function initShowTrack(){
initMap();
initChart();
}
var chart;
var data;
function initChart(){
//defining data and setting up the hash for lookup
var seriesData = [[],[],[],[],[],[]];
epsg4326 = new OpenLayers.Projection("EPSG:4326"); //WGS 1984 projection
projectTo = map.getProjectionObject();
for(var i = 0; i < gon.measurements.length; i++) {
var coords = gon.measurements[i].latlon.replace("(", "").replace(")","").split(" ")
var date = new Date(gon.measurements[i].recorded_at).getTime();
//speed
seriesData[0][i] = {
x: date,
y: gon.measurements[i].speed,
label: "km/h"
}
//consumption
seriesData[1][i] = {
x: date,
y: gon.measurements[i].consumption,
label: "l/100 km"
}
//iat
seriesData[2][i] = {
x: date,
y: gon.measurements[i].iat,
label: "°C"
}
//map
seriesData[3][i] = {
x: date,
y: gon.measurements[i].map,
label: "kPa"
}
//co2
seriesData[4][i] = {
x: date,
y: gon.measurements[i].co2,
label: "g/sec"
}
//maf
seriesData[5][i] = {
x: date,
y: gon.measurements[i].maf,
label: "g/sec"
}
dataHash[date] = new OpenLayers.Geometry.Point( coords[1], coords[2] ).transform(epsg4326, projectTo);
}
chart = new CanvasJS.Chart("chartContainer", {
zoomEnabled: true,
panEnabled: true,
legend: {
fontFamily: "Droid Sans",
horizontalAlign: "left", // left, center ,right
verticalAlign: "top", // top, center, bottom
},
axisX:{
valueFormatString: "hh:mm",
labelFontFamily: "Droid Sans",
includeZero: false
},
axisY: {
title: '<?php echo $route_dropup_speed." in Km/h"; ?>',
titleFontSize: 15,
labelFontFamily: "Droid Sans"
},
axisY2: {
title: "<?php echo $route_dropup_fuelConsumption.' in l/100 km'; ?>",
titleFontSize: 15
//valueFormatString: " "
},
data: [//array of dataSeries
{ //dataSeries object
/*** Change type "column" to "bar", "area", "line" or "pie"***/
type: "spline",
axisYType: "primary",
name: "<?php echo $route_dropup_speed; ?> in km/h",
showInLegend: true,
xValueType: "dateTime",
dataPoints: seriesData[0]
},
{ //dataSeries object
/*** Change type "column" to "bar", "area", "line" or "pie"***/
axisYType: "secondary",
type: "spline",
name: "<?php echo $route_dropup_fuelConsumption; ?> in l/100 km",
showInLegend: true,
xValueType: "dateTime",
dataPoints: seriesData[1]
},
{ //dataSeries object
/*** Change type "column" to "bar", "area", "line" or "pie"***/
axisYType: "secondary",
type: "spline",
name: "<?php echo $route_dropup_intake_temp; ?> in Celsius",
showInLegend: true,
xValueType: "dateTime",
dataPoints: seriesData[2]
},
{ //dataSeries object
/*** Change type "column" to "bar", "area", "line" or "pie"***/
axisYType: "secondary",
type: "spline",
name: "<?php echo $route_dropup_intake_pressure; ?> in kPa",
showInLegend: true,
xValueType: "dateTime",
dataPoints: seriesData[3]
},
{ //dataSeries object
/*** Change type "column" to "bar", "area", "line" or "pie"***/
axisYType: "secondary",
type: "spline",
name: "CO2 in g/sec",
showInLegend: true,
xValueType: "dateTime",
dataPoints: seriesData[4]
},
{ //dataSeries object
/*** Change type "column" to "bar", "area", "line" or "pie"***/
axisYType: "secondary",
type: "spline",
name: "<?php echo $route_dropup_maf ?> in g/sec",
showInLegend: true,
xValueType: "dateTime",
dataPoints: seriesData[5]
}
]
});
chartSeries = $.extend({},chart.options.data);
chart.options.data.splice(2,4);
chart.render();
}
function addSeries(series, axis){
series.axisYType = axis;
//remove series from specified axis
for(var i=0; i<chart.options.data.length; i++){
if(chart.options.data[i].axisYType == axis){
chart.options.data.splice(i,1);
}
}
//add new series to specified axis
chart.options.data.push(series);
if(series.axisYType == "primary"){
chart.options.axisY.title = series.name;
}else{
chart.options.axisY2.title = series.name;
}
chart.render();
}
/* http://b.www.toolserver.org/tiles/bw-mapnik/$%7Bz%7D/$%7Bx%7D/$%7By%7D.png
*/
function initMap() {
// var osm = new OpenLayers.Layer.OSM('<?php echo $route_baseLayer; ?>', [
// "./assets/proxy/ba-simple-proxy.php?mode=native&sub=a&url=${z}%2F${x}%2F${y}.png",
// "./assets/proxy/ba-simple-proxy.php?mode=native&sub=b&url=${z}%2F${x}%2F${y}.png",
// "./assets/proxy/ba-simple-proxy.php?mode=native&sub=c&url=${z}%2F${x}%2F${y}.png"], {
// crossOriginKeyword: null
// });
var osm = new OpenLayers.Layer.OSM('<?php echo $route_baseLayer; ?>', [
"./assets/proxy/ba-simple-proxy.php?mode=native&sub=tile&url=${z}%2F${x}%2F${y}.png"], {
crossOriginKeyword: null
});
osm.attribution = 'Tiles by <a href="http://stamen.com">Stamen</a> (<a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>). Data by <a href="http://openstreetmap.org">OSM</a> (<a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>).';
map.addLayer(osm);
vectorLayer = new OpenLayers.Layer.Vector('<?php echo $route_drivenRoute; ?>');
map.addLayer(vectorLayer);
//map.addControl(new OpenLayers.Control.PanZoomBar());
//map.addControl(new OpenLayers.Control.LayerSwitcher());
//map.addControl(new OpenLayers.Control.MousePosition());
//map.addControl(new OpenLayers.Control.OverviewMap());
//map.addControl(new OpenLayers.Control.KeyboardDefaults());
//map.addControl(new OpenLayers.Control.DragPan());
epsg4326 = new OpenLayers.Projection("EPSG:4326"); //WGS 1984 projection
projectTo = map.getProjectionObject();
var lonLat = new OpenLayers.LonLat(-0.12, 51.503 ).transform(epsg4326, projectTo);
//Get the coordinates from the gon measurements
for(var i=0; i<gon.measurements.length-1; i++) {
var coords = gon.measurements[i].latlon.replace("(", "").replace(")","").split(" ")
var coords2 = gon.measurements[i+1].latlon.replace("(", "").replace(")","").split(" ")
gonPoints.push(
new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.LineString([
new OpenLayers.Geometry.Point( coords[1], coords[2] ).transform(epsg4326, projectTo),
new OpenLayers.Geometry.Point( coords2[1], coords2[2] ).transform(epsg4326, projectTo)
]),
null, style
)
)
}
vectorLayer.addFeatures(gonPoints);
var bounds = new OpenLayers.Bounds();
if(gonPoints) {
if(gonPoints.constructor != Array) {
gonPoints = [gonPoints];
}
// Iterate over the features and extend the bounds to the bounds of the geometries
for(var i=0; i<gonPoints.length; i++) {
if (!bounds) {
bounds = vectorLayer.features[i].geometry.getBounds();
} else {
bounds.extend(vectorLayer.features[i].geometry.getBounds());
}
}
}
map.zoomToExtent(bounds);
changeSensor("speed");
}
function addHeatmapLayer(){
features = [];
for(var i=0; i<gon.measurements.length; i++) {
var measurement = gon.measurements[i];
var coords = gon.measurements[i].latlon.replace("(", "").replace(")","").split(" ")
var g = new OpenLayers.Geometry.Point( coords[1], coords[2] ).transform(epsg4326, projectTo)
//insert what has to be shown here, e.g. speed/CO2
features.push(
new OpenLayers.Feature.Vector(g, {count: measurement.speed})
)
}
//create our vectorial layer using heatmap renderer
heatmap = new OpenLayers.Layer.Vector("Heatmap Layer", {
opacity: 0.3,
renderers: ['Heatmap'],
rendererOptions: {
weight: 'count',
heatmapConfig: {
radius: 15
}
}
});
//heatmap.addFeatures(features);
//map.addLayers([heatmap]);
}
function selectPoint(point){
//postAnalytics();
if(map.getLayersByName("Marker").length > 0){
map.removeLayer(marker);
}
marker = new OpenLayers.Layer.Vector("Marker", {
'displayInLayerSwitcher': false
});
var markers = [new OpenLayers.Feature.Vector(point, null, highlightStyle)];
marker.addFeatures(markers);
map.addLayers([marker]);
}
var lastPost = new Date().getTime();
function postAnalytics(){
if(lastPost != 0 && (new Date().getTime() - lastPost) > 3000){
console.log("interaction");
$.post("http://giv-dueren.uni-muenster.de/analytics/create", { user_id: gon.user, group: gon.user_group, action_name: gon.params.action, url: "/" + gon.params.controller + "/" + gon.params.action + "/", category: "interaction", description: JSON.stringify(gon.params) } );
lastPost = new Date().getTime();
}
}
function changeSensor(sensor){
var unit = "";
switch (sensor) {
case "iat":
unit = " °C";
break;
case "map":
unit = " kPa";
break;
case "co2":
unit = " g/sec";
break;
case "maf":
unit = " g/sec";
break;
case "speed":
unit = " km/h";
break;
case "rpm":
unit = " rpm";
break;
case "consumption":
unit = " l/100km";
for(i = 0; i < vectorLayer.features.length; i++){
var color;
if(gon.measurements[i][sensor] < 5){
color = "#1BE01B";
}else if(gon.measurements[i][sensor] < 9){
color = "#B5E01B";
}else if(gon.measurements[i][sensor] < 13){
color = "#E0C61B";
}else if(gon.measurements[i][sensor] < 20){
color = "#E08B1B";
}else if(gon.measurements[i][sensor] >= 20){
color = "#E01B1B";
}
var style = {
strokeColor: color,
strokeOpacity: 0.8,
strokeWidth: 5
};
vectorLayer.features[i].style = style;
}
vectorLayer.redraw();
document.getElementById("legend1").innerHTML = "0-5 l/100km"
document.getElementById("legend2").innerHTML = "5-9 l/100km"
document.getElementById("legend3").innerHTML = "9-13 l/100km"
document.getElementById("legend4").innerHTML = "13-20 l/100km"
document.getElementById("legend5").innerHTML = ">20 l/100km"
return;
}
for(i = 0; i < vectorLayer.features.length; i++){
var style = {
strokeColor: getColor(sensor, gon.measurements[i][sensor]),
strokeOpacity: 0.8,
strokeWidth: 5
};
vectorLayer.features[i].style = style;
}
vectorLayer.redraw();
var steps = gon.statistics["max_" + sensor]/5;
document.getElementById("legend1").innerHTML = "0" + "-" + Math.round(steps) + unit
document.getElementById("legend2").innerHTML = Math.round(steps) + "-" + Math.round(2*steps) + unit
document.getElementById("legend3").innerHTML = Math.round(2*steps) + "-" + Math.round(3*steps) + unit
document.getElementById("legend4").innerHTML = Math.round(3*steps) + "-" + Math.round(4*steps) + unit
document.getElementById("legend5").innerHTML = Math.round(4*steps) + "-" + Math.round(5*steps) + unit
}
function getColor(sensor, value){
var steps = gon.statistics["max_" + sensor]/5;
if(value < steps) return "#1BE01B";
else if(value < steps * 2) return "#B5E01B";
else if(value < steps * 3) return "#E0C61B";
else if(value < steps * 4) return "#E08B1B";
else return "#E01B1B";
}
var scroll = 0;
$(document).ready(function () {
$("#btn-full-screen").click(function () {
if ($("#btn-full-screen").hasClass("btn-full-screen")) {
scroll = $(window).scrollTop();
window.scrollTo(0,0);
$("#route-information-container").hide();
$("#map-and-chart-container").hide();
$("footer").hide();
$('html, body').css({
'overflow': 'hidden',
'height': '100%'
});
$("#map").appendTo("#full-map-span");
$("#map").height($(window).height());
$("#map").removeClass("simple-map");
$("#map").addClass("full-map");
$("#btn-full-screen").removeClass("btn-full-screen");
$("#btn-full-screen").addClass("btn-partial-screen");
$("#btn-full-screen").text("Minimize")
}
else {
$("#route-information-container").show();
$("#map-and-chart-container").show();
$("footer").show();
$('html, body').css({
'overflow': 'visible'
});
$("#map").height("");
$("#map").appendTo("#small-map-span");
$("#map").removeClass("full-map");
$("#map").addClass("simple-map");
$("#btn-full-screen").removeClass("btn-partial-screen");
$("#btn-full-screen").addClass("btn-full-screen");
$("#btn-full-screen").text('Fullscreen');
$(window).scrollTop(scroll);
}
map.updateSize();
});
$('a#change-sensor-speed').click(function(){
changeSensor("speed");
$('#legend-title').text("<?php echo $route_legend_title.$route_dropup_speed ?>");
});
$('a#change-sensor-rpm').click(function(){
changeSensor("rpm");
$('#legend-title').text("<?php echo $route_legend_title.$route_dropup_speed ?>");
});
$('a#change-sensor-consumption').click(function(){
changeSensor("consumption");
$('#legend-title').text("<?php echo $route_legend_title.$route_dropup_fuelconsumption ?>");
});
$('a#change-sensor-intake-temp').click(function(){
changeSensor("iat");
$('#legend-title').text("<?php echo $route_legend_title.$route_dropup_intake_temp ?>");
});
$('a#change-sensor-intake-pressure').click(function(){
changeSensor("map");
$('#legend-title').text("<?php echo $route_legend_title.$route_dropup_intake_pressure ?>");
});
$('a#change-sensor-co2').click(function(){
changeSensor("co2");
$('#legend-title').text("<?php echo $route_legend_title.'CO2' ?>");
});
$('a#change-sensor-maf').click(function(){
changeSensor("maf");
$('#legend-title').text("<?php echo $route_legend_title.$route_dropup_maf ?>");
});
//GET the information about the specific track
$.get('assets/includes/users.php?track='+$_GET(['id']), function(data) {
if(data >= 400){
console.log(data);
if(data == 400){
error_msg("<? echo $routeError ?>");
}else if(data == 401 || data == 403){
error_msg("<? echo $routeNotAllowed ?>")
}else if(data == 404){
error_msg("<? echo $routeNotFound ?>")
}
$('#loadingIndicator').hide();
}else{
data = JSON.parse(data);
addRouteInformation(data.properties.name);
var fuelType = data.properties.sensor.properties.fuelType;
var measurements = [];
//speed = 0 counts as idle time
var idleTime = 0;
var distance = 0;
if (data.properties.length) {
lengthOfTrack = data.properties.length;
}
// total fuel consumption in liter per hour
var totalFuelConsumptionLiterPerHour = 0;
//prevent memory issues, only show shapefile download for smaller tracks
//max value must correspond with max measurements value of enviroCar-server
if (data.features.length >= 500) {
$('#download-shapefile').hide();
}
if (data.features.length > 1) {
for (var i = 0; i < data.features.length; i++) {
var feature = data.features[i];
if(i == 0){
startTime = new Date(data.features[i].properties.time);
}else if(i == data.features.length - 2){
endTime = new Date(data.features[i + 1].properties.time);
}
var lat1 = feature.geometry.coordinates[1];
var lng1 = feature.geometry.coordinates[0];
var trackPartDistance = 0;
if (lengthOfTrack == 0 && i < data.features.length-1){
var lat2 = data.features[i+1].geometry.coordinates[1];
var lng2 = data.features[i+1].geometry.coordinates[0];
trackPartDistance = getDistance(lat1, lng1, lat2, lng2);
distance = distance + trackPartDistance;
}
var coords = "POINT (" + feature.geometry.coordinates[0] + " " + feature.geometry.coordinates[1]+ ")";
var rpm = checkPhenomenonValue('Rpm', feature).value;
var iat = checkPhenomenonValue('Intake Temperature', feature);
var map = checkPhenomenonValue('Intake Pressure', feature);
var speed = checkPhenomenonValue('Speed', feature);
if(speed == 0){
//add five thousand miliseconds of idle time for each measurement with speed = 0
idleTime = idleTime + 5000;
}
var maf = feature.properties.phenomenons["MAF"];
if(maf){
maf = checkPhenomenonValue("MAF", feature);
}else if (!maf || maf <= 0) {
maf = checkPhenomenonValue("Calculated MAF", feature);
}
var secondsBtwnMeasurements = 0;
if(i == (data.features.length - 1)){
secondsBtwnMeasurements = 1;
}else{
//multiply with seconds between measurements
secondsBtwnMeasurements = (new Date(data.features[i+1].properties.time).getTime() - new Date(feature.properties.time).getTime()) / 1000;
}
var consumption = 0;
var co2 = 0;
var fuelConsumptionOfMeasurement = checkPhenomenonValue('Consumption', feature);
if (speed > 0){
//consumption = (maf * 3355) / (speed * 100);
consumption = (fuelConsumptionOfMeasurement / speed) * 100;
}else{
//consumption = (maf * 3355) / 10000;
consumption = fuelConsumptionOfMeasurement / 10000;//??
}
if (consumption > 50){
consumption = 50;
}
//this does not work as the distance between measurment points can be 0 sometimes
//if(trackPartDistance != 0){
// consumption = fuelConsumptionOfMeasurement * secondsBtwnMeasurements / 3600 / trackPartDistance * 100;
//}
totalFuelConsumptionLiterPerHour += fuelConsumptionOfMeasurement;
co2 = consumption * 2.35 //gets kg/100 km
var recorded_at = feature.properties.time;
var m = {
recorded_at : recorded_at,
speed : speed,
rpm : rpm,