All files / map cue.ts

100% Statements 16/16
100% Branches 0/0
100% Functions 11/11
100% Lines 15/15

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 54 55 56 57 58 59 60                  5x   5x   12x     5x           28x 18x   10x   90x   23x   15x     12x                       5x     28x 18x 10x                
import { Array, Option } from 'effect'
 
import type { GridToggles } from '../core/domain'
import type { LatLon } from '../core/geo/ellipsoid'
import type { RGBA } from '../core/geo/geometry'
import { grids, isGridEnabled } from '../core/systems/registry'
import type { MapTone, SystemOptions } from '../core/systems/types'
import { LineRank, lineFeature } from './features'
 
export const CUE_COLOR: RGBA = [245, 166, 35, 255]
 
const CUE_CELL_WIDTH = 2.5
 
const opaque = ([red, green, blue]: RGBA): RGBA => [red, green, blue, 255]
 
/** The outline of the cell around the cue in each grid that is switched on. */
export const cueCellFeatures = (
  maybeCue: Option.Option<LatLon>,
  options: SystemOptions,
  gridToggles: GridToggles.GridToggles,
  tone: MapTone,
): ReadonlyArray<GeoJSON.Feature<GeoJSON.LineString>> =>
  Option.match(maybeCue, {
    onNone: () => [],
    onSome: cue =>
      Array.getSomes(
        Array.map(
          Array.filter(grids, grid => isGridEnabled(gridToggles, grid)),
          grid =>
            Option.map(
              Option.flatMap(grid.maybeCueOutline, outline =>
                outline(cue, options),
              ),
              path =>
                lineFeature(path, {
                  layer: 'cue-cells',
                  color: opaque(grid.colors[tone]),
                  width: CUE_CELL_WIDTH,
                  rank: LineRank.CueCells,
                }),
            ),
        ),
      ),
  })
 
/** The cue as a point, for the marker's circle layers. */
export const cueMarkerFeatures = (
  maybeCue: Option.Option<LatLon>,
): ReadonlyArray<GeoJSON.Feature<GeoJSON.Point>> =>
  Option.match(maybeCue, {
    onNone: () => [],
    onSome: ({ lat, lon }) => [
      {
        type: 'Feature',
        geometry: { type: 'Point', coordinates: [lon, lat] },
        properties: {},
      },
    ],
  })