nodes2ts
a Typescript porting of the great S2 Geometry library from Google
Last updated 5 months ago by vekexasia .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install nodes2ts 
SYNC missed versions from official npm registry.

Node S2Geometry Typescript

An extensive port of google's s2 geometry library written in Typescript.

The library uses decimal.js and long as external libraries to perform the needed math.

Npm package is nodes2ts.

Tests

This project is backed by 60 1-by-1 comparison tests between this implementation and the original one.

When implementing a not-yet-ported feature, please generate the needed tests by modifiying the java code within java-test-creator folder

Currently not ported

  • S2Loop
  • S2Polygon
  • S2Polyline

Extra code / differences

As already mentioned the lib is almost a 1:1 porting from the java's implementation.

The only exceptions are due javascript limitations such as

  • methods and properties can't share the same name
  • cant have multiple constructor
  • cant overload methods.

The lib also exports a Utils class which contains the following:

export declare class Utils {
    /**
     * Calculates a region covering a circle
     * NOTE: The current implementation uses S2Cap while S2Loop would be better (S2Loop is not implemented yet)
     * @param center
     * @param radiusInKM
     * @param points the number of points to calculate. The higher the better precision
     * @returns {S2Region}
     */
    static calcRegionFromCenterRadius(center: S2LatLng, radiusInKM: number, points?: number): S2Region;
}

Also, for some classes, an extra toGEOJSON method is provided to let developer easily inspect boundaries of cells/points.

Samples

  • Convert Lat/Lng to S2CellId
const cellId = S2CellId.fromPoint(
  S2LatLng.fromDegrees(10 /*latitude*/, 11 /*longitude*/)
);
  • Get previous or next s2cell
// const cellId;
const nextCell = cellId.next();
const prevCell = cellId.prev();
  • Get All neighbor cell ids of cur level
// const cellId;
const neighbors = cellId.getAllNeighbors(cellId.level());
  • See S2cell on google maps
const cell = new S2Cell(cellId);
console.log(cell.toGEOJSON());
// copy the output and paste it on http://geojson.io/

Current Tags

  • 2.0.0                                ...           latest (5 months ago)

9 Versions

  • 2.0.0                                ...           5 months ago
  • 1.1.10                                ...           2 years ago
  • 1.1.9                                ...           3 years ago
  • 1.1.8                                ...           3 years ago
  • 1.1.7                                ...           4 years ago
  • 1.1.6                                ...           4 years ago
  • 1.1.5                                ...           4 years ago
  • 1.1.4                                ...           4 years ago
  • 1.1.3                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 5
Last Day 0
Last Week 1
Last Month 14
Dependencies (1)
Dev Dependencies (17)

Copyright 2014 - 2017 © taobao.org |