fabricjs - complex shape selection on canvas -
i have canvas background image, need draw virtual regions on canvas selecting parts of image.
currently using fabricjs draw simple shapes rectangle, circle on canvas. don't know how draw complex shapes.
can please?
function createpath(event) { var pointers = canvas.getpointer(event.originalevent); if (firstclick) { var pointsarray = ["m", pointers.x, pointers.y]; initializepath(pointsarray); firstclick = false; } else { var pointsarray = ["l", pointers.x, pointers.y]; addpath(pointsarray); } } function initializepath(pointsarray) { var path = new fabric.path('m 0 0'); path.path[0] = pointsarray; path.set({ fill: 'red', stroke: 'green', opacity: 0.3, type: objecttype.region, shape: builderconstants.heatmapshapetype.polygon }); canvas.add(path); } function addpath(pointsarray) { var latestaddedpath = canvas.getobjects()[object.keys(canvas.getobjects()).length - 1]; latestaddedpath.path.push(pointsarray); latestaddedpath.path.push(["z"]); canvas.renderall(); }
Comments
Post a Comment