Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "utils"

Index

Variables

Const BASE32

BASE32: "0123456789bcdefghjkmnpqrstuvwxyz" = "0123456789bcdefghjkmnpqrstuvwxyz"

Const BITS_PER_CHAR

BITS_PER_CHAR: 5 = 5

Const E2

E2: 0.00669447819799 = 0.00669447819799

Const EARTH_EQ_RADIUS

EARTH_EQ_RADIUS: 6378137 = 6378137

Const EARTH_MERI_CIRCUMFERENCE

EARTH_MERI_CIRCUMFERENCE: 40007860 = 40007860

Const EPSILON

EPSILON: 1e-12 = 1e-12

Const GEOHASH_PRECISION

GEOHASH_PRECISION: 10 = 10

Const MAXIMUM_BITS_PRECISION

MAXIMUM_BITS_PRECISION: number = 22 * BITS_PER_CHAR

Const METERS_PER_DEGREE_LATITUDE

METERS_PER_DEGREE_LATITUDE: 110574 = 110574

Functions

boundingBoxBits

  • Calculates the maximum number of bits of a geohash to get a bounding box that is larger than a given size at the given coordinate.

    Parameters

    • coordinate: GeoPoint | GeoPoint

      The coordinate as a Firestore GeoPoint.

    • size: number

      The size of the bounding box.

    Returns number

    The number of bits necessary for the geohash.

boundingBoxCoordinates

  • Calculates eight points on the bounding box and the center of a given circle. At least one geohash of these nine coordinates, truncated' to a precision of at most radius, are guaranteed to be prefixes of any geohash that lies within the circle.

    Parameters

    • center: GeoPoint | GeoPoint

      The center given as Firestore GeoPoint.

    • radius: number

      The radius of the circle.

    Returns GeoPoint[] | GeoPoint[]

    The eight bounding box points.

calculateDistance

  • Method which calculates the distance, in kilometers, between two locations, via the Haversine formula. Note that this is approximate due to the fact that the Earth's radius varies between 6356.752 km and 6378.137 km.

    Parameters

    Returns number

    The distance, in kilometers, between the inputted locations.

decodeGeoDocumentData

  • Decodes the GeoDocument data. Returns non-decoded data if decoding fails.

    Parameters

    • data: Document

      The data encoded as a GeoDocument object.

    Returns DocumentData

    The decoded Firestore document or non-decoded data if decoding fails.

decodeGeoQueryDocumentSnapshotData

  • Decodes the GeoDocument data. Returns non-decoded data if decoding fails.

    Parameters

    • data: Document

      The data encoded as a GeoDocument object.

    • Optional center: GeoPoint | GeoPoint

      The center to calculate the distance of the Document from the query origin.

    Returns object

    The decoded Firestore document or non-decoded data if decoding fails in an object including distance from origin.

degreesToRadians

  • degreesToRadians(degrees: number): number
  • Converts degrees to radians.

    Parameters

    • degrees: number

      The number of degrees to be converted to radians.

    Returns number

    The number of radians equal to the inputted number of degrees.

encodeGeoDocument

  • Encodes a location and geohash as a GeoDocument.

    Parameters

    Returns Document

    The document encoded as GeoDocument object.

encodeGeohash

  • Generates a geohash of the specified precision/string length from the inputted GeoPoint.

    Parameters

    • location: GeoPoint | GeoPoint

      The GeoPoint to encode into a geohash.

    • Default value precision: number = GEOHASH_PRECISION

      The length of the geohash to create. If no precision is specified, the global default is used.

    Returns string

    The geohash of the inputted location.

encodeSetDocument

  • Encodes a Document used by GeoWriteBatch.set as a GeoDocument.

    Parameters

    Returns Document

    The document encoded as GeoDocument object.

encodeUpdateDocument

  • Encodes a Document used by GeoWriteBatch.update as a GeoDocument.

    Parameters

    • data: UpdateData

      The document being updated.

    • Optional customKey: string

      The key of the document to use as the location. Otherwise we default to coordinates.

    Returns UpdateData

    The document encoded as GeoDocument object.

findCoordinates

  • Returns coordinates as GeoPoint from a document.

    Parameters

    • document: DocumentData

      A Firestore document.

    • Optional customKey: string

      The key of the document to use as the location. Otherwise we default to coordinates.

    • Default value flag: boolean = false

      Tells function supress errors.

    Returns GeoPoint | GeoPoint

    The GeoPoint for the location field of a document.

generateGeoQueryDocumentSnapshot

  • Creates GeoFirestore QueryDocumentSnapshot by pulling data out of original Firestore QueryDocumentSnapshot and strip GeoFirsetore Document data, such as geohash and coordinates.

    Parameters

    Returns QueryDocumentSnapshot

    The snapshot as a GeoFirestore QueryDocumentSnapshot.

