[OpenLayers-Dev] vector drawFeature bug or by design?

Andreas Hocevar ahocevar at opengeo.org
Wed Jun 17 10:48:13 EDT 2009

Hi Paul,

On Wed, Jun 17, 2009 at 4:33 PM, Paul Spencer<pspencer at dmsolutions.ca> wrote:
> I have a question about Layer.Vector.drawFeature when passing a
> style ...
> I used this method to update the label of a point with an existing
> style (set directly on the feature) as the measure tool moved by
> calling this.handler.layer.drawFeature(text, {label: newDistance})
> which worked perfectly until the user zoomed using the mouse wheel
> while measuring.  I've since changed this to set text.style.label =
> newDistance; this.handler.layer.drawFeature(text); which works fine.
> But this led me to question whether this is by design or a bug.

This is by design. Styles passed with drawFeature are independent of
the feature's style and are lost with subsequent calls of drawFeature,
which happen on zoomend.

> The relevant docs are:
>      * This function is not designed to be used when adding features to
>      * the layer (use addFeatures instead). It is meant to be used when
>      * the style of a feature has changed, or in some other way needs

As it says: when the style *of a feature* has changed. Passing a style
to drawFeature does not change the feature's style. You do it right in
your working version, and you did not do it in your first attempt.

> I think if it is design that the feature's style is not updated with
> the passed in style then the docs should be updated to indicate this.

On the other hand, the docs do not say that the feature's style is
updated with the passed style... Anyway, please add some clarification
if you see the need. As a non-functional change, this can go in
without ticket and review.


Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.

More information about the Dev mailing list