我正在做一个线框类型的项目,我正在使用 dojo gfx 来创建形状。到目前为止,这就是我卡住的地方。我正在创建一个 gfx 组(在创建曲面之后)并向该组添加 2 个小圆圈(如一个点)。该组是一个 gfx.Movable 组。
现在,我有两个挑战:
1)当组被拖移时,如何连接到gfx组的“onMoved”事件?2) 我如何访问 gfx 组内的圆圈以获取其形状?有没有办法可以为组设置一个 ID 并像 dom.byId() 一样访问它?或任何替代方案/解决方法?
我以为有人会遇到类似的情况,并认为我可能会在这里得到一些帮助。
谢谢。
这是示例代码,您可以假设我已经需要所有必要的模块并且必要的 HTML 元素可用。
var container = dojo.byId("devicesTarget");
var surface = dojox.gfx.createSurface(container, 800, 400);
var group = surface.createGroup();
var _m1 = new gfxMoveable(group);
var circle1 = surface.createCircle({cx: 100, cy: 100, r: 3}).setStroke("green").setFill("white");
var circle2 = surface.createCircle({cx: 400, cy: 400, r: 3}).setStroke("red").setFill("white");
group.add(circle1);
group.add(circle2);
dojo.connect(_m1, "onMoved", function(ARG1){
//This code never gets executed!
console.log("ABC Hurray: The group was moved");
});
dojo.connect(group.getEventSource(), "onMoved", function(ARG1){
//This code never gets executed either!
console.log("XYZ Hurray: The group was moved");
});
dojo.connect(group.getEventSource(), "onmousemove", function(ARG1) {
//This code gets executed successfully after the entire group is moved and onmousemove is triggered. However, I am not getting the recent shape of the circles.
//I always get the initial shape of the circles! :(
var circShape1 = circle1.getShape();
var circShape2 = circle2.getShape();
console.log("circShape1 :", circShape1);
console.log("circShape2 :", circShape2);
});