npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

spherical-geometry-js

v3.0.2

Published

This library provides classes and functions for the computation of geometric data on the surface of the Earth. Code ported from the Google Maps Javascript API v3

Downloads

43,294

Readme

Spherical Geometry Library · npm Downloads

This library provides classes and functions for the computation of geometric data on the surface of the Earth.

This library ports a small but useful subset of classes from the Google Maps Javascript API version 3, to use as a separate module or in node. I also try to have readable code, so that you can understand what calculations are being made.

How to use

import * as geometry from 'spherical-geometry-js';

Or import individual modules

import { computeArea } from 'spherical-geometry-js';
import computeArea from 'spherical-geometry-js/compute-area';

Notes:

  • The API is nearly identical to the Google Maps Javascript API.
  • Functions automatically convert coordinate objects into LatLngs. See convertLatLng for more details.
  • All computed lengths are returned in meters.

API

The full API of the library is described in the typings file.

Classes and libraries ported from the Google Maps Javascript API:

This module tries to maintain full API compatibility with Google Maps so it can be used as a drop-in replacement.

For convenience, LatLng includes some extra methods.

const latlng = new LatLng(123, 56);
// Alias getters for longitude and latitude

latlng.x === latlng.lng();
latlng.y === latlng.lat();

latlng[0] === latlng.lng();
latlng[1] === latlng.lat();
import { equalLatLngs } from 'spherical-geometry-js';

equalLatLngs(latlng1, latlng2) === latlng1.equals(latlng2);

convertLatLng(like) ⇒ LatLng

import { LatLng, convertLatLng } from 'spherical-geometry-js';

convertLatLng({ lat: 123, lng: 56 }).equals(new LatLng(123, 56));
convertLatLng([56, 123]).equals(new LatLng(123, 56));
convertLatLng({ x: 56, y: 123 }).equals(new LatLng(123, 56));

Helper function that tries to convert and object into a LatLng. Tries a few different methods:

  1. If instanceof LatLng, clone the object and return it.

  2. If it has lat and lng properties...

    2a. if the properties are functions (like Google LatLngs), use the lat() and lng() values as latitude and longitude.

    2b. otherwise get lat and lng, parse them as floats and use them.

  3. If it has lat and long properties, parse them as floats use them.

  4. If it has lat and lon properties, parse them as floats use them.

  5. If it has latitude and longitude properties, parse them as floats use them.

  6. If it has number values for 0 and 1 (aka an array of two numbers), use 1 as latitude and 0 as longitude.

  7. If it has x and y properties, try using y as latitude and x and longitude.