Update fabric.js Path points dynamically

前端 未结 4 789
栀梦
栀梦 2021-01-20 04:05

I\'m trying to add points to a path object dynamically. When I do, the path renders correctly, but the bounding rectangle never gets updated, making it nearly impossible for

4条回答
  •  北恋
    北恋 (楼主)
    2021-01-20 04:50

    Please, fabricjs does not support adding point dinamically as of now. To make it work you can add points like you are doing and then use internal method path._parseDimensions() each time you add points and desire to update bounding box dimension.

    var dims = path._parseDimensions();
    path.setWidth(dims.width);
    path.setHeight(dims.height);
    path.pathOffset.x = path.width/2;
    path.pathOffset.y = path.height/2;
    path.setCoords();
    

    Look this updated fiddle that has the necessary code to solve your problem. I hope it works for every situation.

    http://jsfiddle.net/17ueLva2/6/

提交回复
热议问题