feature.setStyle is not a function
See original GitHub issueThe feature object retrieved by the map.forEachFeatureAtPixel seems not having the setStyle and get method
map.forEachFeatureAtPixel(e.pixel, function (feature) {
boundarySelected = feature;
feature.setStyle(highlightStyle);
return true;
});
if (boundarySelected) {
status.innerHTML = boundarySelected.get('name');
} else {
status.innerHTML = ' ';
}
The setStyle method and get(‘name’) method should exist like shown in the Hover Example and in the Feature documentation
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Cannot set a style for clicked features in vector layer
Solution 1: setStyle(null) OpenLayers will use the feature's style if it has one, and otherwise use the layer's style. So re-setting the ...
Read more >Openlayers - Unable to set the style of features
I have both tried feature.style = selected_polygon_style; and feature.setStyle(selected_polygon_style); . The first just doesn't change the ...
Read more >feature is not passed to style function when set via .setStyle()
setStyle (stylefunction) , it doesn't work. The problem is that the feature is not passed on to the style function, only the resolution....
Read more >OpenLayers v7.2.2 API - Class: Feature
setStyle (style) ... Set the style for the feature to override the layer style. This can be a single style object, an array...
Read more >Data Layer | Maps JavaScript API - Google Developers
The setStyle() method takes either a StyleOptions object literal, or a function that computes the style for each feature.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The vector tiles are only rendered once and then cached, so changing the style of the feature afterwards will not work, plus you have the problem that the geometry may be split between multiple tiles and setting the style on just one of those features will give unexpected results.
When you look in the example in my previous comment you will find there is a separate layer created for highlighting the active geometry that uses the same source but renders with
renderMode: 'vector'
, so no tile caching takes place. Using a style function and identifying the features by an id value will allow you to consistently style the entire geometry.Have a look at this example which is using a MVT source: https://openlayers.org/en/latest/examples/vector-tile-selection.html As written above the features of your tile source are not
ol/Feature
butol/render/Feature
which is a different class optimized for just rendering. They are not meant to be changed and there are a lot of functions not available compared to the normalol/Feature
objects.