Skip to content

Commit 4270c23

Browse files
fix: 再次恢复patch397 (#463)
1 parent 6461a9a commit 4270c23

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

packages/core/plugin/PolygonModifyPlugin.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,24 @@ function renderIconEdge(
9090
left: number,
9191
top: number,
9292
styleOverride: any,
93-
fabricObject: fabric.Object
93+
fabricObject: fabric.Object,
94+
img: HTMLImageElement
9495
) {
95-
const img = document.createElement('img');
96-
img.src = edgeImg;
9796
drawImg(ctx, left, top, img, 25, 25, fabric.util.degreesToRadians(fabricObject.angle || 0));
9897
}
9998

10099
class PolygonModifyPlugin implements IPluginTempl {
101100
public isEdit: boolean;
101+
private img: HTMLImageElement;
102102
static pluginName = 'PolygonModifyPlugin';
103103
static events = [];
104104
static apis = ['toggleEdit', 'activeEdit', 'inActiveEdit'];
105105

106106
constructor(public canvas: fabric.Canvas, public editor: IEditor) {
107107
this.isEdit = false;
108+
const img = document.createElement('img');
109+
img.src = edgeImg;
110+
this.img = img;
108111
this.init();
109112
}
110113
init() {
@@ -124,6 +127,7 @@ class PolygonModifyPlugin implements IPluginTempl {
124127
this._ensureEvent(poly);
125128
if (poly.points == null) return;
126129
const lastControl = poly.points.length - 1;
130+
const This = this;
127131
poly.controls = poly.points.reduce<Record<string, PointIndexControl>>(function (
128132
acc,
129133
point,
@@ -133,7 +137,7 @@ class PolygonModifyPlugin implements IPluginTempl {
133137
positionHandler: polygonPositionHandler,
134138
actionHandler: anchorWrapper(index > 0 ? index - 1 : lastControl, actionHandler),
135139
actionName: 'modifyPolygon',
136-
render: (...args) => renderIconEdge(...args),
140+
render: (...args) => renderIconEdge(...args, This.img),
137141
});
138142
Object.defineProperty(acc['p' + index], 'pointIndex', { value: index });
139143
return acc;

0 commit comments

Comments
 (0)