I created an onChange feature event and each time I drag the feature over the map, it console.log its properties.
var newFeature = new ol.Feature({
geometry: new ol.geom.Point(e_coordinate),
property: 1
});
newFeature.setId(33);
source.addFeature(newFeature);
I change the property as follows
source.getFeatureById(33).values_.property=2
And if I console.log the property I get 2, which is correct
Finally I add the on change event on the feature
newFeature.on('change',
function () {
try {
console.log("on change props -->" + props);
} catch (error) {
alert('feature on change error 2\n' + error);
}
},
newFeature
);
The problem appears when I drag the feature over the map. It keeps logging the previous value (1) and not the latest one (2). Is there any way to reset the new property some how inside the on change event?
Am I missing something?
.values_
. Internal OL properties should never be modifed directly. The correct way is by using.set
method:source.getFeatureById(33).set('property', 2)
. Second, third parameternewFeature
in settingchange
event processing function has no meaning, method.on
accepts only two parameters. Third, what do you mean by "keeps logging the previous value"? What isprops
? Where is it defined? When does it change?