Dylan Nguyen 5e797bf9cd
Merge pull request #88 from mapbox/npm-audit-fix
[bugi] Package Security Audit
2024-04-10 14:01:08 +03:00
2019-05-03 10:40:39 -04:00
2015-06-21 17:48:46 -04:00
2020-12-10 11:05:09 -05:00
2015-07-19 14:15:03 +02:00
2023-09-14 10:51:00 -04:00
2012-07-19 13:06:11 -04:00
2012-07-19 13:06:11 -04:00
2012-07-26 15:16:21 -04:00
2024-01-16 15:28:40 +02:00
2023-10-24 09:37:03 -04:00
2023-04-06 16:47:48 -04:00

Build Status codecov

polyline

A simple google-esque polyline implementation in Javascript. Compatible with nodejs (npm install @mapbox/polyline and the browser (copy src/polyline.js)).

Encodes from / decodes into [lat, lng] coordinate pairs. Use fromGeoJSON() to encode from GeoJSON objects, or toGeoJSON to decode to a GeoJSON LineString.

Installation

npm install @mapbox/polyline

Note that the old package polyline has been deprecated in favor of @mapbox/polyline (the old package remain but won't receive updates).

Example

var polyline = require('@mapbox/polyline');

// returns an array of lat, lon pairs
polyline.decode('_p~iF~ps|U_ulLnnqC_mqNvxq`@');

// returns an array of lat, lon pairs from polyline6 by passing a precision parameter
polyline.decode('cxl_cBqwvnS|Dy@ogFyxmAf`IsnA|CjFzCsHluD_k@hi@ljL', 6);

// returns a GeoJSON LineString Geometry
polyline.toGeoJSON('_p~iF~ps|U_ulLnnqC_mqNvxq`@');

// returns a string-encoded polyline (from coordinate ordered lat,lng)
polyline.encode([[38.5, -120.2], [40.7, -120.95], [43.252, -126.453]]);

// returns a string-encoded polyline from a GeoJSON LineString
polyline.fromGeoJSON({ "type": "Feature",
  "geometry": {
    "type": "LineString",
    "coordinates": [[-120.2, 38.5], [-120.95, 40.7], [-126.453, 43.252]]
  },
  "properties": {}
});

API Documentation

Command line

Install globally or run ./node_modules/.bin/polyline.

Send input via stdin and use --decode, --encode, --toGeoJSON, or --fromGeoJSON flags. If omitted will default to --decode.

Example :

cat file.json | ./bin/polyline.bin.js --fromGeoJSON > result.txt
Description
polyline encoding and decoding in javascript
Readme BSD-3-Clause 901 KiB
Languages
JavaScript 99.7%
Makefile 0.3%