All files / tcb-admin-node/src/database/geo point.ts

70% Statements 7/10
100% Branches 0/0
25% Functions 1/4
70% Lines 7/10
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 593x 3x             3x                                       1x 1x   1x 1x                                                    
import { Validate } from "../validate";
import { SYMBOL_GEO_POINT } from '../helper/symbol'
 
/**
 * 地址位置
 *
 * @author haroldhu
 */
export class Point {
  /**
   * 纬度
   * [-90, 90]
   */
  readonly latitude: number;
 
  /**
   * 经度
   * [-180, 180]
   */
  readonly longitude: number;
 
  /**
   * 初始化
   *
   * @param latitude    - 纬度 [-90, 90]
   * @param longitude   - 经度 [-180, 180]
   */
  constructor(longitude: number, latitude: number) {
    Validate.isGeopoint("longitude", longitude);
    Validate.isGeopoint("latitude", latitude);
 
    this.longitude = longitude;
    this.latitude = latitude;
  }
 
  parse(key) {
    return {
      [key]: {
        type: 'Point',
        coordinates: [this.longitude, this.latitude]
      }
    }
  }
 
  toJSON(): object {
    return {
      type: 'Point',
      coordinates: [
        this.longitude,
        this.latitude,
      ],
    }
  }
 
  get _internalType() {
    return SYMBOL_GEO_POINT
  }
}