/
map.scala.html
104 lines (79 loc) · 2.83 KB
/
map.scala.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
@sidebar = {
<h3>Layers</h3>
<form class="form-vertical" id="layersForm">
</form>
<div id="newVehicle" class="alert alert-block alert-info fade in hide">
<a class="close" data-dismiss="alert" href="#">×</a>
<h4 class="alert-heading">A new vehicle has joined the race!</h4>
<p id="vehicleName"></p>
</div>
}
@css = {
<style TYPE="text/css">
/* A small hack to hide an unwanted dialog box */
div.olLayerGoogleCopyright {
display: none !important;
}
</style>
}
@javascript = {
<script src="@routes.Assets.at("openlayers/OpenLayers.js")" type="text/javascript"></script>
<script src="@routes.Assets.at("javascripts/maptracker.js")" type="text/javascript"></script>
<script src="@routes.Assets.at("javascripts/twitterbootstrap/bootstrap-alert.js")" type="text/javascript"></script>
<script src="http://maps.google.com/maps/api/js?v=3.6&sensor=false"></script>
<script type="text/javascript">
$(document).ready(function() {
// hidable alert thanks to Twitter Bootstrap
$(".alert").alert();
// map initialization
var map = initMap();
var markers = new Array();
// open a WebSocket
var WS = window['MozWebSocket'] ? MozWebSocket : WebSocket
var mapSocket = new WS("@routes.Application.mapsocket().webSocketURL(request)");
mapSocket.onmessage = function(event) {
var move = JSON.parse(event.data);
var marker = null;
// search the marker
$.each(markers,
function(intIndex, objValue){
if (move.id == objValue.id) {
marker = objValue;
}
});
if (marker == null) {
// create the marker
marker = createMarker(map, move.id, move.longitude, move.latitude);
// and add it to the list of marker
markers.push(marker);
// tell the user that we have a new vehicle
$("#newVehicle").removeClass("hide");
$("#vehicleName").text("And its name is \"" + move.id + "\" !");
window.setTimeout(function() {
$("#newVehicle").fadeTo(500, 0).slideUp(500, function(){
$(this).addClass("hide");
});
}, 5000);
} else {
marker = moveMarker(map, marker, move.id, move.longitude, move.latitude);
}
}
// if errors on websocket
var onalert = function(event) {
$(".alert").removeClass("hide");
}
mapSocket.onerror = onalert;
mapSocket.onclose = onalert;
});
</script>
}
@main("Welcome to the MapTracker !")(sidebar)(javascript)(css) {
<h2>Map</h2>
<div class="alert alert-block alert-error fade in hide">
<a class="close" data-dismiss="alert" href="#">×</a>
<h4 class="alert-heading">Oh snap! You got an error!</h4>
<p>The server seems to be down :(</p>
</div>
<div id="map" style="width: 600px; height: 450px">
</div>
}