Tell me more ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

In the OpenLayers SelectFeature, how can I manually set a feature as selected/unselected and have it reflect the appropriate color?

For instance, when my application loads, it sends back the existing select state which I want to set on the polygons. Thanks!

share|improve this question
Use styleMap rules example openlayers.org/dev/examples/select-feature-multilayer.html – Mapperz May 1 at 16:42
I'm unclear from the example on how to manually select a feature. Are you referring to using renderIntent to show the right colors initially? Will that also show the element as selected? I'm going to work on an example on JSFiddle and share it in a bit. – Nick Karnik May 1 at 17:00
select an object it changes colour indicating it is selected. – Mapperz May 1 at 17:03
jsfiddle is ideal. – Mapperz May 1 at 17:04
I get that the color changes when you click and select the box. Question is how to manually trigger that. Almost done with the fiddle. – Nick Karnik May 1 at 17:11
show 2 more comments

1 Answer

I noticed that there are two methods which can be used to select a feature manually.

  1. Method select(feature) in the SelectFeatures control.
  2. Method clickFeature(feature) in the SelectFeatures control.

Here's a fiddle demonstrating that feature in case anyone else is interested.

At one point, I wasn't able to get select to work. Setting selectFeature.allowSelection to true let me select it, but later I noticed that it worked without it so I'm not sure when setting that to true is required. If you run into any issues, you might want to try playing with that attribute. Looking into the source further should allow us to understand the purpose of that variable.

share|improve this answer
Not allowed to post more than two links under 10 reputation so I had to remove references to select and clickFeature. However, they're available on the SelectFeatures control page link that I've included. – Nick Karnik May 3 at 21:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.