From 59df68fe68e0380537cbfddf0540bebc74192927 Mon Sep 17 00:00:00 2001 From: Antoine Abt Date: Wed, 18 Dec 2013 13:59:57 +0100 Subject: [PATCH] Update property change listener --- src/ol/feature.js | 6 ++++++ test/spec/ol/feature.test.js | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/ol/feature.js b/src/ol/feature.js index 90c5555407..0193470d28 100644 --- a/src/ol/feature.js +++ b/src/ol/feature.js @@ -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_(); }; diff --git a/test/spec/ol/feature.test.js b/test/spec/ol/feature.test.js index 7f89004ecd..d8df678645 100644 --- a/test/spec/ol/feature.test.js +++ b/test/spec/ol/feature.test.js @@ -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]); }); });