[OpenLayers-Users] programmatically selecting a feature using a
ModifyFeature control
Michael Anderson
mike at spatialit.com
Fri Feb 27 14:40:02 EST 2009
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
More information about the Users
mailing list