Turfjs / turf

A modular geospatial engine written in JavaScript and TypeScript

Home Page:https://turfjs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

lineArc with leaflet - end angle problem?

tj26x opened this issue · comments

commented

Hello,
I am having trouble with turf lineArc returning the error: coordinates must be an array of two or more positions.
for the example below for RA if I change the endAngley to a value of 276 or 278 turf.lineArc works correctly but a value of 277 always gives an error. R8A also gives the same error.

        //RB works correctly
        var centery = turf.point([115.959444, -31.945]);
        var startAngley = 253; 
        var endAngley = 278;
        var radiusy =69.83195;
        var arc = turf.lineArc(centery, radiusy * 1.852, startAngley, endAngley, options);

        //RA gives error as below
        var centery = turf.point([115.959444, -31.945]);
        var startAngley = 253;
        var endAngley = 277; //change this to 276 or 278 and works fine?!?
        var radiusy =119.7195; //changing this value makes no difference.
        var arc = turf.lineArc(centery, radiusy * 1.852, startAngley, endAngley, options);

       //R8A not ok, give error below		
        var centerx = turf.point([115.959444, -31.945]);
	var startAnglex = 303;
	var endAnglex = 327;
	var radiusx = 60.0439;
	console.log("R168A test");
	var arc = turf.lineArc(centerx, radiusx * 1.852, startAnglex, endAnglex, options);
	console.log(arc);
> turf.min.js:1  Uncaught Error: coordinates must be an array of two or
> more positions
>     at h (turf.min.js:1:2371)
>     at Object.bi [as lineArc] (turf.min.js:43:85958)
>     at getOrderedPolyLines (?dataset=7a95f134-be37-49e6-9aca-0b0780f30258:223009:18)
>     at drawVolume (?dataset=7a95f134-be37-49e6-9aca-0b0780f30258:222669:22)
>     at HTMLDivElement.<anonymous> (?dataset=7a95f134-be37-49e6-9aca-0b0780f30258:222549:8)
>     at HTMLDivElement.dispatch (jquery.min.js:2:43331)
>     at y.handle (jquery.min.js:2:41315)
>     at Object.trigger (jquery.min.js:2:71937)
>     at E.fn.init.triggerHandler (jquery.min.js:2:72616)
>     at Object.checkboxChange (gijgo.min.js:1:121495)

here is a jsfiddle showing the problem.

https://jsfiddle.net/7g9smnkd/1/

I have thousands of these types of lineArc calculations but these 2 are the only ones that cause an error.
Any help would be greatly appreciated.
Thank you.

Using turfjs 7.0.0-alpha.0 (but experienced problem on previous release too)

Thanks for raising - I haven't got the time to fully debug this right now but looking at your reproduction case (thank you for including) it does seem odd and there is nothing immediately obvious wrong with your code or the data. I noticed if you change the steps option down to 14 it passes without an error.

I'll flag this as a bug and hopefully when I or someone gets more time we can investigate.

Oh, this is a good one! 🤯

Basically, if 360 / number of steps in options equals end angle - start angle, this function errors out. So when you changed the angle by a single degree in either direction it was enough to upset that relationship and let the code work.

A fix shouldn't be too difficult. Stay tuned.

Looking into this a bit more @tj26x it has already been fixed and was included in 7.0.0-alpha.0 and later. Would you mind confirming that you're using that version? Just noted that the Turf version in your jsfiddle is still 6.5.0.

commented

So it looks like I am using 6.5.0 but everywhere i go to download the minified (turf.min.js) release 7.0.x points me to this: https://npmcdn.com/@turf/turf@6.5.0/turf.min.js

putting 7.0.0 in the address does not work?

Where can I download an actual 7.0.x release?

Thank you.

7.0.0 isn't officially released yet so please try https://npmcdn.com/@turf/turf@7.0.0-alpha.2/turf.min.js

That's the latest alpha release.

commented

Release 7.0.0 fix my problem. Is it to be officially released soon?

Thank you very much.

Thanks for confirming @tj26x. Will close this issue. Sorry, I'm not aware of any planned release date for v7.