我浏览了图书馆附带的示例集合,但不幸的是,所有专门用于合成图形的示例都是基于解析 json 文件。
reader.unmarshal(canvas, jsonDocument);
但是,我想看到的是如何从基本图形创建复合图形,例如:
var figure_1 = new draw2d.shape.basic.Rectangle(....);
var figure_1 = new draw2d.shape.basic.Diamond(....);
... then do something, so that figure_1 and figure_2 are now part of
... a composite figure
PS。我认为我需要的是StrongComposite,但我不知道如何使用它。希望有人能帮忙!
编辑
这是我尝试过的:
var baseRectangle = new draw2d.shape.composite.StrongComposite({width: 200, height: 200, x: conf.x, y: conf.y});
var top = new draw2d.shape.basic.Oval({width: 120, height: 40, x: conf.x, y: conf.y});
var bottom = new draw2d.shape.basic.Oval({width: 120, height: 40, x: conf.x, y: conf.y + 60});
baseRectangle.assignFigure(top);
baseRectangle.assignFigure(bottom);
canvas.add(baseRectangle);
但它不起作用。我只看到一个灰色的盒子。我也试过这个:
var baseRectangle = new draw2d.shape.composite.StrongComposite({width: 200, height: 200, x: conf.x, y: conf.y});
var top = new draw2d.shape.basic.Oval({width: 120, height: 40, x: conf.x, y: conf.y});
var bottom = new draw2d.shape.basic.Oval({width: 120, height: 40, x: conf.x, y: conf.y + 60});
baseRectangle.assignFigure(top);
baseRectangle.assignFigure(bottom);
canvas.add(top);
canvas.add(bottom);
但结果,我得到了完全独立的椭圆形。