Simplify fix for #1685

Create `Base` objects for options, so `extend()` can be used to override properties in a fast and nondestructive manner.
This commit is contained in:
Jürg Lehni 2019-07-12 12:14:22 +02:00
parent aec1c2c138
commit 0bb04fffff
3 changed files with 8 additions and 13 deletions

View file

@ -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,

View file

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

View file

@ -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)