Open ngoluan opened 6 years ago
Hi @ngoluan
Sorry for the slow reply. Unfortunately the shortest path module needs a bit of love at the moment, I've been working on a complete rewrite but it's taking a little while.
I would've thought flattening the data would've been sufficient but apparently not, the only other thing I can think in the short term is try bumping up the resolution
option to 1000 and see if that makes a difference.
If you need additional help perhaps throw together a jsfiddle or runkit snippet, it just saves in the amount of time we have to spend time getting things setup to test :)
Thanks
Thanks for the response! I'll give it a try and will come back if I have any issues.
Hi @rowanwins
I'm one step closer, thanks to your tip. But, when I try it, turf.shortestPath produced a straight line, rather one that avoids obstacles.
Here's the jsfiddle. Do you have any tips?
Hi @rowanwins
I'm one step closer, thanks to your tip. But, when I try it, turf.shortestPath produced a straight line, rather one that avoids obstacles.
Here's the jsfiddle. Do you have any tips?
You have to set a lower resolution. For the example you provided, the resolution has to be 1 for it to make a sensible path.
It may seem like maps have different resolutions, as a resolution at about 40 was enough for me on another map I tried. Note that a much lower resolution means that the path finding algorithm will be much slower. (n² I think)
If you want a curved line, you can use bezierSpline on the path.
Just dropping a note that I did eventually put together this visibility-graph module which is probably a better option in alot of cases
Do you have any tips on how to use this with a land geojson? I'm trying to plot a course between two points and avoid land masses, which is represented by a GeometryCollection of Polygons. But, it throws me an invalid obstacles error probably because the geometry is a multipolygon. So, I try to flatten it using turf.flatten but now I'm stuck in a massive loop.
You can find the geojson file at: http://www.luanngo.ca/apps/game/res/land_sm.json Thanks!