-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
218 lines (183 loc) · 6.77 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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/themes/blitzer/jquery-ui.css" type="text/css" />
<link rel="stylesheet" href="style.css" type="text/css"></link>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js"></script>
<title>Skärgårdsbåtarna Live</title>
<script type="text/javascript" src="scripts/markerwithlabel.js"></script>
<script type="text/javascript" src="scripts/jetties.js"></script>
<script type="text/javascript" src="scripts/boats.js"></script>
<script type="text/javascript">
var boatmarkers = [];
var searchmap = {};
var map = null;
function initialize() {
initmap();
initdialog();
}
function initdialog() {
/* create dialog */
var dialogWidth = Math.min(450, $(window).width()); /* don't overflow mobile */
$('#welcome').dialog({
width: dialogWidth
,modal: true
,resizable: false
,draggable: false});
$('#closetext').click(closeDialog);
/* setup the auto complete, add boats & jetties */
var boatsnjetties = [];
$.each(boats, function(i, boat) {
boatsnjetties.push(boat.name);
});
$.each(jetties, function(i, jetty) {
boatsnjetties.push(jetty.name);
});
boatsnjetties.sort();
$('#searchinput').autocomplete({
minLength: 1,
source: function(req, cb) {
var term = req.term.toLowerCase();
cb($.grep(boatsnjetties, function (elem, index) {
return elem.toLowerCase().indexOf(term) == 0; // == elem.startsWith(term)
}));
}
});
$('#searchform').submit(function (event) {
/* move the map to the position of the marker,
close the dialog and done!
*/
var sought = $('#searchinput').val();
var soughtmarker = searchmap[sought];
map.panTo(soughtmarker.getPosition());
google.maps.event.trigger(soughtmarker, 'click');
closeDialog();
// stop propagation
event.preventDefault();
return false;
});
}
function closeDialog() {
$('#welcome').dialog('close');
}
function initmap() {
var vaxholm = new google.maps.LatLng(59.416, 18.316);
var myOptions = {
zoom: 13,
center: vaxholm,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
// place the jetties and forget about them, they'll never need to be updated
$.each(jetties, addJetty);
// go boats go
updateBoats();
}
function addJetty(index, jetty)
{
var marker = new google.maps.Marker({
position: new google.maps.LatLng(jetty.lat, jetty.lng),
title: jetty.name,
icon: 'images/jetty.png',
zIndex:1});
var infowindow = new google.maps.InfoWindow({
content: '<h2 class="jettyname">' + jetty.name + '</h2>'
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
searchmap[jetty.name] = marker;
marker.setMap(map);
}
function updateBoats()
{
/* fetch new data */
$.ajax({
url: 'http://localhost/~hjon/skargardsbatarna/backend/data.php',
// url: 'http://xn--skrgrdsbtarna-cfbre.nu/backend/data.php',
dataType: 'json',
success: function (data, text, jqxhr) {
var entries = data.entries;
// clear out the old markers/arrows and put new ones
// TODO remove the arrows
if (entries.length > 0)
{
removeBoats();
}
$.each(entries, function (index, entry) {
addBoat(entry);
});
}
});
}
function addBoat(boat)
{
var mmsi = boat.mmsi;
var name = "";
// TODO this should be done in a better way. maybe mmsi: name in boats.js
$.each(boats, function (i, b)
{
if (b.mmsi == mmsi)
name = b.name;
});
var marker = new MarkerWithLabel({
position: new google.maps.LatLng(boat.lat, boat.lng),
title: name,
icon: 'images/boat.png',
labelContent: name.substring(0, name.indexOf("(båt)")-1), // remove (båt)
labelAnchor: new google.maps.Point(33,0),
labelClass: 'boatlabel',
zIndex:2});
/* let the user know when the position of the boat was updated */
var minutesAgo = Math.ceil((new Date().getTime() - boat.lasttime*1000)/(60*1000));
var description = '<h2 class="boatname">' + name + '</h2><br />' +
'Positionen uppdaterades för <b>' + minutesAgo + ' minut' + (minutesAgo > 1 ? 'er' : '') + ' sen</b>.<br />'
+ 'Båten rör sig i ' + Math.round((0.53995680*boat.speed)) + ' knop.';
var infowindow = new google.maps.InfoWindow({
content: description
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
marker.setMap(map);
searchmap[name] = marker;
// save for removal
boatmarkers.push(marker);
}
function removeBoats()
{
$.each(boatmarkers, function(index, marker) {
marker.setMap(null);
});
}
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12460693-6']);
_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 onload="initialize()">
<div id="welcome" title="SKÄRGÅRDSBÅTARNA.NU">
Här ser du i realtid var Waxholmsbolagets båtar befinner sig!
<br />
<b>Sök efter den båt eller brygga du vill se:</b>
<br />
<form id="searchform" action="#">
<input type="text" id="searchinput" placeholder="Sök efter båt eller brygga" />
<input type="submit" id="searchbutton" value="Visa">
</form>
<a href="#" id="closetext">Stäng rutan</a>
</div>
<div id="map_canvas"></div>
</body>
</html>