选择符号定义路径

时间:2018-01-03 16:53:06

标签: paperjs hittest

我需要查看定义SymbolItem的路径的段和句柄。这是与this one 相关的问题,但反过来(我希望在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; 
    } 
}

1 个答案:

答案 0 :(得分:1)

使用SymbolDefinition / SymbolItem可防止您更改每个符号项目的属性。
在这种情况下,您唯一可以做的就是选择所有具有相同定义的符号。
要实现所需的功能,必须直接使用Path
这是显示解决方案的sketch

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];
    }
}