Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 894e3339

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

Re #8163 - refactoring

Zobrazit rozdíly:

website/public/js/zcu-heatmap.js
77 77
  $('.popup-controls').hide()
78 78
}
79 79

  
80
const areSameCoord = (first, second) => {
80
const areCoordsIdentical = (first, second) => {
81 81
  return first.lat === second.lat && first.lng === second.lng
82 82
}
83 83

  
......
175 175

  
176 176
const genMultipleDatasetsPopUp = (sum, currentPage, countPages, datasetName) => {
177 177
  const popupHeader = `<strong id="dataset-name">${datasetName}</strong>`
178
  const popupData = `<div id="number-info"><span id="current-number">${sum}</span></div>`
178
  const popupData = `<div id="place-intesity"><span id="current-number">${sum}</span></div>`
179 179
  const { previousButton, nextButton, pagesList } = getPaginationButtonsInPopup(currentPage, countPages)
180 180

  
181 181
  return `
......
195 195
    <strong>${datasetName}</strong>
196 196
    <div id="place-name">${placeName}</div>`
197 197
  const popupData = `
198
    <div id="number-info">
198
    <div id="place-intesity">
199 199
      <span id="current-number">${currentCount}</span>
200 200
      <span id="part-info">${(sum && sum !== Number(currentCount)) ? '/' + sum : ''}</span>
201 201
    </div>`
......
215 215
    loadCheckboxDatasetNameData()
216 216

  
217 217
    data.forEach((item, index) => {
218
      Object.keys(item).forEach((datasetName) => {
218
      Object.keys(item).forEach(datasetName => {
219 219
        if (datasetName === $(checkbox).val()) {
220 220
          delete data[index][datasetName]
221 221
        }
......
295 295

  
296 296
const getCountPagesInPopup = () => {
297 297
  const infoKeys = Object.keys(info)
298

  
298 299
  if (infoKeys.length === 1) {
299 300
    // return number of records in one dataset (one dataset in area)
300 301
    return info[infoKeys[0]].items.length
......
303 304
  return infoKeys.length
304 305
}
305 306

  
306
const getElFromObjectInfo = (position) => {
307
const getPopupDataOnPage = (pageInPopup) => {
307 308
  const keys = Object.keys(info)
308
  return info[keys[position]]
309
  return info[keys[pageInPopup]]
309 310
}
310 311

  
311
const hasInfoMultipleDatasets = () => {
312
const areMultipleDatasetsInRadius = () => {
312 313
  return Object.keys(info).length > 1
313 314
}
314 315

  
315
const setNewPopupDatasetName = (datasetName) => {
316
const setPopupDatasetClassName = (datasetName) => {
316 317
  const popup = $('.leaflet-popup')
317 318

  
318 319
  popup.removeClass(function (index, css) {
319
    return (css.match (/(^|\s)popup-\S+/g) || []).join(' ');
320
    return (css.match(/(^|\s)popup-\S+/g) || []).join(' ');
320 321
  })
321
  popup.addClass(`popup-${datasetName}`)
322
  popup.addClass('popup-' + datasetName)
322 323
}
323 324

  
324 325
function showInfo (e) {
......
341 342
    lng: e.latlng.lng,
342 343
    lat: e.latlng.lat
343 344
  }
344
  Object.keys(data[currentTime]).forEach((key) => {
345

  
346
  Object.keys(data[currentTime]).forEach(key => {
345 347
    const namedData = data[currentTime][key]
348

  
346 349
    namedData.items.forEach(element => {
347 350
      if (e.latlng.distanceTo(new L.LatLng(element.x, element.y)) < radius) {
348 351
        lat += element.x
......
369 372
    acc[item.datasetName].number += Number(item.number)
370 373
    return acc
371 374
  }, {})
372
  // There is one dataset
373 375

  
374
  const numDatasets = Object.keys(datasetsInRadius).length
376
  const countDatasets = Object.keys(datasetsInRadius).length
375 377

  
376
  if (!numDatasets) {
378
  if (!countDatasets) {
377 379
    if (mymap._popup) {
378 380
      $('#part-info').text('')
379 381
      $('#current-number').html(0)
......
383 385
    return
384 386
  }
385 387

  
386
  if (numDatasets === 1) {
387
    const infoDict = getElFromObjectInfo(0)
388
    const info_ = infoDict.items
389
    const { place, number } = info_[currentPageInPopup]
388
  if (countDatasets === 1) {
389
    const markersInRadius = getPopupDataOnPage(0)
390
    const popupPagesData = markersInRadius.items
391
    const { place, number } = popupPagesData[currentPageInPopup]
390 392

  
391
    if (!globalPopup._popup || !areSameCoord(globalPopup.coord, eventCoord)) {
392
      globalPopup._popup = prepareLayerPopUp(lat, lng, i, `popup-${infoDict.datasetName}`)
393
    if (!globalPopup._popup || !areCoordsIdentical(globalPopup.coord, eventCoord)) {
394
      globalPopup._popup = prepareLayerPopUp(lat, lng, i, `popup-${markersInRadius.datasetName}`)
393 395
      globalPopup.coord = eventCoord
394 396
    }
395 397
    else {
396
      setNewPopupDatasetName(infoDict.datasetName)
398
      setPopupDatasetClassName(markersInRadius.datasetName)
397 399
    }
398 400

  
399
    setGlobalPopupContent(getPopupContent(datasetDictNameDisplayName[infoDict.datasetName], place, number, total, 1, info_.length))
401
    setGlobalPopupContent(getPopupContent(datasetDictNameDisplayName[markersInRadius.datasetName], place, number, total, 1, popupPagesData.length))
400 402

  
401
    if (info_.length === 1) {
403
    if (popupPagesData.length === 1) {
402 404
      disablePopupControls()
403 405
    }
404 406
  } else {
405
    const { datasetName, number } = getElFromObjectInfo(currentPageInPopup)
407
    const { datasetName, number } = getPopupDataOnPage(currentPageInPopup)
406 408

  
407
    if (!globalPopup._popup || !areSameCoord(globalPopup.coord, eventCoord)) {
409
    if (!globalPopup._popup || !areCoordsIdentical(globalPopup.coord, eventCoord)) {
408 410
      globalPopup._popup = prepareLayerPopUp(lat, lng, i, `popup-${datasetName}`)
409 411
      globalPopup.coord = eventCoord
410 412
    }
411 413
    else {
412
      setNewPopupDatasetName(datasetName)
414
      setPopupDatasetClassName(datasetName)
413 415
    }
414 416

  
415 417
    setGlobalPopupContent(genMultipleDatasetsPopUp(number, 1, getCountPagesInPopup(), datasetDictNameDisplayName[datasetName]))
......
435 437
}
436 438

  
437 439
function setPageContentInPopup (page) {
438
  const previousPageData = hasInfoMultipleDatasets() ? getElFromObjectInfo(page) : getElFromObjectInfo(0).items[page]
439
  const currentPageData = hasInfoMultipleDatasets() ? getElFromObjectInfo(currentPageInPopup) : getElFromObjectInfo(0).items[currentPageInPopup]
440
  const previousPageData = areMultipleDatasetsInRadius() ? getPopupDataOnPage(page) : getPopupDataOnPage(0).items[page]
441
  const currentPageData = areMultipleDatasetsInRadius() ? getPopupDataOnPage(currentPageInPopup) : getPopupDataOnPage(0).items[currentPageInPopup]
440 442
  const datasetName = $('#dataset-name')
441 443

  
442 444
  if (datasetName) {

Také k dispozici: Unified diff