geohashQueries

  • Calculates a set of queries to fully contain a given circle. A query is a GeoPoint where any geohash is guaranteed to be lexiographically larger then start and smaller than end.

    Parameters

    • center: GeoPoint | GeoPoint

      The center given as a GeoPoint.

    • radius: number

      The radius of the circle.

    Returns string[][]

    An array of geohashes containing a GeoPoint.

geohashQuery

  • geohashQuery(geohash: string, bits: number): string[]
  • Calculates the bounding box query for a geohash with x bits precision.

    Parameters

    • geohash: string

      The geohash whose bounding box query to generate.

    • bits: number

      The number of bits of precision.

    Returns string[]

    A [start, end] pair of geohashes.

latitudeBitsForResolution

  • latitudeBitsForResolution(resolution: number): number
  • Calculates the bits necessary to reach a given resolution, in meters, for the latitude.

    Parameters

    • resolution: number

      The bits necessary to reach a given resolution, in meters.

    Returns number

    Bits necessary to reach a given resolution, in meters, for the latitude.

log2

  • log2(x: number): number
  • Calculates the base 2 logarithm of the given number.

    Parameters

    • x: number

      A number

    Returns number

    The base 2 logarithm of a number

longitudeBitsForResolution

  • longitudeBitsForResolution(resolution: number, latitude: number): number
  • Calculates the bits necessary to reach a given resolution, in meters, for the longitude at a given latitude.

    Parameters

    • resolution: number

      The desired resolution.

    • latitude: number

      The latitude used in the conversion.

    Returns number

    The bits necessary to reach a given resolution, in meters.

metersToLongitudeDegrees

  • metersToLongitudeDegrees(distance: number, latitude: number): number
  • Calculates the number of degrees a given distance is at a given latitude.

    Parameters

    • distance: number

      The distance to convert.

    • latitude: number

      The latitude at which to calculate.

    Returns number

    The number of degrees the distance corresponds to.

sanitizeSetOptions

  • Remove customKey attribute so firestore doesn't' reject.

    Parameters

    Returns SetOptions

    The same object but without custom key

toGeoPoint

  • Returns a 'GeoPoint.' (Kind of fake, but get's the job done!)

    Parameters

    • latitude: number

      Latitude for GeoPoint.

    • longitude: number

      Longitude for GeoPoint.

    Returns GeoPoint | GeoPoint

    Firestore "GeoPoint"

validateGeoDocument

  • validateGeoDocument(data: Document, flag?: boolean): boolean
  • Validates the inputted GeoDocument object and throws an error, or returns boolean, if it is invalid.

    Parameters

    • data: Document

      The GeoDocument object to be validated.

    • Default value flag: boolean = false

      Tells function to send up boolean if valid instead of throwing an error.

    Returns boolean

    Flag if data is valid

validateGeohash

  • validateGeohash(geohash: string, flag?: boolean): boolean
  • Validates the inputted geohash and throws an error, or returns boolean, if it is invalid.

    Parameters

    • geohash: string

      The geohash to be validated.

    • Default value flag: boolean = false

      Tells function to send up boolean if valid instead of throwing an error.

    Returns boolean

validateLimit

  • validateLimit(limit: number, flag?: boolean): boolean
  • Validates the inputted limit and throws an error, or returns boolean, if it is invalid.

    Parameters

    • limit: number

      The limit to be applied by GeoQuery.limit()

    • Default value flag: boolean = false

      Tells function to send up boolean if valid instead of throwing an error.

    Returns boolean

validateLocation

  • Validates the inputted location and throws an error, or returns boolean, if it is invalid.

    Parameters

    • location: GeoPoint | GeoPoint

      The Firestore GeoPoint to be verified.

    • Default value flag: boolean = false

      Tells function to send up boolean if valid instead of throwing an error.

    Returns boolean

validateQueryCriteria

  • validateQueryCriteria(newQueryCriteria: QueryCriteria, requireCenterAndRadius?: boolean): void
  • Validates the inputted query criteria and throws an error if it is invalid.

    Parameters

    • newQueryCriteria: QueryCriteria

      The criteria which specifies the query's center and/or radius.

    • Default value requireCenterAndRadius: boolean = false

      The criteria which center and radius required.

    Returns void

wrapLongitude

  • wrapLongitude(longitude: number): number
  • Wraps the longitude to [-180,180].

    Parameters

    • longitude: number

      The longitude to wrap.

    Returns number

    longitude The resulting longitude.

Generated using TypeDoc