1.2.1 • Published 7 months ago

@mapbox/polyline v1.2.1

Weekly downloads
102,155
License
-
Repository
github
Last release
7 months 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-579facilmap-serverexpo-componentsiobroker.radar-traphypertrack-simulate-locationshotel-libraries-geo@egodigital/egoosegpx-to-encoded-polyline@fleetbase/leaflet-routing-machinehere-map-wrappergeojson-polylinegeojson-polyline-collections-fixgeometry-librarygeo-routers@dtox/utilsmysamay-activity-srvnb-planpelias-interpolationpelias-polylineoalley.jsoptioquomb-mapleaflet-better-filelayerleaflet-routing-machineleaflet-routing-machine-customleaflet-routing-machine-legsleaflet-routing-machine-lightleaflet-routing-machine-locationiqleaflet-routing-machine-doneleaflet.stravasegmentslrm-googlelrm-google-routerlrm-mapzenmake-geo-jsonmapbox-gl-direction-locationmapbox-gl-directions-v2mapdirectmapdirectrealtimemaplibre-gl-vector-text-protocolmaptalks.formatsmeey-gl-directionsminsktrans-parserpolyline-circlepolyline-midpointconvert-google-directionscargolink-mapcargolink-map-jstileserver-gltileserver-gl-lightsg-heatmapsingapore-train-datarouting-componentsstatic-maps-overlayreact-native-map-directionridecabridertransform-to-geojsontransport-tracker-servertrackasia-gl-directionstookan-tracker-react-native-sdktookan-tracker-sdk-react-nativetripkit-reactvietmap-gl-directionsvietmaps-gl-directionsvietmaps-sdkvanessa-mapbox-gl-directionsvandelay-utildirections-to-geojson@leuven2030/ui@opentripplanner/core-utils@opentripplanner/route-viewer-overlay@opentripplanner/transitive-overlay@opentripplanner/trip-viewer-overlay@mybus/spatial@nbai/nbmap-gl@nbai/skynet-tool-test@juliuste/hafas-client@motowhere/common@ott_test/core-utilszippi-market-core@infinitebrahmanuniverse/nolb-_map@mapbox/fid@mapbox/mapbox-gl-directions@mapbox/mapbox-sdk@mapbox/yolp-mapbox-static-maps@iterplatform/components@usig-gcba/recorridos-multimodo
1.2.1

7 months ago

1.2.0

1 year ago

1.1.1

4 years ago

1.1.0

5 years ago

1.0.0

6 years ago

0.2.0

7 years ago