Projekt

Obecné

Profil

« Předchozí | Další » 

Revize ab904bf5

Přidáno uživatelem Martin Sebela před více než 3 roky(ů)

refactoring

Zobrazit rozdíly:

website/public/js/index.js
17 17
let positionsSourceRoute
18 18

  
19 19
let currentTime
20

  
21 20
let currentDate
22 21

  
23 22
var timer
......
40 39
const datasetDictNameDisplayName = {}
41 40
var datasetSelected = []
42 41

  
43
// data only for one day
42
// animate data only in one day
44 43
let lockedDay = false
45 44

  
46 45
// loading information for async operations
......
49 48
// default loader showup delay
50 49
const defaultLoaderDelay = 1000
51 50

  
52
// marks for all datasets
53
const dataSourceMarks = {}
51
// map markers for all datasets
52
const dataMapMarkers = {}
54 53

  
55 54
const globalMarkersHolder = {}
56 55
// all marker from which popup was removed
......
85 84

  
86 85

  
87 86
/* ------------ DATA FETCHERS ------------ */
87

  
88 88
const genericFetch = async (route, method) => {
89 89
  const headers = new Headers()
90
  const myRequest = new Request(route, {
90
  const request = new Request(route, {
91 91
    method: method,
92 92
    headers: headers
93 93
  })
94
  const beforeJson = await fetch(myRequest)
94
  const beforeJson = await fetch(request)
95 95

  
96 96
  return beforeJson.json()
97 97
}
98
const fetchByNameDate = async (baseRoute, name, date, currentTime) => {
99
  return await genericFetch(baseRoute + '/' + name + '/' + date + '/' + currentTime, 'GET')
98

  
99
const fetchDatasetDataByDatetime = async (route, datasetName, date, time) => {
100
  return await genericFetch(route + '/' + datasetName + '/' + date + '/' + time, 'GET')
100 101
}
101 102

  
102
const fetchDataSourceMarks = async (positionRoute, datasetName) => {
103
    return await genericFetch(positionRoute + '/' + datasetName, 'GET')
103
const fetchDatasetMapMarkers = async (route, datasetName) => {
104
  return await genericFetch(route + '/' + datasetName, 'GET')
104 105
}
105 106

  
106
preload = async (time, change, date) => {
107
preload = async (time, timeShift, date) => {
107 108
  loadingY()
108 109

  
109
  for (let nTime = time + change; nTime >= 0 && nTime <= 23; nTime = nTime + change) {
110
  for (let nTime = time + timeShift; nTime >= 0 && nTime <= 23; nTime = nTime + timeShift) {
110 111
    if (!data[nTime]) {
111 112
      data[nTime] = {}
112 113
    }
113 114

  
114 115
    datasetSelected.forEach(async (datasetName) => {
115 116
      if (!data[nTime][datasetName]) {
116
        data[nTime][datasetName] = await fetchByNameDate(dataSourceRoute, datasetName, date, nTime)
117
        data[nTime][datasetName] = await fetchDatasetDataByDatetime(dataSourceRoute, datasetName, date, nTime)
117 118
      }
118 119
    })
119 120
  }
......
125 126
 * Load and display heatmap layer for current data
126 127
 * 
127 128
 * @param {string} opendataRoute route to dataset source
128
 * @param {string} positionsRoute  route to dataset postitions source
129
 * @param {string} positionsRoute  route to dataset positions source
129 130
 */
130 131
const loadCurrentTimeHeatmap = async (opendataRoute, positionsRoute, loaderDelay = defaultLoaderDelay) => {
131 132
  loadCheckboxDatasetNameData()
......
136 137
  data[currentTime] = {}
137 138

  
138 139
  const dataSelectedHandler = async (datasetName) => {
139
    if (!(datasetName in dataSourceMarks)) {
140
      dataSourceMarks[datasetName] = await fetchDataSourceMarks(positionsRoute, datasetName)
140
    if (!(datasetName in dataMapMarkers)) {
141
      dataMapMarkers[datasetName] = await fetchDatasetMapMarkers(positionsRoute, datasetName)
141 142
    }
142 143

  
143
    const datasetData = await fetchByNameDate(dataSourceRoute, datasetName, currentDateToString(), currentTime)
144
    const datasetData = await fetchDatasetDataByDatetime(dataSourceRoute, datasetName, currentDateToString(), currentTime)
144 145
    data[currentTime][datasetName] = datasetData
145 146
  }
147

  
146 148
  datasetSelected.forEach((datasetName) => {
147 149
    allPromises.push(dataSelectedHandler(datasetName))
148 150
  })
......
152 154
  await Promise.all(allPromises).then(
153 155
    () => {
154 156
      loadingN(0)
155
      drawMapMarkers(dataSourceMarks)
157
      drawMapMarkers(dataMapMarkers)
156 158
      drawHeatmap(data[currentTime])
157 159

  
158 160
      preload(currentTime, 1, currentDateToString())
......
190 192
    maxZoom: 19
191 193
  }).addTo(mymap)
192 194

  
193
  mymap.on('click', function (e) { showInfo(e) })
195
  mymap.on('click', function (e) { showPopup(e) })
194 196
}
195 197

  
196 198
const setMapView = (latitude, longitude, zoom) => {
......
308 310

  
309 311

  
310 312

  
311
/* ------------ POPUPs ------------ */
313
/* ------------ POPUPS ------------ */
312 314

  
313 315
const setGlobalPopupContent = (content) => {
314 316
  globalPopup._popup.setContent(content)
......
411 413
  popup.addClass('popup-' + datasetName)
412 414
}
413 415

  
414
const showInfo = (e) => {
416
const showPopup = (e) => {
415 417
  info = []
416 418
  currentPageInPopup = 0
417 419

  
......
527 529
  const { _popup } = mymap
528 530

  
529 531
  if (_popup) {
530
    showInfo({
532
    showPopup({
531 533
      latlng: _popup.getLatLng()
532 534
    })
533 535
  }
......
715 717
}
716 718

  
717 719
const initDatepicker = async (availableDatesSource) => {
718
  var availableDates = ''
719 720
  const result = await genericFetch(availableDatesSource, 'GET')
720
  availableDates = String(result).split(',')
721
  const datesContainData = String(result).split(',')
722

  
721 723
  $('#date').datepicker({
722 724
    format: 'yyyy-mm-dd',
723 725
    language: 'cs',
724 726
    beforeShowDay: function (date) {
725
      if (availableDates.indexOf(formatDate(date)) < 0) {
727
      if (datesContainData.indexOf(formatDate(date)) < 0) {
726 728
        return { enabled: false, tooltip: 'Žádná data' }
727 729
      } else {
728 730
        return { enabled: true }
......
865 867
  $('#player-time > .spinner-border').addClass('d-none')
866 868
  setTimeline()
867 869
}
870

  
868 871
module.exports = {
869 872
  initDatepicker,
870 873
  initLocationsMenu,

Také k dispozici: Unified diff