diff --git a/src/ol/feature.js b/src/ol/feature.js index a0909998dd..553d0c39d5 100644 --- a/src/ol/feature.js +++ b/src/ol/feature.js @@ -185,6 +185,7 @@ ol.Feature.prototype.setStyle = function(style) { */ ol.Feature.prototype.setId = function(id) { this.id_ = id; + this.dispatchChangeEvent(); }; diff --git a/test/spec/ol/feature.test.js b/test/spec/ol/feature.test.js index de7d617344..76f5ea4d69 100644 --- a/test/spec/ol/feature.test.js +++ b/test/spec/ol/feature.test.js @@ -232,6 +232,34 @@ describe('ol.Feature', function() { }); + describe('#setId()', function() { + + it('sets the feature identifier', function() { + var feature = new ol.Feature(); + expect(feature.getId()).to.be(undefined); + feature.setId('foo'); + expect(feature.getId()).to.be('foo'); + }); + + it('accepts a string or number', function() { + var feature = new ol.Feature(); + feature.setId('foo'); + expect(feature.getId()).to.be('foo'); + feature.setId(2); + expect(feature.getId()).to.be(2); + }); + + it('dispatches the "change" event', function(done) { + var feature = new ol.Feature(); + feature.on('change', function() { + expect(feature.getId()).to.be('foo'); + done(); + }); + feature.setId('foo'); + }); + + }); + describe('#getStyleFunction()', function() { var styleFunction = function(resolution) {