Skip to content

Commit

Permalink
Merge pull request openlayers#2742 from fredj/updatefeature
Browse files Browse the repository at this point in the history
Dispatch an 'updatefeature' from the vector source
  • Loading branch information
fredj committed Sep 25, 2014
2 parents b1ca9a4 + 79b8ef3 commit aafe50c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/ol/source/vectorsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ ol.source.VectorEventType = {
* @api stable
*/
ADDFEATURE: 'addfeature',

/**
* Triggered when a feature is updated.
* @event ol.source.VectorEvent#updatefeature
* @api
*/
UPDATEFEATURE: 'updatefeature',

/**
* Triggered when a feature is removed from the source.
* @event ol.source.VectorEvent#removefeature
Expand Down Expand Up @@ -437,6 +445,8 @@ ol.source.Vector.prototype.handleFeatureChange_ = function(event) {
}
}
this.changed();
this.dispatchEvent(new ol.source.VectorEvent(
ol.source.VectorEventType.UPDATEFEATURE, feature));
};


Expand Down
11 changes: 11 additions & 0 deletions test/spec/ol/source/vectorsource.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,17 @@ describe('ol.source.Vector', function() {
expect(listener).to.be.called();
});

it('fires a updatefeature event when updating a feature', function() {
var feature = new ol.Feature(new ol.geom.Point([1, 1]));
vectorSource.addFeature(feature);
var listener = sinon.spy(function(event) {
expect(event.feature).to.be(feature);
});
vectorSource.on('updatefeature', listener);
feature.setStyle(null);
expect(listener).to.be.called();
});

});

describe('#getFeatureById()', function() {
Expand Down

0 comments on commit aafe50c

Please sign in to comment.