Is there any chance to trigger a manual selection for an ol.feature in ol4? I saw the post here, but i have the same issue : the custom selection style is not applied. Any workarounds to get programmatically selection working as normal selection(within map)?
Asked
Active
Viewed 2,662 times
3
-
I suspect it's a bug in openlayers 4; I have spent several hours on the same issue (which I described here https://stackoverflow.com/questions/44264227/openlayers-4-11-no-style-applied-when-programatically-selecting-a-feature ), but still nothing to show for it. – Andrei Jun 07 '17 at 07:14
1 Answers
0
The problem I had to solve was - if an user clicked on a record in an external table, I had to display a popup for that feature. This is how I solved the problem.
- When drawing the map, I saved the layer source, the list of features in a global variable.
- When user clicks on the record in the table, I get the ID of the record.
- Get the feature - layerSource.getFeatureById (id)
- Draw the popup. (don't think you are interested in this step)
If you have to set the style, I think you will need to remove the old Vector layer from the map, and redraw the layer again. For the style, you will need to use a function that will return a different style for the selected feature.

sudhir shakya
- 827
- 1
- 9
- 21
-
1My problem is the how can i make the manual 'select' event to pass thorught the ol.interaction.select style. I have the feature, i have the interaction, i have the selection style function (given to the interaction) but i dont kow how to combine them to make programatically selection as it as from map. I have this code : `selectControl.getFeatures().push(featureToSelect); selectControl.dispatchEvent({ type: 'select', selected: [featureToSelect], deselected: [], });` but my selection style doesn't apply. It applies the default selection style. – N. Silviu Jun 07 '17 at 06:58