Merge pull request #21385 from rimig/latlon-geohash

Adds typings for latlon-geohash
This commit is contained in:
Daniel Rosenwasser
2017-11-12 00:46:32 -08:00
committed by GitHub
4 changed files with 137 additions and 0 deletions
+94
View File
@@ -0,0 +1,94 @@
// Type definitions for latlon-geohash 1.1
// Project: https://github.com/chrisveness/latlon-geohash
// Definitions by: Robert Imig <https://github.com/rimig>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4
export enum Direction {
North = "N",
South = "S",
East = "E",
West = "W"
}
export interface Neighbours {
n: string;
ne: string;
e: string;
se: string;
s: string;
sw: string;
w: string;
nw: string;
}
export interface Bounds {
sw: Point;
ne: Point;
}
export interface Point {
lat: number;
lon: number;
}
/**
* Encodes latitude/longitude to geohash, either to specified precision or to automatically
* evaluated precision.
*
* @param lat - Latitude in degrees.
* @param lon - Longitude in degrees.
* @param [precision] - Number of characters in resulting geohash.
* @returns Geohash of supplied latitude/longitude.
* @throws Invalid geohash.
*
* @example
* var geohash = Geohash.encode(52.205, 0.119, 7); // geohash: 'u120fxw'
*/
export function encode(
latitude: number,
longitude: number,
precision?: number
): string;
/**
* Decode geohash to latitude/longitude (location is approximate centre of geohash cell,
* to reasonable precision).
*
* @param geohash - Geohash string to be converted to latitude/longitude.
* @returns (Center of) geohashed location.
* @throws Invalid geohash.
*
* @example
* var latlon = Geohash.decode('u120fxw'); // latlon: { lat: 52.205, lon: 0.1188 }
*/
export function decode(geohash: string): Point;
/**
* Returns SW/NE latitude/longitude bounds of specified geohash.
*
* @param geohash - Cell that bounds are required of.
* @returns The Bounds
* @throws Invalid geohash.
*/
export function bounds(geohash: string): Bounds;
/**
* Determines adjacent cell in given direction.
*
* @param geohash - Cell to which adjacent cell is required.
* @param direction - Direction from geohash (N/S/E/W).
* @returns Geocode of adjacent cell.
* @throws Invalid geohash.
*/
export function adjacent(geohash: string, direction: Direction | string): string;
/**
* Returns all 8 adjacent cells to specified geohash.
*
* @param geohash - Geohash neighbours are required of.
* @returns The neighbours
* @throws Invalid geohash.
*/
export function neighbours(geohash: string): Neighbours;
@@ -0,0 +1,19 @@
import * as Geohash from "latlon-geohash";
// Encoding
const atx_geohash: string = Geohash.encode(30.2672, -97.7431);
const atx_geohash_p3: string = Geohash.encode(30.2672, -97.7431, 3);
// Decoding
const atx_latlong: Geohash.Point = Geohash.decode(atx_geohash);
// Bounds
const atx_bounds: Geohash.Bounds = Geohash.bounds(atx_geohash);
// Adjacent
const atx_adj_cell1: string = Geohash.adjacent(atx_geohash, Geohash.Direction.North);
const atx_adj_cell2: string = Geohash.adjacent(atx_geohash, "N");
// Neighbors
const atx_neighbors: Geohash.Neighbours = Geohash.neighbours(atx_geohash);
const atx_adj_cell3: string = atx_neighbors.n;
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"latlon-geohash-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }