jim*_*jim 5 javascript svg canvas subclassing fabricjs
我有一个FabricJS基于FabricJS组的自定义子类:
var canvasObject = fabric.util.createClass(fabric.Group, {
type: 'canvasObject',
initialize: function(options) {
options || (options = { });
this.callSuper('initialize', options);
var rectBase = new fabric.Rect({
fill : 'red',
originX: 'left',
originY: 'top',
left: options.margin.l,
top: options.margin.t,
width : (options.width-options.margin.l-options.margin.r),
height :(options.height-options.margin.t-options.margin.b),
});
var labeledRect = new LabeledRect({
width: options.width,
height: options.height,
'idname': options.idname,
background: 'transparent',
labelFont: '14px Helvetica',
});
this.callSuper('initialize', [labeledRect, rectBase], options);
},
toObject: function() {
return fabric.util.object.extend(this.callSuper('toObject'), {
idname: this.get('idname')
});
},
_render: function(ctx) {
this.callSuper('_render', ctx);
}
});
Run Code Online (Sandbox Code Playgroud)
如何在此自定义组中包含 SVG。我希望能够从类似于以下的 URL 加载 SVG:
fabric.loadSVGFromURL('example.svg', function(objects, options) {
var shape = fabric.util.groupSVGElements(objects, options);
canvas.add(shape.scale(1));
canvas.renderAll();
});
Run Code Online (Sandbox Code Playgroud)
但将其添加到我的自定义组中的画布中 - 这样添加的每个 canvasObject 都可以附加一个 SVG。
我尝试将 SVG 添加到 PathGroup 对象 - 但我不确定异步加载是否可以使用它。
我还希望能够更新每个组中的 SVG 图像。如何像更新对象属性一样更新 SVG 路径内容?