New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

polyline-extended

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

polyline-extended

Encode, decode, length, merge polylines

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
89
increased by8.54%
Maintainers
1
Weekly downloads
 
Created
Source

Polyline Extended

Implementation for Google polyline algorithm with extra salt and sugar.

Demo image

Documentation for polyline algorithm

https://developers.google.com/maps/documentation/utilities/polylinealgorithm

Example

const lib = require("polyline-extended");

lib.decode("ecfnJ_cgwCDnG??{BN?Aq@n@??eEhH@?CYEkCA?gNb@u@??K[CcDXFpE");
lib.encode([[60.123, 24.12312], [60.13123, 25.21312], ...[lat, lon]]);

lib.length("ecfnJ_cgwCDnG??{BN?Aq@n@??eEhH@?CYEkCA?gNb@u@??K[CcDXFpE", "meter");

lib.mergeTwoPolylines("ecfnJ_cgwCDnG??", "{BN?Aq@n@??eEhH@?CYEkCA");

lib.mergePolylines([
  "ecfnJ_cgwCDnG??",
  "{BN?Aq@n@??eEhH@?CYEkCA",
  "?gNb@u@??K[CcDXFpE"
]);

API

Core

✓ Encoding
✓ Decoding
✓ Length
✓ Merging
  ✓ Merge two polylines
  ✓ Merge multiple polylines

Supporting functions

✓ Haversine
✓ Haversine distance

Documentation

Encoding
/**
 * Encode pairs of lat and lon into a polyline encoded string
 * @param points {Array.Array[lat, lon]}
 * @return encoded polyline {String}
 */
function encode(points)
Decoding
/**
 * Decode a polyline string into an array of coordinates.
 * @see This is adapted from the implementation in Project-OSRM
 * https://github.com/DennisOSRM/Project-OSRM-Web/blob/master/WebContent/routing/OSRM.RoutingGeometry.js
 *
 * @param {string} polyline - polyline string
 * @param {integer} precision - coordinates precision (number of decimal)
 *
 * @return {Array[Array[Number]]} coordinates
 */
function decode(polyline, precision)
Length
/**
 * Calculate the distance of the polyline. If radius is not provided, distance is flat, else distance is haversine distance
 * NOTE: Support flat surface and sphere
 *
 * @param {string} polyline - The polyline to calculate from
 * @param {enum={meter, kilometer}]} [unit=kilometer] - The unit of the response.
 *
 * @return {Float} length - unit based on options.radius unit
 */
function length(polyline, unit)
Merge two polylines
/**
 * Merge two polylines into one single polyline
 * @param {string} poly1 - origin polyline
 * @param {string} poly2 - connected polyline
 *
 * @return {string} finalPolyline - merged polyline
 */
function mergeTwoPolylines(poly1, poly2)
Merge multiple polylines
/**
 * Merge multiple polylines into a connected one
 * @param  {Array[string]} polylines - Array of multi polylines
 *
 * @return {string} one single merged polyline
 */
function mergePolylines(polylines)
Haversine
/**
 * Calculate haversine of a number
 *
 * @param {float} number - input number
 * @return {float} haversine
 */
function haversine(number)
Haversine Distance
/**
 * Calculate the haversine distance between 2 points
 * on the Earth, using radius of 6371 km
 *
 * @param {Array[{ lat,lon }]} point1 - lat, lon are mandatory
 * @param {Array[{ lat,lon }]} point2 - lat, lon are mandatory
 * @return {float} distance
 */
function haversineDistance(_point1, _point2)

Keywords

FAQs

Package last updated on 05 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc