Skip to content

🗺️ Simple utility library for handling geojson polylines

License

Notifications You must be signed in to change notification settings

dongy7/Polyline

Repository files navigation

Polyline

Build Status npm version codecov

Simple utility library for dealing with JSON polylines

Installation

To use with a module bundler like webpack:

npm install --save polyline-coordinates

Usage

const Polyline = require('polyline-coordinates');

// the polyline needs to be an array of [latitude, longitude] values
const polyline = Polyline.createLine([[34.028337, -118.259954], [37.773566, -122.412786]])

polyline.getLengthInMiles()
// 347.618 miles

polyline.getLengthInKm()
// 559.43555212 km

polyline.getPointCovering(0.5);
// [35.91355, 120.33155]

API

Polyline.createLine(geojson)

Creates a new polyline instance with the json representation of a polyline.

Polyline.getDistanceBetweenPoints(start, end)

Returns the distance in miles between two coordinates.

Polyline.getDistanceBetweenPointsKm(start, end)

Returns the distance in kilometers between two coordinates.

.getLengthInMiles()

Returns the total distance covered by the polyline in miles.

.getLengthInKm()

Returns the total distance covered by the polyline in kilometers.

.getPointCovering(percent)

Returns the coordinate of the point that covers the percentage of the polyline specified.

For example .getPointCovering(0.5) will return the coordinates of the point that is located in the middle of the polyline.

About

🗺️ Simple utility library for handling geojson polylines

Resources

License

Stars

Watchers

Forks

Packages

No packages published