I have a feature with a label set via feature.style.text. In my unit tests, I need to grab the value of the label.

Normally I would use getStyle().getText().getText(). However, in the example below I am using a style function, so calling getStyle() on my iconFeature returns a function and gives the error:

iconFeature.getStyle(...).getText is not a function

var iconFeature = new Feature({
    geometry: new Point([250, 1000])

iconFeature.setStyle((f, r) => {
    return new Style({
        text: new Text({
            offsetX: 100 * (0.04 / r),
            padding: [0, 0, 0, 1000],
            text: 'Icon Label Vaue'


Any thoughts on how to get the label text of my feature's style?

In case it matters - This is an Angular app using OL 5

  • 1
    iconFeature.getStyle()(iconFeature, map.getView().getResolution()).getText().getText() should work in that case – Mike Jul 11 at 19:43
  • Excellent! That worked. – jebbbbzzz Jul 11 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.