Tom MacWright 08c8cf6086 Merge pull request #21 from mapbox/add-mapbox-namespace
Move package to @mapbox namespace.
2016-12-21 21:25:23 -05:00
2015-11-02 17:23:28 +01:00
2016-06-10 17:31:02 -04:00
2016-06-10 17:31:02 -04:00
2015-06-21 17:48:46 -04:00
2016-12-21 21:23:46 -05:00
2015-07-19 14:15:03 +02:00
2015-08-04 14:57:32 -07: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
2016-12-21 21:24:15 -05:00

Build Status Coverage Status

polyline

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

Encodes/decodes into lat/lng coordinate pairs. Use fromGeoJSON() to encode from GeoJSON objects.

Installation

npm install @mapbox/polyline

Example

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

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

// returns a string-encoded polyline
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": {}
});

Command line

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

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

Example :

cat file.json | ./bin/polyline.bin.js --fromGeoJSON > result.txt

Documentation

See Also

Description
polyline encoding and decoding in javascript
Readme BSD-3-Clause 901 KiB
Languages
JavaScript 99.7%
Makefile 0.3%