[OpenLayers-Dev] DrawFeature.featureAdded() - called in wrong place?

Jeff Dege jdege at korterra.com
Fri Apr 6 13:51:08 EDT 2007

> From: dev-bounces at openlayers.org 
> [mailto:dev-bounces at openlayers.org] On Behalf Of Tim Schaub
> Sent: Friday, April 06, 2007 11:04 AM
> You have 3 or 4 dozen options here.

Of course I do.

> So, while the DrawFeature control is not really meant to be used to do

> anything custom with features *before* they are added to a layer (more

> on this below) - you could customize this control to do what you want.
> If you construct your DrawFeature control with something like:
>      var options = {drawFeature: myDrawFeature};
>      var control = new OpenLayers.Control.DrawFeature(
>                            layer, OpenLayers.Handler.Polygon, 
> options);
> and myDrawFeature is something like:
>      function myDrawFeature(geometry) {
>          var feature = new OpenLayers.Feature.Vector(geometry);
>          // do something with feature before it is added to the layer
>          // at this point you know which control did the drawing
>          layer.addFeatures([feature]);
>          control.featureAdded(feature);
>      }
> All that said, I wonder if you really need to be using the DrawFeature

> control at all.  If you want users to digitize polygons, and then you 
> want to do a lot of custom stuff *before* adding the features to a 
> layer, then it sounds to me like you should make a custom control that

> uses the polygon handler.

Deriving my own custom control might be cleaner, but what you've
described above is working, so I expect I'll stick with it until I have
reason to revisit this section of code.


More information about the Dev mailing list