Friday, March 5, 2010

How to listen to a feature creation by an edit tool

Today Virginie BERRE of Magellium showed a nice way to catch a feature created with the editing tool in udig. Guess I have to post that here in order to remember it myself :)


map.getEditManager().addListener(new IEditManagerListener() {
public void changed(EditManagerEvent event) {
SimpleFeature feature= map.getEditManager().getEditFeature();
if(feature != null) {
FilterFactory factory = CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints());
Id uDigfilter = factory.id(Collections.singleton(feature.getIdentifier()));
try {
FeatureCollection collection = dodStore.getFeatures(uDigfilter);

// do something with it

} catch (IOException e) {
e.printStackTrace();
}
}

}

});