Projekt

Obecné

Profil

Stáhnout (2.49 KB) Statistiky
| Větev: | Revize:
1 64bc2934 vastja
var mymap;
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 64bc2934 vastja
  mymap = 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 64bc2934 vastja
  }).addTo(mymap);
18 c236b33a msebela
}
19 3fc08f2d vastja
20 351696d5 Martin Sebela
21 c236b33a msebela
function setMapView(latitude = startX, longitude = startY, zoom = startZoom) {
22 64bc2934 vastja
  mymap.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 64bc2934 vastja
function showHeatmap(route) {
63
64
  var name = $('#type').children("option:selected").text();
65
  var parts = $('#date').val().split('-');
66
  var date = parts[2] + parts[1] + parts[0];
67
  var time = $('#time').children("option:selected").val();
68 351696d5 Martin Sebela
69 c236b33a msebela
  $.ajax({
70
    type: "POST",
71 64bc2934 vastja
    url: route + '/' +  name + '/' + date + '/' + time,
72 c236b33a msebela
    success: function(result) {
73
      drawHeatmap(result);
74
    }
75
  });
76 3fc08f2d vastja
}
77
78 351696d5 Martin Sebela
79 3fc08f2d vastja
function drawHeatmap(points) {
80 03c02899 vastja
81
  // Todo still switched
82 0919408a vastja
  points = points.map(function (p) { return [p['y'], p['x'], p['number']]; });
83 03c02899 vastja
  if (heatmapLayer != null) {
84
    mymap.removeLayer(heatmapLayer);
85
  }
86 64bc2934 vastja
  heatmapLayer = L.heatLayer(points, {opacity: 0.5}).addTo(mymap);
87
  heatmapLayer.options = {opacity: 1};
88 03c02899 vastja
  // var heat_01 = ...
89
  // on background map.addLayer(heat_01) -> map.removeLayer(heat_01);
90 64bc2934 vastja
  // $(.leaflet-heatmap-layer).css('opacity', 'value');
91 03c02899 vastja
}
92 3fc08f2d vastja
93 03c02899 vastja
function checkDataSetsAvailability(route) {
94
95
  var parts = $('#date').val().split('-');
96
  
97
  $.ajax({
98
    type: "POST",
99
    // Todo it might be good idea to change db collections format
100
    url: route + '/' + parts[2] + parts[1] + parts[0],
101
    success: function(result) {
102
      updateAvailableDataSets(result);
103
    }
104
  });
105
}
106
107
function updateAvailableDataSets(available) {
108
  
109 0919408a vastja
  var options = '';
110
111
  Object.entries(available).forEach(([key, value]) => {
112
    options += '<option value="' + value + '">' + key + '</option>\n'; 
113
  });
114 03c02899 vastja
115 64bc2934 vastja
  $('#type').empty().append(options);
116 03c02899 vastja
  
117
}