All files / core/systems/georef system.ts

100% Statements 8/8
100% Branches 0/0
100% Functions 4/4
100% Lines 8/8

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                  14x       2058x     14x 2009x       1001x 1001x                       14x               1x      
import { Option, pipe } from 'effect'
 
import { cellBox } from '../cell'
import { compact, makeParser } from '../parser'
import { singleReading } from '../reading'
import type { Formatter, Grid, Parser } from '../types'
import { fromGeoref, isGeoref, toGeoref } from './georef'
import { georefCellOutline, georefGrid } from './grid'
 
export const formatter: Formatter = {
  id: 'GEOREF',
  label: 'GEOREF',
  maybeGridId: Option.some('Georef'),
  format: point => singleReading(toGeoref(point), '1′ square'),
}
 
export const parser: Parser = makeParser('GEOREF', text =>
  pipe(
    compact(text),
    Option.liftPredicate(isGeoref),
    Option.map(reference => {
      const cell = fromGeoref(reference)
      return {
        kind: 'GEOREF',
        point: {
          lat: (cell.south + cell.north) / 2,
          lon: (cell.west + cell.east) / 2,
        },
        maybeBounds: Option.some(cellBox(cell)),
      }
    }),
  ),
)
 
export const grid: Grid = {
  id: 'Georef',
  label: 'GEOREF',
  description: 'GEOREF 15° quadrangles, and 1° squares from zoom 6',
  colors: { onDark: [64, 196, 160, 140], onLight: [0, 128, 100, 160] },
  isEnabledByDefault: false,
  build: georefGrid,
  maybeCueOutline: Option.some(point =>
    Option.some(georefCellOutline(toGeoref(point))),
  ),
}