From 0bb04fffffb67f7dc0bf623485119c1b948e68d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Fri, 12 Jul 2019 12:14:22 +0200 Subject: [PATCH] Simplify fix for #1685 Create `Base` objects for options, so `extend()` can be used to override properties in a fast and nondestructive manner. --- src/item/HitResult.js | 2 +- src/item/Item.js | 4 ++-- src/item/SymbolItem.js | 15 +++++---------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/item/HitResult.js b/src/item/HitResult.js index 253dc16b..bb51f333 100644 --- a/src/item/HitResult.js +++ b/src/item/HitResult.js @@ -105,7 +105,7 @@ var HitResult = Base.extend(/** @lends HitResult# */{ */ getOptions: function(args) { var options = args && Base.read(args); - return Base.set({ + return new Base({ // Type of item, for instanceof check: Group, Layer, Path, // CompoundPath, Shape, Raster, SymbolItem, ... type: null, diff --git a/src/item/Item.js b/src/item/Item.js index 96636702..99b2b823 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -1818,7 +1818,7 @@ new function() { // Injection scope for various item event handlers // See CompoundPath#_contains() for the reason for !! var matrix = this._matrix; return ( - matrix.isInvertible() && + matrix.isInvertible() && !!this._contains(matrix._inverseTransform(Point.read(arguments))) ); }, @@ -1886,7 +1886,7 @@ new function() { // Injection scope for hit-test functions shared with project var point = Point.read(arguments), options = HitResult.getOptions(arguments), all = []; - this._hitTest(point, Base.set({ all: all }, options)); + this._hitTest(point, new Base({ all: all }, options)); return all; } diff --git a/src/item/SymbolItem.js b/src/item/SymbolItem.js index 1a95a3a8..01b6a779 100644 --- a/src/item/SymbolItem.js +++ b/src/item/SymbolItem.js @@ -121,16 +121,11 @@ 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; + // We need to call definition item hit test with `options.all = false`, + // as otherwise it would populate the array with its own matches. + // Instead we want only returning one match per symbol-item, see #1680 + var opts = options.extend({ all: false }); + var res = this._definition._item._hitTest(point, opts, viewMatrix); // TODO: When the symbol's definition is a path, should hitResult // contain information like HitResult#curve? if (res)