Unexpected behaviour in v6.0.1 - Feature.getStyle()
See original GitHub issueDescribe the bug In version 5.3.0 Feature.getStyle() returned an object, in version 6.0.1 it’s now returning a function.
To Reproduce Steps to reproduce the behavior:
- Create a Feature and render it on the map.
- Get the feature using VectorSource.getFeatureById().
- Try to extract the style from the feature using Feature.getStyle().
Expected behavior Previously it returned an object upon which I could call setImage() for instance.
More information
After debugging some more it appeares it returnes a function that is stored in the variable style_ on the feature object.
This function seams to be a static function that expects a feature as it’s parameter.
When using that function and passing on the feature as a parameter i get an array of style objects back. In my case it only has one style on position 0.
Something like this:
const style = feature.getStyle()(feature)[0]
Or more readable:
const getStyleFunction = feature.getStyle();
const stylesArray = getStyleFunction(feature);
const style = styleArray[0];
Instead of previously:
const style = feature.getStyle()
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (10 by maintainers)
Top GitHub Comments
ol/interaction/Select does test
if (this.style_) {
but it is meaningless because the initialisationthis.style_ = options.style ? options.style : getDefaultStyleFunction();
should be
this.style_ = options.style !== undefined ? options.style : getDefaultStyleFunction();
null
orfalse
could then be specified to prevent overriding the styleThe above would still need to be documented. Previously a Select style only overrode a layer style. If the feature already had a style that had precedence. Backward compatibility could be maintained if the Select only sets its style on a selected feature if the feature has no style, and resets it to undefined when a feature is deselected.