I need to select link using link properties, I am able to find the feature but not able to highlight programmatically. please help..
In openlayers 2 we have selectFeature but not sure what is in ol3
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this community@ahocevar's answer saved me hours but one thing is missing from the code is to add select interaction to map object:
var select = new ol.interaction.Select();
//make sure you add select interaction to map
map.addInteraction(select);
var features = select.getFeatures();
// now you have an ol.Collection of features that you can add features to
features.push(feature);
// now the pushed feature is highlighted
//to dehighlight, just simply remove the feature from select
features.remove(feature);
Programmatic feature selection works by manipulating the Select interaction's feature collection:
var select = new ol.interaction.Select();
var features = select.getFeatures();
// now you have an ol.Collection of features that you can add features to
features.push(feature);
// now the pushed feature is highlighted
The above snippet assumes that the feature you want to highlight is assigned to the feature
variable.