Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am able to identify the selected features on my map using the following line:

vector_layer.selectedFeatures

I would like to be able to deselect this feature using a standalone function (not an event-handler). I've tried using the functions unselect() and unselectAll() unsuccessfully and can't find any examples of this approach.

I am aware that clicking on the selected object can be used to unselect. In this case I want a programmatic solution.

share|improve this question
    
It's not quite what I am trying to do but unSelect issues are discussed here: github.com/openlayers/openlayers/pull/486 –  djq Nov 13 '12 at 18:22

3 Answers 3

up vote 8 down vote accepted

You can unselect features with unselect and unselectAll methods of SelectFeature control:

selectControl = new OpenLayers.Control.SelectFeature(vectorLayer);
...
map.addControls([selectControl]);
selectControl.activate();

// unselect any specific feature...
selectControl.unselect(vectorLayer.features[0]);
// ...or all features
selectControl.unselectAll();

If this doesn't work, there's probably bug in your code.

Here is fiddle: http://jsfiddle.net/dHxnh/1/

share|improve this answer

thanks for the suggestions. I have seen these and tried to adapt them for my grid layer. As far as I can tell, every example for selecting features involved creating the features first. I have not (yet) seen a working example where an existing layer is loaded and the user selects features from this layer.

I am starting to think that selectFeature only works for vectors that you create on the fly. I hope this is not true or else I am in trouble. ;)

share|improve this answer

Openlayers unselecting Objects - various methods

Use the shift key to select multiple features. Use the ctrl key to toggle selection on features one at a time. Note: the "clickout" option has no effect when "hover" is selected

http://openlayers.org/dev/examples/select-feature.html

click out to unselect features

share|improve this answer
    
Sorry, should have added the word programmatic. I want to unselect using a function, not a click. –  djq Nov 13 '12 at 18:38

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.