source: binary-improvements/webserver_legacy/js/leaflet.control.gametime.js@ 461

Last change on this file since 461 was 249, checked in by alloc, 9 years ago

Fixes: Web v8

File size: 1.6 KB
Line 
1L.Control.GameTime = L.Control.extend({
2 options: {
3 position: 'bottomright'
4 },
5
6 onAdd: function (map) {
7 var name = 'control-gametime',
8 container = L.DomUtil.create('div', name + ' webmap-control');
9
10 container.innerHTML = "Loading ..."
11 L.DomEvent.on (container, 'mousemove', L.DomEvent.stopPropagation);
12
13 this._map = map;
14 this._div = container;
15
16 window.setTimeout($.proxy(this._updateGameTimeEvent, this), 0);
17
18 return container;
19 },
20
21 onRemove: function (map) {
22 },
23
24 _updateGameTimeEvent: function() {
25 var div = this._div;
26 $.getJSON( "../api/getstats")
27 .done(function(data) {
28 var time = "Day " + data.gametime.days + ", ";
29 if (data.gametime.hours < 10)
30 time += "0";
31 time += data.gametime.hours;
32 time += ":";
33 if (data.gametime.minutes < 10)
34 time += "0";
35 time += data.gametime.minutes;
36 div.innerHTML = time;
37 })
38 .fail(function(jqxhr, textStatus, error) {
39 console.log("Error fetching game stats");
40 })
41 .always(function() {
42 });
43 window.setTimeout($.proxy(this._updateGameTimeEvent, this), 2000);
44 }
45
46});
47
Note: See TracBrowser for help on using the repository browser.