我需要查看定义 SymbolItem 的路径的段和句柄。这是一个与此相关的问题,但相反(我希望在该 jsfiddle 上显示的行为(。根据以下示例,我可以查看 SymbolItem 的边界框,但我无法选择路径本身以查看其段/句柄。我错过了什么?
function onMouseDown(event) {
project.activeLayer.selected = false;
// Check whether there is something on that position already. If there isn't:
// Add a circle centered around the position of the mouse:
if (event.item === null) {
var circle = new Path.Circle(new Point(0, 0), 10);
circle.fillColor = '#' + Math.floor(Math.random() * 16777215).toString(16);
var circleSymbol = new SymbolDefinition(circle);
multiply(circleSymbol, event.point);
}
// If there is an item at that position, select the item.
else {
event.item.selected = true;
}
}
function multiply(item, location) {
for (var i = 0; i < 10; i++) {
var next = item.place(location);
next.position.x = next.position.x + 20 * i;
}
}
使用 SymbolDefinition
/SymbolItem
可防止更改每个符号项的属性。
在这种情况下,您唯一能做的就是选择共享通用定义的所有符号。
要实现您想要的,您必须直接使用Path
。
这是显示解决方案的草图。
function onMouseDown(event) {
project.activeLayer.selected = false;
if (event.item === null) {
var circle = new Path.Circle(new Point(0, 0), 10);
circle.fillColor = Color.random();
// just pass the circle instead of making a symbol definition
multiply(circle, event.point);
}
else {
event.item.selected = true;
}
}
function multiply(item, location) {
for (var i = 0; i < 10; i++) {
// use passed item for first iteration, then use a clone
var next = i === 0 ? item : item.clone();
next.position = location + [20 * i, 0];
}
}