[OpenLayers-Users] Different types of polygons?

Jeff Dege jeff.dege at korterra.com
Tue Apr 6 12:55:57 EDT 2010


You've given me two ideas:

1. In the Vector layer's featureadded event handler, check which control is active.
2. Apply two different feateradded event handlers to the two different DrawFeature controls.

Either should work.  Depending on how time is left in the schedule after I get the rest of the system working, I may revisit my derived class solution.

Thanks.

From: Pierre Giraud [mailto:pierre.giraud at camptocamp.com]
Sent: Tuesday, April 06, 2010 9:36 AM
To: Jeff Dege
Cc: users at openlayers.org
Subject: Re: [OpenLayers-Users] Different types of polygons?

Relying on events is often a good solution. First because you don't have to extend or create your own classes.

I think I can still be possible while listening on "featureadded" on the layer and check which one of your draw feature controls is currently activated.
But perhaps it would be quicker to listen directly on each draw feature control events. Reading the documentation [1], it seems like the DrawFeature control also exposes a "featureaded" event.
In the callback, it should then be easy to add an attribute like you already did, then redraw the layer.

Does it help you ?

[1] http://dev.openlayers.org/docs/files/OpenLayers/Control/DrawFeature-js.html#OpenLayers.Control.DrawFeature.EVENT_TYPES
On Tue, Apr 6, 2010 at 4:25 PM, Jeff Dege <jeff.dege at korterra.com<mailto:jeff.dege at korterra.com>> wrote:
Once I have features with different attributes, the mechanisms you describe would work, but I don't have any attributes in my features to distinguish them by.

The features are being created by the DrawFeature control.  And it doesn't add any attributes to the features it creates. My problem is how to have two different instances of the DrawFeature control add different attributes to the features they create.

Currently, I've created my own control that adds an attribute to the feature, based on an option passed when the control was created, and this is working. But it seems a bit kludgy, and is likely to break if a future version of OpenLayers makes changes to how DrawFeature.drawFeature() works.  So I was wondering if there was a better way to do it.

From: Pierre Giraud [mailto:pierre.giraud at camptocamp.com<mailto:pierre.giraud at camptocamp.com>]
Sent: Tuesday, April 06, 2010 2:46 AM
To: Jeff Dege
Cc: users at openlayers.org<mailto:users at openlayers.org>
Subject: Re: [OpenLayers-Users] Different types of polygons?

You can add a listener on the "featureadded" event of your vector layer. In this listener callback function, you should be able, for example, to set a specific value for an attribute of the added feature. Then using a StyleMap on your layer you should be able to draw the given feature with a specific color depending on the attribute value.

I hope this helps.

Pierre
On Mon, Apr 5, 2010 at 11:26 PM, Jeff Dege <jeff.dege at korterra.com<mailto:jeff.dege at korterra.com>> wrote:
I find myself needing to draw two different kinds of polygons on a Vector layer.  First, they need to have different colors, and second, they need to be processed differently when they are complete.

I'm currently working on the first problem, and am playing around with two DrawFeature controls.  Right now, they behave the same.  I'm trying to find a way to hook into them, in some way, so I can modify the features they create.

Any ideas?


_______________________________________________
Users mailing list
Users at openlayers.org<mailto:Users at openlayers.org>
http://openlayers.org/mailman/listinfo/users



--
Pierre GIRAUD
Géomaticien, Analyste

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 93
Mail : pierre.giraud at camptocamp.com<mailto:pierre.giraud at camptocamp.com>
http://www.camptocamp.com

_______________________________________________
Users mailing list
Users at openlayers.org<mailto:Users at openlayers.org>
http://openlayers.org/mailman/listinfo/users



--
Pierre GIRAUD
Géomaticien, Analyste

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 93
Mail : pierre.giraud at camptocamp.com<mailto:pierre.giraud at camptocamp.com>
http://www.camptocamp.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20100406/e74c6108/attachment.html


More information about the Users mailing list