Fix SymbolItem#hitTestAll()

Closes #1680
This commit is contained in:
Samuel Asensi 2019-07-12 12:06:26 +02:00 committed by Jürg Lehni
parent c9a8d54623
commit aec1c2c138
2 changed files with 24 additions and 0 deletions

View file

@ -121,7 +121,16 @@ var SymbolItem = Item.extend(/** @lends SymbolItem# */{
},
_hitTestSelf: function(point, options, viewMatrix) {
// We need to call definition item hit test with `options.all`
// disabled, otherwise it would populate the array with its own
// matches. What we want instead is only returning one match per symbol
// item (#1680). So we store original matches array...
var all = options.all;
// ...we temporarily disable `options.all`...
delete options.all;
var res = this._definition._item._hitTest(point, options, viewMatrix);
// ...then after hit testing, we restore the original matches array.
options.all = all;
// TODO: When the symbol's definition is a path, should hitResult
// contain information like HitResult#curve?
if (res)

View file

@ -143,3 +143,18 @@ test('SymbolItem#bounds with #applyMatrix = false', function() {
equals(function() { return placed.bounds; },
{ x: 150, y: 150, width: 100, height: 100 });
});
test('SymbolItem#hitTestAll', function() {
var symbol = new SymbolDefinition(
new Path.Circle({
center: [0, 0],
radius: 10,
fillColor: 'orange'
})
);
var symbolItem = symbol.place([50, 50]);
var hitTestAll = symbolItem.hitTestAll([50, 50]);
equals(hitTestAll.length, 1);
equals(hitTestAll[0].item.id, symbolItem.id);
});