@mapbox/polyline
    DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/mapbox__polyline package

    1.1.1 • Public • Published

    Build Status Coverage Status

    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 feature
    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
    

    Keywords

    none

    Install

    npm i @mapbox/polyline

    DownloadsWeekly Downloads

    227,015

    Version

    1.1.1

    License

    none

    Unpacked Size

    16.6 kB

    Total Files

    12

    Last publish

    Collaborators

    • mapbox-admin
    • mapbox-machine-user
    • mapbox-npm
    • mapbox-npm-01
    • mapbox-npm-02
    • mapbox-npm-03
    • mapbox-npm-04
    • mapbox-npm-05
    • mapbox-npm-06
    • mapbox-npm-07
    • mapbox-npm-08
    • mapbox-npm-09
    • mapbox-npm-advanced-actions
    • mapbox-npm-ci