Skip to content

How force Fabric.js polygon to update his points correctly after modify #10428

Answered by shookcodes
TheSinOfGreed asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @TheSinOfGreed!

I just battled with a similar issue with Polygons and their points. Here's what worked for me.

I utilized controlsUtils to generate polygon point controls, then, instead of polygon.setBoundingBox(true), add the option "exactBoundingBox: true" to your initial Polygon options.

const polygon = new fabric.Polygon(polygonPoints, {
  fill: "rgba(0, 128, 255, 0.5)",
  stroke: "blue",
  strokeWidth: 2,
  selectable: true,
  exactBoundingBox: true
});

// Import controlsUtils from Fabric
polygon.set({
  controls: controlsUtils.createPolyControls(polygon)
})

I have a polygon that changes between default controls (using controlsUtils.createObjectDefaultControls()) and polyContro…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@asturur
Comment options

Answer selected by asturur
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants