我正在爲一個圓創建一個SymbolDefinition
,並使用new SymbolItem(definition)
將它放置在畫布上。用於創建定義的圓對象具有默認位置(0,0),默認顏色,並且沒有附加信息,因爲無論默認紙張設置如何。PaperJS SymbolItems在命中搜索結果後丟失屬性
當我實例的符號,並將其放置在某個位置(可以說(20,30)爲例),我也附加了一些其他信息,如名稱,在其數據屬性一些輔助信息等
如果我點擊放置的圓圈並使用project#hitResultAll
對該物品進行回調搜索,則包含在命中結果中的物品將不再擁有上述任何信息。實際上,它似乎是用來創建定義的原始圓對象;它的位置實際上是(0,0),它沒有名稱,數據屬性是空的。
這是一個jsFiddle with an example(打開開發控制檯查看輸出)。
萬一鏈接不起作用,這裏是示例代碼:
var canvas = paper.createCanvas(100, 100);
document.getElementById("canvasDiv").appendChild(canvas);
paper.setup(canvas);
var circle = paper.Path.Circle([0,0], 10);
circle.fillColor = 'red';
var definition = new paper.SymbolDefinition(circle);
var tool = new paper.Tool();
tool.onMouseUp = function(event){
var hitResult = paper.project.hitTestAll(event.point);
if(hitResult.length > 0){
var result = hitResult[0];
var item = result.item;
console.log("Item name should be 'Bob', but is actually " + item.name);
// Output is: Item name should be 'Bob', but is actually null
}
};
var actualCircle = new paper.SymbolItem(definition);
actualCircle.position = [20,30];
actualCircle.name = 'Bob';
console.log("Symbol Item was created with the name " + actualCircle.name);
// Output is: Symbol Item was created with the name Bob
有誰知道爲什麼發生這種情況,我該怎麼去解決呢?