Simplify.js (License: BSD, GitHub: mourner / simplify-js, npm: simplify-js) is a tiny high-performance JavaScript polyline simplification library by Vladimir Agafonkin, extracted from Leaflet, a JS interactive maps library of the same author. It uses a combination of Douglas-Peucker and Radial Distance algorithms. Works both on browser and server platforms.

Polyline simplification dramatically reduces the number of points in a polyline while retaining its shape, giving a huge performance boost when processing it and also reducing visual noise. For example, it's essential when rendering a 70k-points line chart or a map route in the browser using Canvas or SVG.

points, simplified with tolerance: px
After simplification: points (~ times less)
Performed in ms

The test data for the example is actually a ~10700 mile car route from Lisboa, Portugal to Singapore on a world scale, generated by the CloudMade Navigation service based on OpenStreetMap data.

simplify(points, tolerance, highQuality)

Returns an array of simplified points.

points [Array]

An array of points of {x: Number, y: Number} format.

Configurability of point format would draw a significant performance overhead, so if you use a different format, e.g. [Number, Number], just run search/replace of .x and .y through the source of the library to suite it to your application. For a version that works with 3D points, check out the 3d branch.

tolerance [Number] (optional, 1 by default)

Affects the amount of simplification (in the same metric as the point coordinates).

highQuality [Boolean] (optional, false by default)

Excludes distance-based preprocessing step which leads to highest quality simplification but runs ~10-20 times slower.