I have a ol.StyleFunction
set on a layer.
function style(feature: ol.Feature, resolution: number): ol.style.Style {
return ol.style.Style({
// stuff from the feature properties
});
}
Not all of the features contain their own styling information. In this case, i'd like to fall back to the default style.
function style(feature: ol.Feature, resolution: number): ol.style.Style {
if (!hasOwnStyle(feature)) {
// defaultStyle is private :(
return ol.style.Style.defaultStyle();
}
return ol.style.Style({
// stuff from the feature properties
});
}
Is there a way to access the default style?
return feature.getStyle();
?????? It should be assigned if not provided. – Hecatefeature.getStyle()
is oftennull
, so it is better to usecreateDefaultStyles(feature, resolution)
. See my answer below. – Erinnerinna