All files / map properties.ts

100% Statements 5/5
100% Branches 0/0
100% Functions 0/0
100% Lines 5/5

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 61 62 63 64 65 66 67 68 69 70 71 72                                      2x                                 2x     2x     2x                         2x                                
import { Option, Record, Schema } from 'effect'
 
import {
  Camera,
  GridToggles,
  LatLon,
  MapStyle,
  RangeRings,
} from '../core/domain'
import { GarsPrecision } from '../core/systems/gars'
import { MgrsPrecision } from '../core/systems/mgrs'
import { ProfileId } from '../core/systems/profiles'
import { TileZoom } from '../core/systems/tile'
import * as CameraRequest from './cameraRequest'
 
/**
 * The properties of `<coordkit-map>`, declared once. The element's TypeScript type and the
 * Foldkit binding (`CustomElement.define` in view.ts) are both derived from this record.
 */
export const mapPropertyFields = {
  profile: ProfileId,
  basemap: MapStyle.Basemap,
  projection: MapStyle.Projection,
  gridToggles: GridToggles.GridToggles,
  isGridLabelsVisible: Schema.Boolean,
  cue: Schema.Option(LatLon.LatLon),
  mgrsPrecision: MgrsPrecision,
  garsPrecision: GarsPrecision,
  tileZoom: TileZoom,
  isRangeRingsVisible: Schema.Boolean,
  ringSpacing: RangeRings.RingSpacing,
  ringUnit: RangeRings.RingUnit,
  camera: Schema.Option(Camera.Camera),
  cameraRequest: Schema.Option(CameraRequest.CameraRequest),
}
 
export const MapProperties = Schema.Struct(mapPropertyFields)
export type MapProperties = typeof MapProperties.Type
 
export const mapPropertyNames = Record.keys(mapPropertyFields)
 
/** The CustomEvents `<coordkit-map>` dispatches, with the detail each carries. */
export const mapEventFields = {
  'map-ready': Schema.Struct({}),
  'map-failed': Schema.Struct({ reason: Schema.String }),
  'map-moved': Camera.Camera,
  'cursor-moved': LatLon.LatLon,
  'cursor-left': Schema.Struct({}),
  'map-clicked': LatLon.LatLon,
}
 
/**
 * What the element shows before the view first sets its properties. The view sets every
 * property on the first render, so these only matter for a bare element, as in tests.
 */
export const initialMapProperties: MapProperties = {
  profile: 'Land',
  basemap: 'Satellite',
  projection: 'Mercator',
  gridToggles: {},
  isGridLabelsVisible: true,
  cue: Option.none(),
  mgrsPrecision: 0,
  garsPrecision: 30,
  tileZoom: 12,
  isRangeRingsVisible: true,
  ringSpacing: 'Auto',
  ringUnit: 'NauticalMiles',
  camera: Option.none(),
  cameraRequest: Option.none(),
}