Skip to content

Commit

Permalink
Merge pull request #697 from geographika/selection-clear
Browse files Browse the repository at this point in the history
Fix for removing a selected features throwing a key error
  • Loading branch information
geographika committed Jun 22, 2021
2 parents c749533 + 94c23b1 commit 416af44
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
3 changes: 2 additions & 1 deletion classic/selection/FeatureModelMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ Ext.define('GeoExt.selection.FeatureModelMixin', {
var selFeature = record.getFeature();

// toggle feature's selection state
selFeature.set(me.selectedFeatureAttr, isSelected);
var silent = true;
selFeature.set(me.selectedFeatureAttr, isSelected, silent);

if (isSelected) {
me.selectedFeatures.push(selFeature);
Expand Down
68 changes: 68 additions & 0 deletions test/spec/GeoExt/selection/FeatureRowModel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,72 @@ describe('GeoExt.selection.FeatureRowModel', function() {
}
);
});

describe('selection and clearing of features with filters', function() {
var selModel;
var grid;
var featStore;
var selRec;
var selFeat;
var layer;

beforeEach(function() {
var feat = new ol.Feature({fid: 1});
var coll = new ol.Collection();
coll.push(feat);

layer = new ol.layer.Vector({
source: new ol.source.Vector({
features: coll
})
});

featStore =
Ext.create('GeoExt.data.store.Features', {
layer: layer
});

featStore.filterBy(function(rec) {
return rec.get('fid') !== -1;
});

selModel = Ext.create('GeoExt.selection.FeatureRowModel', {
mode: 'SINGLE'
});
// feature grid with a feature selection model
grid = Ext.create('Ext.grid.Panel', {
store: featStore,
selModel: selModel
});
selRec = featStore.getAt(0);
selFeat = selRec.getFeature();
});

afterEach(function() {
selModel.destroy();
featStore.destroy();
grid.destroy();
selModel = null;
featStore = null;
grid = null;
selRec = null;
selFeat = null;
});

it('selection is cleared when layer is cleared', function() {
grid.getView().setSelection(selRec);
layer.getSource().clear();
expect(selModel.selectedFeatures.getLength()).to.be(0);
expect(featStore.getData().getCount()).to.be(0);
expect(layer.getSource().getFeatures().length).to.be(0);
});

it('selection is cleared when feature is removed', function() {
grid.getView().setSelection(selRec);
layer.getSource().removeFeature(selFeat);
expect(selModel.selectedFeatures.getLength()).to.be(0);
expect(featStore.getData().getCount()).to.be(0);
expect(layer.getSource().getFeatures().length).to.be(0);
});
});
});

0 comments on commit 416af44

Please sign in to comment.