JSPM

@mapbox/polyline

0.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 366921
  • Score
    100M100P100Q175420F

Polyline encoding and decoding

Package Exports

  • @mapbox/polyline

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@mapbox/polyline) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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