Reduce a track to at most max points that keep its shape: first thin a
long track by index (a day's hike can be 20,000 points), then drop the
points that bend the line least (Ramer–Douglas–Peucker), searching for the
smallest tolerance that fits. Distances are in degrees with longitude
scaled by latitude, which is plenty for a thumbnail. A track crossing the
180th meridian is not split, so a map would draw it across the globe.
Throws a RangeError when max is under 2 (a line needs both ends).
Reduce a track to at most
maxpoints that keep its shape: first thin a long track by index (a day's hike can be 20,000 points), then drop the points that bend the line least (Ramer–Douglas–Peucker), searching for the smallest tolerance that fits. Distances are in degrees with longitude scaled by latitude, which is plenty for a thumbnail. A track crossing the 180th meridian is not split, so a map would draw it across the globe. Throws a RangeError whenmaxis under 2 (a line needs both ends).