Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 3ae59f75

Přidáno uživatelem Jakub Vašta před asi 4 roky(ů)

+ popups
+ heatmap maximální intenzita

Zobrazit rozdíly:

website/public/js/zcu-heatmap.js
23 23
    attribution: '',
24 24
    maxZoom: 19
25 25
  }).addTo(mymap);
26

  
27
  mymap.on('click', showInfo);
28

  
26 29
}
27 30

  
31
var info = [];
32
var currenInfo = 0;
33
var infoLength = 0;
34

  
35
function showInfo(e) {
36

  
37
  info = []
38
  currenInfo = 0;
39

  
40
  // https://wiki.openstreetmap.org/wiki/Zoom_levels
41
  // Todo change to variable - it is used in heatmap init
42
  var stile =  40075016.686 * Math.cos(startX) / Math.pow(2, mymap.getZoom()) ;
43
  var radius = 25 * stile / 256;
44

  
45
  var i = 0;
46
  var lat = 0;
47
  var lng = 0;
48

  
49
  data[currentTime]['items'].forEach(element => {
50
    if (e.latlng.distanceTo(new L.LatLng(element.x, element.y)) < radius) {
51
      lat += element.x
52
      lng += element.y;
53
      info[i] = {'place' : element.place, 'number' : element.number};
54
      i++;
55
    }
56
  });
57

  
58
  
59
  if (info.length > 0) {
60
    var popup = L.popup()
61
                  .setLatLng([lat / i, lng / i])
62
                  .setContent('<div id=\'place-info\'>Umístění: ' + info[currenInfo].place + '</div>' +
63
                              '<div id=\'number-info\'>Počet: ' + info[currenInfo].number + '</div>' +
64
                              '<div class=\'popup-controls\'>' +
65
                                '<button id=\'previous-info-btn\' onclick=\'previousInfo()\'>&lt</button>' +
66
                                '<div id=\'count-info\'>' + (currenInfo + 1) + '/' + info.length + '</div>' +
67
                                '<button id=\'next-info-btn\' onclick=\'nextInfo()\'>&gt</button>' +
68
                              '</div>'
69
                              )
70
                  .openOn(mymap);
71
    
72
    if (info.length == 1) {
73
      $('#previous-info-btn').prop('disabled', true);
74
      $('#next-info-btn').prop('disabled', true);
75
      $('.popup-controls').hide();
76
    }
77
  }
78

  
79
}
80

  
81
function previousInfo() {
82
  currenInfo = (currenInfo + info.length - 1) % info.length;
83
  displayInfoText();
84
}
85

  
86
function nextInfo() {
87
  currenInfo = (currenInfo + 1) % info.length
88
  displayInfoText();
89
}
90

  
91
function displayInfoText() {
92
  $('#place-info').html('Umístění: ' + info[currenInfo].place)
93
  $('#number-info').html('Počet: ' + info[currenInfo].number)
94
  $('#count-info').html(currenInfo + 1 + '/' + info.length);
95
}
28 96

  
29 97
function setMapView(latitude = startX, longitude = startY, zoom = startZoom) {
30 98
  mymap.setView([latitude, longitude], zoom);
......
37 105
    $('#play-pause').attr('class', 'pause');
38 106
    timer = setInterval(
39 107
      function() {
108
        mymap.closePopup();
40 109
        next();
41 110
      },
42 111
      800
......
109 178
}
110 179

  
111 180

  
112
function drawHeatmap(points) {
181
function drawHeatmap(data) {
113 182

  
114 183
  // Todo still switched
115
  if (points != null) {
116
    points = points.map(function (p) { return [p['x'], p['y'], p['number']]; });
184
  if (data['items'] != null) {
185
    points = data['items'].map(function (p) { return [p['x'], p['y'], p['number']]; });
117 186
    if (heatmapLayer != null) {
118 187
      mymap.removeLayer(heatmapLayer);
119 188
    }
120
    heatmapLayer = L.heatLayer(points).addTo(mymap);
189
    heatmapLayer = L.heatLayer(points, {'max' : data['max'], 'minOpacity' : 0.5}).addTo(mymap);
121 190
  }
122 191
  else {
123 192
    if (heatmapLayer != null) {

Také k dispozici: Unified diff