Skip to content

Commit

Permalink
Apply correct model to FeatureStore with fields
Browse files Browse the repository at this point in the history
This ensures that the FeatureStore (GeoExt.data.store.Features) uses the
correct model class in case of beeing instanciated with a 'fields'
configuration. Otherwise an implicit model is generated and the reference
to the OL feature in the record is missing (fixes geoext#171).
This also adds some tests and adapts the featuregrid example to show the
fixed behaviour.
  • Loading branch information
chrismayer committed Aug 30, 2016
1 parent 0939673 commit 79c8a38
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
4 changes: 3 additions & 1 deletion examples/features/grid.js
Expand Up @@ -228,6 +228,8 @@ Ext.application({

// create feature store by passing a feature collection
featStore1 = Ext.create('GeoExt.data.store.Features', {
fields: ['city', 'pop'],
model: 'GeoExt.data.model.Feature',
features: featColl,
map: olMap,
createLayer: true,
Expand All @@ -254,7 +256,7 @@ Ext.application({
},
onWidgetAttach: function(column, gxRenderer, record) {
// update the symbolizer with the related feature
var feature = record.olObject;
var feature = record.getFeature();
gxRenderer.update({
feature: feature,
symbolizers: featRenderer.determineStyle(record)
Expand Down
8 changes: 8 additions & 0 deletions src/data/store/Features.js
Expand Up @@ -145,6 +145,14 @@ Ext.define('GeoExt.data.store.Features', {
me.bindLayerEvents();
},

applyFields: function(fields) {
if (fields) {
this.setModel(
Ext.data.schema.Schema.lookupEntity('GeoExt.data.model.Feature')
);
}
},

/**
* Returns the FeatureCollection which is in sync with this store.
*
Expand Down
66 changes: 66 additions & 0 deletions test/spec/GeoExt/data/store/Features.test.js
Expand Up @@ -60,6 +60,72 @@ describe('GeoExt.data.store.Features', function() {

});

describe('constructor (with fields)', function() {
var feat;
var store;

beforeEach(function() {
var coll = new ol.Collection();
var feat = new ol.Feature();
coll.push(feat);
store = Ext.create('GeoExt.data.store.Features', {
features: coll,
fields: ['foo']
});
});

afterEach(function() {
if (store.destroy) {
store.destroy();
}
store = null;
coll = null;
});

it('constructs an instance of GeoExt.data.store.Features', function() {
expect(store).to.be.an(GeoExt.data.store.Features);
});
it('constructs records with an olObject reference', function() {
expect(store.getAt(0).getFeature()).to.be(feat);
});
it('ensures the store has the right model', function() {
expect(store.model).to.be.an(GeoExt.data.model.Feature);
});

});

describe('constructor (with fields and model)', function() {
var feat;
var store;

beforeEach(function() {
var coll = new ol.Collection();
var feat = new ol.Feature();
coll.push(feat);
store = Ext.create('GeoExt.data.store.Features', {
features: coll,
fields: ['foo'],
model: 'GeoExt.data.model.Feature'
});
});

afterEach(function() {
if (store.destroy) {
store.destroy();
}
store = null;
coll = null;
});

it('constructs an instance of GeoExt.data.store.Features', function() {
expect(store).to.be.an(GeoExt.data.store.Features);
});
it('constructs records with an olObject reference', function() {
expect(store.getAt(0).getFeature()).to.be(feat);
});

});

describe('constructor (with layer)', function() {
var div;
var map;
Expand Down

0 comments on commit 79c8a38

Please sign in to comment.