Skip to content

Commit

Permalink
Add a hit tolerance to feature selection model. (#690)
Browse files Browse the repository at this point in the history
* Add a hit tolerance to feature selection model.

* Add fix to order of operations.

* Remove setting bound to true in destroy

* Improve test for call of unbind

* Make test script callable without lint
  • Loading branch information
simonseyock committed Jun 10, 2021
1 parent 0e6df60 commit 9d955f5
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
12 changes: 8 additions & 4 deletions classic/selection/FeatureModelMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ Ext.define('GeoExt.selection.FeatureModelMixin', {

mixinConfig: {
after: {
destroy: 'unbindOlEvents',
bindComponent: 'bindFeatureModel'
},
before: {
destroy: 'unbindOlEvents',
constructor: 'onConstruct',
onSelectChange: 'beforeSelectChange'
}
Expand All @@ -57,6 +57,11 @@ Ext.define('GeoExt.selection.FeatureModelMixin', {
*/
mapSelection: false,

/**
* Set a pixel tolerance for the map selection. Defaults to 12.
*/
selectionTolerance: 12,

/**
* The default style for the selected features.
* @cfg {ol.style.Style}
Expand Down Expand Up @@ -187,8 +192,6 @@ Ext.define('GeoExt.selection.FeatureModelMixin', {
me.map.un('singleclick', me.onFeatureClick);
me.mapClickRegistered = false;
}

this.bound_ = false;
},

/**
Expand Down Expand Up @@ -253,7 +256,8 @@ Ext.define('GeoExt.selection.FeatureModelMixin', {
}, {
layerFilter: function(layer) {
return layer === me.layer;
}
},
hitTolerance: me.selectionTolerance
});

if (feat) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"clean:dist": "rimraf ./dist/*",
"lint": "eslint src/ examples/ classic/ && eslint -c test/.eslintrc test/",
"lint:fix": "eslint --fix src/ examples/ && eslint --fix -c test/.eslintrc test/",
"pretest": "npm run test:fetch-external && npm run lint",
"test": "karma start test/karma.conf.js --single-run",
"test": "npm run lint && npm run test:spec",
"test:spec": "npm run test:fetch-external && karma start test/karma.conf.js --single-run",
"test:fetch-external": "node ./bin/fetch-external-resources.js",
"test:debug": "karma start test/karma.conf.js --single-run --debug",
"test:coverage": "karma start test/karma.conf.js --single-run --reporters coverage",
Expand Down
46 changes: 40 additions & 6 deletions test/spec/GeoExt/selection/FeatureRowModel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,52 @@ describe('GeoExt.selection.FeatureRowModel', function() {
});

describe('destruction', function() {
var testObjs;
var map;

beforeEach(function() {
testObjs = TestUtil.setupTestObjects({
mapOpts: {
view: new ol.View({
center: [0, 0],
zoom: 2
})
}
});

map = testObjs.map;
});

afterEach(function() {
TestUtil.teardownTestObjects(testObjs);
});

it('binds and unbinds', function() {
var selModel = Ext.create('GeoExt.selection.FeatureRowModel');
var spy = sinon.spy(GeoExt.selection.FeatureRowModel.prototype,
'onFeatureClick');

var selModel = Ext.create('GeoExt.selection.FeatureRowModel', {
mapSelection: true,
map: map,
layer: new ol.layer.Vector({
source: new ol.source.Vector()
})
});

expect(selModel.bound_).to.be(undefined);
var panel = Ext.create('Ext.grid.Panel', {
title: 'Feature Grid w. SelectionModel',
selModel: selModel
});

selModel.bindComponent();
map.dispatchEvent('singleclick');

expect(selModel.bound_).to.be(true);
expect(spy.calledOnce).to.be(true);

selModel.destroy();
panel.destroy();

map.dispatchEvent('singleclick');

expect(selModel.bound_).to.be(false);
expect(spy.calledOnce).to.be(true);
});
});

Expand Down

0 comments on commit 9d955f5

Please sign in to comment.