[OpenLayers-Users] programmatically selecting a feature using a ModifyFeature control

Eric Lemoine eric.c2c at gmail.com
Sat Feb 28 09:22:18 EST 2009


Hi

Programmatically selecting a feature (whether it's for modification or
not) isn't really supported at this point. I agree that this is a
limitation.

However, you can probably work around this by calling the select
feature control's select() method. You can therefore try the
following:

modifyFeatureControl.selectControl.select(feature);

Although this may work, unselecting it by clicking on the feature may
not work, because the feature isn't selected from the feature
handler's viewpoint. To make it work try the following after calling
the select() method:

modifyFeatureControl.selectControl.handlers.feature.feature = feature.

Yes, somewhat hackish!

Hope this helps,

Eric

2009/2/27, Michael Anderson <mike at spatialit.com>:
> Hello,
>
> I'm trying to programmatically select a feature in a layer with a Modify
> feature control. It seems to be selecting, but the feature does not turn the
> selected color and display it's vertices. Here is the relevant code:
>
> First, I set up the ModifyFeature control when the page loads and set up a
> couple event listeners:
>
> var controls = {fieldModify: new
> OpenLayers.Control.ModifyFeature(farmFieldsLayer)}; // there are more
> controls in the real app
> farmFieldsLayer.events.register("beforefeaturemodified", null,
> onFieldBeforeModified);
> farmFieldsLayer.events.register("afterfeaturemodified", null,
> onFieldAfterModified);
>
> Then in another function I try to select a feature like this ('feature' is
> passed into the function):
> controls.fieldModify.selectFeature(feature);
>
> When I click on a feature, onFieldBeforeModified fires and the feature is
> highlighted with it's vertices displayed. Then when I click on another
> feature, onFieldAfterModified fires for the feature I clicked on previously,
> then onFieldBeforeModified fires for the new feature and it is highlighted.
>
> When I use .selectFeature() to select a feature, onFieldBeforeModified does
> not fire and the feature is not highlighted. When I call it again on another
> feature, onFieldAfterModified does fire. That's why I think it really is
> being selected even though I can't see it. What I want is selecting using
> .selectFeature() to work just like clicking on the feature.
>
> Am I doing something wrong, or shouldn't it work as I want it to.
> Thanks.
> Mike
>
>
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>

-- 
Envoyé avec mon mobile



More information about the Users mailing list