PaperJS SymbolItems在命中结果搜索后丢失属性 [英] PaperJS SymbolItems lose properties after hit result search

查看:175
本文介绍了PaperJS SymbolItems在命中结果搜索后丢失属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个圆创建一个 SymbolDefinition ,并使用 new SymbolItem(定义)。用于创建定义的圆形对象的默认位置为(0,0),默认颜色,没有其他信息,因为无论是什么默认纸张设置。

I'm creating a SymbolDefinition for a circle, and placing it on the canvas using new SymbolItem(definition). The circle object used to create the definition had a default position of (0,0), a default color, and no additional information because whatever defaults paper sets.

当我例如,将符号放在某个位置(比方说(20,30)),我还附加一些其他信息,如名称,数据属性中的一些补充信息等。

When I instance the symbol and place it at a certain position (lets say (20,30) for example), I also append some other information such as a name, some supplementary info in its data property, etc.

如果我点击放置的圆圈,并使用项目#hitResultAll 对该项目进行回调搜索,则命中结果中包含的项目为no更长时间拥有上述任何信息。实际上,它似乎是用于创建定义的原始圆形对象;它的位置实际上是(0,0),它没有名称,data属性为空。

If I click on the placed circle, and have a callback search for that item using project#hitResultAll, the item contained within the hit result no longer possesses any of the information mentioned above. In fact, it appears to be the original circle object used to create the definition; its position is in fact (0,0), it has no name, and the data property is empty.

这是 jsFiddle with an example (打开开发控制台查看输出)。

Here is a jsFiddle with an example (open dev console to see output).

如果链接不起作用,这里是示例代码:

In case the link doesn't work, here is the example code:

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

有谁知道为什么这是怎么回事,以及如何解决这个问题?

Does anyone know why this is happening, and how I can go about solving it?

推荐答案

这结果是paperJS热门测试中的一个错误码。感谢 Lehni ,这已得到解决。在这篇文章发布时,尚未部署新版本,但只要你使用任何高于0.10.2的版本,你就应该是安全的。

This turned out to be a bug in the paperJS hit test code. Thanks to Lehni, this has been resolved. At the time of this post, a new release has not been deployed yet, but so long as you use any version above 0.10.2, you should be safe.

如果根据Lehni的说法,你坚持使用旧版本:

If you are stuck with an older version, according to Lehni:


如果你使用hitTest()而不是hitTestAll(),它会返回预期的结果。

If you use hitTest() instead of hitTestAll(), it returns the expected result.

这篇关于PaperJS SymbolItems在命中结果搜索后丢失属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