Simplify.js (License: BSD, GitHub: mourner / simplify-js, npm: simplify-js) is a high-performance JavaScript 2D/3D polyline simplification library by Vladimir Agafonkin, extracted from Leaflet, a JS library of the same author for interactive maps. It uses a combination of Douglas-Peucker and Radial Distance algorithms. Works both on browser and server platforms.
Usage: simplify(points, tolerance) // returns an array of simplified points
points
is an array of points of {x: Number, y: Number}
format. It doesn't have the ability to configure point format due to significant performance hit, 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. Similarly, to make it work with 3D points, go through the commented lines at the top of the source.
tolerance
affects the amount of simplification (in the same metric as the point coordinates), 1
by default.
number of points: ,
simplified with tolerance: px
after simplification:
The test data for the example is actually a ~8900 mile car route from London, UK to Phnom Penh, Cambodia on a world scale, generated by the CloudMade Navigation service based on OpenStreetMap data.