-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
143 lines (108 loc) · 3.96 KB
/
app.js
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
$(document).ready(function(){
$('#table-reference').hide();
$('#infos1tr').hide();
$('#infos2tr').hide();
var bairrosAgrupados = 'http://felipefontana.com.br:49160/bairros/agrupados';
$.get(bairrosAgrupados, function(data) {
var option = '';
for (var i = 0; i < data.length; i++) {
option += '<option value="'+ data[i]._id +'" data-count="' + data[i].count + '">' + data[i]._id + '</option>';
}
$('.selectBairros').append(option);
});
var bairrosRank = 'http://felipefontana.com.br:49160/bairros/rank';
$.get(bairrosRank, function(data) {
var top10 = '<table class="table table-striped table-bordered"><tr class="header"><td>Ordem</td><td>Nome</td><td>Ocorrências</td></tr>';
for (var i = 0; i < 10; i++) {
var y = i+1;
top10 += '<tr><td>'+ y +'</td><td>'+ data[i]._id +'</td> <td><span style="color:red">'+ data[i].count +'</span></td></tr>';
}
top10 += '</table>';
$('#top10').html(top10);
});
$('.selectBairros').on('change', function(){
newPlot();
});
});
var map, heatmap;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: {lat: -15.587909, lng: -56.111856},
mapTypeId: google.maps.MapTypeId.MAP
});
getPoints(function (data) {
heatmap = new google.maps.visualization.HeatmapLayer({
data: data,
map: map,
maxIntensity: 8,
});
});
}
function getPoints(cb) {
var arrayPoints= [];
var url = 'http://felipefontana.com.br:49160/bairros';
$.get(url, function(data) {
for (var i = 0; i < data.length; i++) {
arrayPoints.push(new google.maps.LatLng(data[i].POINTS.lat, data[i].POINTS.lng));
}
cb(arrayPoints);
});
}
function clearSelects() {
$('#selectBairros1').val('');
$('#selectBairros2').val('');
newPlot();
}
function newPlot() {
var selectBairros1 = $('#selectBairros1');
var selectBairros1Val = $('#selectBairros1').val();
var selectBairros2 = $('#selectBairros2');
var selectBairros2Val = $('#selectBairros2').val();
if(selectBairros1Val && !selectBairros2Val){
var bairrosDetail = 'http://felipefontana.com.br:49160/bairros/'+ selectBairros1.val();
}
else if(!selectBairros1Val && selectBairros2Val){
var bairrosDetail = 'http://felipefontana.com.br:49160/bairros/'+ selectBairros2.val();
}
else if(selectBairros1Val == '' && selectBairros2Val == ''){
var bairrosDetail = 'http://felipefontana.com.br:49160/bairros';
}
else {
var bairrosDetail = 'http://felipefontana.com.br:49160/bairros/'+ selectBairros1.val() +','+ selectBairros2.val();
}
var arrayPoints= [];
$.get(bairrosDetail, function(data) {
for (var i = 0; i < data.length; i++) {
arrayPoints.push(new google.maps.LatLng(data[i].POINTS.lat, data[i].POINTS.lng));
}
var self1 = selectBairros1.val();
if(self1){
$('#infos1Name').html(self1);
$('#infos1').html(selectBairros1.find(':selected').data('count') || 0);
$('#infos1tr').show();
$('#table-reference').show();
} else {
$('#infos1tr').hide();
}
var self2 = selectBairros2.val();
if(self2){
$('#infos2Name').html(self2);
$('#infos2').html(selectBairros2.find(':selected').data('count') || 0);
$('#infos2tr').show();
$('#table-reference').show();
} else {
$('#infos2tr').hide();
}
if(!self1 && !self2){
$('#table-reference').hide();
}
$('#infostotal').html(data.length);
heatmap.setMap(null);
heatmap = new google.maps.visualization.HeatmapLayer({
data: arrayPoints,
map: map,
maxIntensity: 8,
});
});
}