0

I have a path that has over 13,000 lat/lon points. Testing locally it works fine, but once on a device it's SUPER taxing and laggy. The path is so dense because the path has been snapped to roads.

What can I do in order to optimize things so my app runs more smoothly? Define the path densities based on zoom level?? How can I do this?

Justin Young
  • 2,393
  • 3
  • 36
  • 62

3 Answers3

2

Leaflet has a smoothFactor option for L.Polyline vectors:

How much to simplify the polyline on each zoom level. More means better performance and smoother look, and less means more accurate representation.

http://leafletjs.com/reference.html#polyline-smoothfactor

iH8
  • 27,722
  • 4
  • 67
  • 76
1

You can simplify your path as a GeoJSON file, for example using the online tool mapshaper. The website is pretty straight-forward to use.

Simplifying from the source also saves downloading time, rather than fetching the entire 13k points and simplifying in the client with Leaflet.

ghybs
  • 47,565
  • 6
  • 74
  • 99
0

If you are looking for a javascript solution geojson-mend. Ex usuage:

var geomend = require("geojson-mend");
var isMended = geomend.nReduce(<GEOJSON OBJECT>, <TOLERANCE>);
console.log(isMended);

Replace <GEOJSON OBJECT> with your GeoJSON object and the <TOLERANCE> with the resolution you want. 0.0001 is roughly equal to 11.1m.

In your scenario, you could use a variation of this plugin to get and save different levels of details on zoom level change?

pewpewlasers
  • 3,025
  • 4
  • 31
  • 58