Update property change listener

This commit is contained in:
Antoine Abt
2013-12-18 13:59:57 +01:00
parent 97ed71dfe2
commit 59df68fe68
2 changed files with 24 additions and 0 deletions

View File

@@ -209,6 +209,12 @@ ol.Feature.prototype.setId = function(id) {
* @param {string} name Geometry property name.
*/
ol.Feature.prototype.setGeometryName = function(name) {
goog.events.unlisten(
this, ol.Object.getChangeEventType(this.geometryName_),
this.handleGeometryChanged_, false, this);
this.geometryName_ = name;
goog.events.listen(
this, ol.Object.getChangeEventType(this.geometryName_),
this.handleGeometryChanged_, false, this);
this.handleGeometryChanged_();
};

View File

@@ -185,6 +185,24 @@ describe('ol.Feature', function() {
expect(feature.getGeometry()).to.be(point);
feature.setGeometryName('altGeometry');
expect(feature.getGeometry()).to.be(point2);
feature.on('change', function() {
expect.fail();
});
point.setCoordinates([0, 2]);
});
it('changes property listener', function(done) {
var feature = new ol.Feature();
feature.setGeometry(point);
var point2 = new ol.geom.Point([1, 2]);
feature.set('altGeometry', point2);
feature.setGeometryName('altGeometry');
feature.on('change', function() {
done();
});
point2.setCoordinates([0, 2]);
});
});