Projekt

Obecné

Profil

Stáhnout (2.14 KB) Statistiky
| Větev: | Revize:
1 351696d5 Martin Sebela
var map;
2 03c02899 vastja
var heatmapLayer = null;
3
4 c236b33a msebela
var startX = 49.7248;
5
var startY = 13.3521;
6
var startZoom = 17;
7 3fc08f2d vastja
8 351696d5 Martin Sebela
var currentTime = 0;
9
10
11 c236b33a msebela
function initMap() {
12 351696d5 Martin Sebela
  map = L.map('heatmap').setView([startX, startY], startZoom);
13 3fc08f2d vastja
14 c236b33a msebela
  L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
15
    attribution: '',
16
    maxZoom: 19
17 351696d5 Martin Sebela
  }).addTo(map);
18 c236b33a msebela
}
19 3fc08f2d vastja
20 351696d5 Martin Sebela
21 c236b33a msebela
function setMapView(latitude = startX, longitude = startY, zoom = startZoom) {
22 351696d5 Martin Sebela
  map.setView([latitude, longitude], zoom);
23 3fc08f2d vastja
}
24
25 351696d5 Martin Sebela
26
function changeTime(direction, max = 0) {
27
  let time = document.getElementById('time');
28
29
  if (direction === 'next') {
30
    currentTime += 1;
31
32
    if (currentTime > 23) {
33
      currentTime = 0;
34
    }
35
  }
36
  else if (direction === 'prev') {
37
    currentTime -= 1;
38
39
    if (currentTime < 0) {
40
      currentTime = 23;
41
    }
42
  }
43
44
  time.textContent = currentTime + ":00";
45
  time.className = 'time hour-' + currentTime;
46
}
47
48
49
function animateTimeline() {
50
  setTimeout(
51
    function () {
52
      if (currentTime < 23) {
53
        animateTimeline();
54
        changeTime('next');
55
      }
56
      else {
57
        changeTime('next');
58
      }
59
    }, 400);
60
}
61
62 03c02899 vastja
function showHeatmap(route, date) {
63 351696d5 Martin Sebela
64 c236b33a msebela
  $.ajax({
65
    type: "POST",
66 03c02899 vastja
    url: route + date,
67 c236b33a msebela
    success: function(result) {
68
      drawHeatmap(result);
69
    }
70
  });
71 3fc08f2d vastja
}
72
73 351696d5 Martin Sebela
74 3fc08f2d vastja
function drawHeatmap(points) {
75 03c02899 vastja
76
  // Todo still switched
77 896f0d9c vastja
  points = points.map(function (p) { return [p['x'], p['y'], p['number']]; });
78 03c02899 vastja
  if (heatmapLayer != null) {
79
    mymap.removeLayer(heatmapLayer);
80
  }
81
  heatmapLayer = L.heatLayer(points).addTo(mymap), draw = true; 
82
  // var heat_01 = ...
83
  // on background map.addLayer(heat_01) -> map.removeLayer(heat_01);
84
}
85 3fc08f2d vastja
86 03c02899 vastja
function checkDataSetsAvailability(route) {
87
88
  var parts = $('#date').val().split('-');
89
  
90
  $.ajax({
91
    type: "POST",
92
    // Todo it might be good idea to change db collections format
93
    url: route + '/' + parts[2] + parts[1] + parts[0],
94
    success: function(result) {
95
      updateAvailableDataSets(result);
96
    }
97
  });
98
}
99
100
function updateAvailableDataSets(available) {
101
  
102
  var options;
103
  for (i = 0; i < available.length; i++) {
104
    options += '<options value="' + i + '">' + available[i] + '</option>\n'; 
105
  }
106
107
  $('#types').empty().append(options);
108
  
109
}