Git Product home page Git Product logo

lib-maidenhead-locator's Introduction

@hamset/maidenhead-locator

GitHub Actions Workflow Status NPM Downloads NPM Version (with dist tag) npm bundle size GitHub License

Maidenhead grid locator and WGS84 coordinate calculation and transformation

Usage

npm i @hamset/maidenhead-locator
import {
  validateGridLocator,
  WGS84ToMaidenhead,
  maidenheadToWGS84,
  maidenheadToBoundingBox,
  GridLocator,
  WGS84,
  LatLng
} from '@hamset/maidenhead-locator';

// convert maidenhead grid locator to WGS84 coordinate
const grid_locator = 'DM06gs'
const coordinate: WGS84 = maidenheadToWGS84(grid_locator);
// output: { lat: 36.75, lng: -119.5 }

// convert WGS84 coordinate to maidenhead grid locator
const coordinate: LatLng = { lat: 36.75, lng: -119.5 }
const grid_locator: GridLocator = WGS84ToMaidenhead(coordinate);
// output: 'DM06gs'

// get bounding box coordinates from maidenhead grid locator
const grid_locator = 'DM06gs'
const bounds: [LatLng, LatLng] = maidenheadToBoundingBox(grid_locator); 
// output: [ [ 36.75, -119.5 ], [ 36.791666666666664, -119.41666666666667 ] ]

APIs

import { CoordinateLike, GridLocator, WGS84 } from "./types";
/**
 * Validate grid locator
 * @param gridLocator grid locator
 * @returns true if the grid locator is valid
 */
declare const validateGridLocator: (gridLocator: GridLocator) => boolean;
/**
 * Convert WGS84 to Maidenhead
 * @param coord coordinate
 * @returns grid locator
 */
declare const WGS84ToMaidenhead: (coord: CoordinateLike) => GridLocator;
/**
 * Convert Maidenhead to WGS84
 * @param gridLocator grid locator
 * @returns coordinate
 */
declare const maidenheadToWGS84: (gridLocator: GridLocator) => WGS84;
/**
 * Convert Maidenhead to bounding box coordinates
 * @param gridLocator grid locator
 * @returns A two-dimensional array containing two diagonal coordinates of bounds
 */
declare const maidenheadToBoundingBox: (gridLocator: GridLocator) => [LatLng, LatLng];

//
// types
//
export type LatLng = [number, number];
export interface WGS84 {
    lat: number;
    lng: number;
}
export type CoordinateLike = LatLng | WGS84;
export type LatLngBounds = [LatLng, LatLng];
export type GridLocator = string;

lib-maidenhead-locator's People

Contributors

hoshinosuzumi avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.