forked from maxcanna/bicineabbiamo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
239 lines (204 loc) · 12.1 KB
/
index.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
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
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>bicineabbiamo</title>
<meta name="description" content="bicineabbiamo">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- For Chrome for Android: -->
<meta name="theme-color" content="#f07800">
<!-- For Safari for iOS: -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/material-design-iconic-font/2.2.0/css/material-design-iconic-font.min.css">
<link href="http://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<link rel="manifest" href="manifest.json">
<!-- For Chrome for Android: -->
<link rel="icon" sizes="192x192" href="images/touch/launcher-icon-4x.png">
<link rel="icon" sizes="144x144" href="images/touch/launcher-icon-3x.png">
<link rel="icon" sizes="96x96" href="images/touch/launcher-icon-2x.png">
<link rel="icon" sizes="72x72" href="images/touch/launcher-icon-1-5x.png">
<link rel="icon" sizes="48x48" href="images/touch/launcher-icon-1x.png">
<!-- For Safari for iOS: -->
<link rel="apple-touch-icon-precomposed" sizes="192x192" href="images/touch/launcher-icon-4x.png">
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="images/touch/launcher-icon-3x.png">
<link rel="apple-touch-icon-precomposed" sizes="96x96" href="images/touch/launcher-icon-2x.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="images/touch/launcher-icon-1-5x.png">
<link rel="apple-touch-icon-precomposed" sizes="48x48" href="images/touch/launcher-icon-1x.png">
<style >
body {
margin: 0;
padding: 10px 20px 20px;
font-family: Arial;
font-size: 16px;
}
#map-container {
padding: 6px;
border-width: 1px;
border-style: solid;
border-color: #ccc #ccc #999 #ccc;
-webkit-box-shadow: rgba(64, 64, 64, 0.5) 0 2px 5px;
-moz-box-shadow: rgba(64, 64, 64, 0.5) 0 2px 5px;
box-shadow: rgba(64, 64, 64, 0.1) 0 2px 5px;
width: 600px;
}
#map {
width: 600px;
height: 400px;
}
</style>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key={YOUR-KEY}&sensor=false"></script>
<script type="text/javascript" src="src/markerclusterer.js"></script>
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12846745-20']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' === document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<h3>A simple example of MarkerClusterer (100 markers)</h3>
<div id="map-container"><div id="map"></div></div>
<span id="refreshButton" class="zmdi-hc-stack zmdi-hc-lg" style="position: fixed; right: 0; top: 0;">
<i id="refreshIcon" class="zmdi zmdi-refresh zmdi-hc-stack-1x" style="font-size: 40%"></i>
<i class="zmdi zmdi-circle-o zmdi-hc-stack-1x" style="font-size: 65%"></i>
</span>
<img src="images/touch/launcher-icon-4x.png" width="96" height="96">
<div id="content"></div>
<script>
var content = $('#content');
var refreshIcon = $('#refreshIcon');
var loadData = function () {
content.html('Cerco di capire dove sei...');
refreshIcon.addClass('zmdi-hc-spin');
if ('geolocation' in navigator) {
navigator.geolocation.getCurrentPosition(
function (position) {
content.html('Conto le bici una ad una...');
$.ajax({
url: 'https://tonicdev.io/maxcanna/bicineabbiamo/2.2.0?lat='
+ position.coords.latitude +
'&lon='
+ position.coords.longitude +
'&onlyAvailable=true&onlyFirstResult=false',
})
.done(function (data) {
console.log(data);
for (var i = 0; i < data.length; i++) {
//content.append('<div>' + JSON.stringify(data[i])+'</div>');
content.append('<div>'
+ i + " -"
+ JSON.stringify(data[i].name)+","
+ JSON.stringify(data[i].bikes[0].name)+ ":"
+ JSON.stringify(data[i].bikes[0].count) + ","
+ JSON.stringify(data[i].bikes[1].name)+":"
+ JSON.stringify(data[i].bikes[1].count) + ","
+ "Liberi:"
+ JSON.stringify(data[i].emptyslotcount)
+ "su:"
+ JSON.stringify(data[i].slotsnumber)
+'</div>');
}
function initialize(data) {
var center = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 14,
center: center,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var markers = [];
/*for (var i = 0; i < 100; i++) {
var dataPhoto = data.photos[i];
var latLng = new google.maps.LatLng(dataPhoto.latitude,
dataPhoto.longitude);
var marker = new google.maps.Marker({
position: latLng
});
markers.push(marker);
}*/
for (var i = 0; i < data.length; i++) {
//content.append('<div>' + JSON.stringify(data[i])+'</div>');
var bikecount= data[i].bikes[0].count + data[i].bikes[1].count;
var out = bikecount / data[i].slotsnumber;
console.log(bikecount + "/"+ data[i].slotsnumber +"="+out);
var curricon = "";
switch (true) {
case (0 <= out && out < 0.25):
curricon = 'images/ICONS_m_02.png';
curricon = 'images/icons2_01.png';
curricon = 'images/icons2_09.png';
curricon = 'images/icons2_15.png';
curricon = 'images/icons2_21.png';
break;
case (0.25 <= out && out < 0.50):
curricon = 'images/ICONS_m_03.png';
curricon = 'images/icons2_10.png';
curricon = 'images/icons2_16.png';
curricon = 'images/icons2_22.png';
break;
case (0.50 <= out && out < 0.75):
curricon = 'images/ICONS_m_04.png';
curricon = 'images/icons2_11.png';
curricon = 'images/icons2_17.png';
curricon = 'images/icons2_23.png';
break;
case (0.75 <= out && out <= 1):
curricon = 'images/ICONS_m_05.png';
curricon = 'images/icons2_12.png';
curricon = 'images/icons2_18.png';
curricon = 'images/icons2_24.png';
break;
}
console.log(curricon);
var latLng = new google.maps.LatLng(data[i].latitude,
data[i].longitude);
var marker = new google.maps.Marker({
position: latLng,
icon: curricon
});
markers.push(marker);
}
latLng = new google.maps.LatLng(position.coords.latitude,
position.coords.longitude);
marker = new google.maps.Marker({
position: latLng
});
markers.push(marker);
var markerCluster = new MarkerClusterer(map, markers, {gridSize: 50,imagePath: 'images/m'});
}
google.maps.event.addDomListener(window, 'load', initialize(data));
refreshIcon.removeClass('zmdi-hc-spin');
})
.fail(function () {
content.html('Niente, non riesco a contarle bene');
refreshIcon.removeClass('zmdi-hc-spin');
});
},
function (error) {
console.error('Error:', error);
content.html('Eh ma se non mi dici dove sei!');
refreshIcon.removeClass('zmdi-hc-spin');
},
{
enableHighAccuracy: true
});
} else {
content.html('Ma se tu non collabori!');
refreshIcon.removeClass('zmdi-hc-spin');
}
};
$(loadData());
$('#refreshButton').click(function() {
if(!refreshIcon.hasClass('zmdi-hc-spin')){
loadData();
}
});
</script>
</body>
</html>