konvajs / konva

Konva.js is an HTML5 Canvas JavaScript framework that extends the 2d context by enabling canvas interactivity for desktop and mobile applications.

Home Page:http://konvajs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Konvajs Path getPointAtLength Incorrect Compute

nazimwibsoft opened this issue · comments

I have been working with KonvaJS for self testing the new tool, i was loading a SVG path and trying to animate another object around its path, however the getPointAtLength gives me incorrect position on the canvas, I have made a sample to demonstrate this.

image

Attached is a simple SVG closed path and here i have loop through its points to put a red dot. We can clearly see it going in wrong direction.

`// Get the total length of the path
//var totalLength = svgPath.getTotalLength();
var totalLength = konvaPath.getLength();

// Draw a circle at each 1 unit length along the path
for (var length = 0; length <= totalLength; length++) {
  var point = konvaPath.getPointAtLength(length);
  var marker = new Konva.Circle({
    x: point.x,
    y: point.y,
    radius: 2,
    fill: 'red'
  });
  layer.add(marker);
}

`
A very simple piece of code, i wonder if anyone never tried this or reported this issue here as i was unable to find an existing issue logged. Kindly see if this is something already in the roadmap to be fixed, I don't think it should be a big issue that could not be resolved.

DOM SVG already provides same method getPointAtLength on SVG element it works perfectly.

Attached is the working version
working.zip

notworking.zip
This is not working version that is using Konva JS Path method

Thanks for the good demo. Fixed. I will release later.

That's great!