# All files / components/geo/processing mixins.ts

24.24% Statements 8/33
0% Branches 0/16
0% Functions 0/4
25.81% Lines 8/31

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    541x
    1x
    1x

    1x

    1x

    1x

    1x

    1x

     import {S2} from 's2-geometry'
    import {HEX_DIGIT_NUM} from '../../../utils/geo'
    import {CoordinateEncoding} from './GeoTable'
    import {Coordinates} from './GeoTable'
    import {START_COLUMN, STOP_COLUMN, TIME_COLUMN} from './tableProcessing'

    export const getLatLonMixin = function(index: number): Coordinates {
      if (this.coordinateEncoding === CoordinateEncoding.FIELDS) {
        return {
          lon: this.getValue(index, this.latLonColumns.lon.column),
          lat: this.getValue(index, this.latLonColumns.lat.column),
        }
      }
      const cellId = this.getS2CellID(index)
      if (cellId === null || cellId.length > HEX_DIGIT_NUM) {
        return null
      }
      const precisionTrimmingTable = [BigInt(1)]
      precisionTrimming(precisionTrimmingTable)
      const fixed =
        BigInt('0x' + cellId) *
        precisionTrimmingTable[HEX_DIGIT_NUM - cellId.length]
      const latLng = S2.idToLatLng(fixed.toString())
      return {
        lon: latLng.lng,
        lat: latLng.lat,
      }
    }

    export const getTimeStringMixin = function(index: number): string {
      const timeValue = this.getValue(index, TIME_COLUMN)
      if (timeValue) {
        return timestampToString(timeValue)
      }
      const startValue = this.getValue(index, START_COLUMN)
      const stopValue = this.getValue(index, STOP_COLUMN)
      if (startValue && stopValue) {
        return `${timestampToString(startValue)} - ${timestampToString(stopValue)}`
      }
      const value = startValue || stopValue
      if (value) {
        return timestampToString(value)
      }
    }

    const timestampToString = timeValue => new Date(timeValue).toLocaleString()

    const precisionTrimming = precisionTrimmingTable => {
      for (let i = 1; i < 17; i++) {
        precisionTrimmingTable[i] = precisionTrimmingTable[i - 1] * BigInt(16)
      }
      return precisionTrimmingTable
    }