From 54aeca247d2fb81b237006666067be798b4b9689 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Sun, 1 Apr 2018 10:30:00 -0700 Subject: [PATCH] Add --toGeoJSON option --- README.md | 5 +++-- bin/polyline.bin.js | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index db0547f..ef92952 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,8 @@ A simple [google-esque polyline](https://developers.google.com/maps/documentation/utilities/polylinealgorithm) implementation in Javascript. Compatible with nodejs (`npm install @mapbox/polyline` and the browser (copy `src/polyline.js`)). -Encodes/decodes into lat/lng coordinate pairs. Use `fromGeoJSON()` to encode from GeoJSON objects. +Encodes/decodes into [lat, lng] coordinate pairs. Use `fromGeoJSON()` to encode from GeoJSON objects, or `toGeoJSON` to +decode to a GeoJSON LineString. ## Installation @@ -36,7 +37,7 @@ polyline.fromGeoJSON({ "type": "Feature", 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`. +Send input via stdin and use `--decode`, `--encode`, `--toGeoJSON`, or `--fromGeoJSON` flags. If omitted will default to `--decode`. Example : diff --git a/bin/polyline.bin.js b/bin/polyline.bin.js index c209332..9a6d8d4 100755 --- a/bin/polyline.bin.js +++ b/bin/polyline.bin.js @@ -2,7 +2,7 @@ var polyline = require('../'); -var HELP = 'Provide data from stdin and use with --decode (default), --encode, or --fromGeoJSON\n'; +var HELP = 'Provide data from stdin and use with --decode (default), --encode, --toGeoJSON, or --fromGeoJSON\n'; var mode = process.argv[2] || '--decode'; var rawInput = ''; @@ -34,6 +34,8 @@ function convert(rawString, mode) { return polyline.decode(rawString); case '--encode' : return polyline.encode(rawString); + case '--toGeoJSON': + return polyline.toGeoJSON(rawString); case '--fromGeoJSON' : return polyline.fromGeoJSON(JSON.parse(rawString)); }