OpenLayers getText() from style function

by jebbbbzzz   Last Updated July 11, 2019 19:22 PM

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'
        })
    });
});

console.log(iconFeature.getStyle().getText().getText());

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



Related Questions




Openlayer change:rotation not called

Updated September 05, 2017 21:22 PM


cannot append a featureCollection in typescript

Updated September 13, 2017 12:22 PM