[OpenLayers-Users] How to select feature from code?

Maciej Wisniowski pigletto at gmail.com
Thu Apr 8 08:16:23 EDT 2010


Hi!

Short question is:
 how to select specific feature on the map from code, while I have access to
desired feature object?


Longer version:
In my application I have a Vector layer that displays some features
(OpenLayers.Feature.Vector).
I also have SelectFeature there, defined as:

this.selctrl = new OpenLayers.Control.SelectFeature(this.layer)

Features loaded into Vector layer are also shown in a list placed below the
map.
So, for example, I have 3 features shown on my map, and 3 corresponding
links in a list.

What I want to do is to be able to click on the link and select
corresponding feature on the map.
So far, while clicking on link, I am able to:
- get corresponding Feature.Vector object
- pan the map to chosen feature
- partially (!) select this feature

I said partially because when I use something like:
    selctr.select(chosen_feature)   //selctrl is SelectFeature

it selects feature on the map (it has changed icon), but I'm not able to
unselect this feature by clicking outside it. I have to first click on this
"selected" feature, and then I can click outside to unselect it.

Seems to me that my code lacks something from Handler.Feature which is used
by SelectFeature. Should I use events to trigger click on the feature?
Any ideas?

-- 
Maciej Wiśniowski
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20100408/8695fbac/attachment.html


More information about the Users mailing list