1.2.1 • Published 2 years ago

@mapbox/polyline v1.2.1

Weekly downloads
102,155
License
-
Repository
github
Last release
2 years ago

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
@mapbox-ts/mapbox-gl-directionsmycourier-sharedvietmap-sdk@chargetrip/javascript-sdkblindajeleaflet.travelnotesgraphhopperleaflet.travelnotesmapboxleaflet.travelnotesmapzenvalhallaleaflet.travelnotesopenrouteserviceleaflet.travelnotesosrmviatransitmb-gl-dir-swf@expocraft/coresop-vml@everything-registry/sub-chunk-579vandelay-utilvanessa-mapbox-gl-directionsvietmap-gl-directions@doncicuto/core-utils@conveyal/analysis-ui@conveyal/tauigeovis-map-server@myorders/leaflet-routing-machine1static-maps-overlaytileserver-gltileserver-gl-lighttransform-to-geojsontrackasia-gl-directionstripkit-reacttransport-tracker-servertookan-tracker-react-native-sdktookan-tracker-sdk-react-native@axdspub/axiom-maps@barbora-delivery/coordinate@barbora-delivery/osrm@barbora-delivery/vroom-route-planner@barbora-express/courier-app-ui@chargetrip/planner-widget@acalcutt/tileserver-gl@acalcutt/tileserver-gl-lightvietmaps-gl-directionsvietmaps-sdkzippi-market-core@dtox/utils@greendistrict/sdk@fleetbase/leaflet-routing-machine@egodigital/egoose@gitrows/gitrows-utils@gluedigital/tileserver-gl@gluedigital/tileserver-gl-light@infinitebrahmanuniverse/nolb-_map@lipagas/leaflet-routing-machine@leuven2030/ui@iterplatform/components@myorders/leaflet-routing-machine@mybus/spatial@motowhere/common@mapbox/fid@mapbox/mapbox-sdk@mapbox/yolp-mapbox-static-maps@nbai/nbmap-gl@nbai/skynet-tool-test@easypark/ui@mapbox/mapbox-gl-directions@juliuste/hafas-client@opentripplanner/core-utils@opentripplanner/route-viewer-overlay@opentripplanner/transitive-overlay@opentripplanner/trip-viewer-overlay@ott_test/core-utilsmrmv-shared-packageminsktrans-parsermysamay-activity-srvoptioquooalley.jspelias-polylinepelias-interpolationrouting-componentsreact-native-map-directionnb-plannearmydear-react-mapplanner-widgetpolyline-circlepolyline-midpointridecabridersg-heatmapsimple-multi-geocodersingapore-train-datagpx-to-encoded-polylinehypertrack-simulate-locationshotel-libraries-geohere-map-wrapperiobroker.radar-trapleaflet-routing-machine-legsleaflet-routing-machine-lightleaflet-routing-machine-locationiqleaflet-routing-machineleaflet-routing-machine-customleaflet-routing-machine-doneleaflet-better-filelayer
1.2.1

2 years ago

1.2.0

2 years ago

1.1.1

5 years ago

1.1.0

6 years ago

1.0.0

7 years ago

0.2.0

8 years ago