1

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.

7
  • Use styleMap rules example openlayers.org/dev/examples/select-feature-multilayer.html
    – Mapperz
    Commented May 1, 2013 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
    Commented May 1, 2013 at 17:00
  • select an object it changes colour indicating it is selected.
    – Mapperz
    Commented May 1, 2013 at 17:03
  • jsfiddle is ideal.
    – Mapperz
    Commented May 1, 2013 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
    Commented May 1, 2013 at 17:11

1 Answer 1

0

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.

1
  • 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
    Commented May 3, 2013 at 21:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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