1

I have a feature layer in my application.

    let layer = new OlLayerVector({
        source: vectorSource
    });

So I need to set a style for this layer. But style should write attribute value as text.

    let layer = new OlLayerVector({
        source: vectorSource
    });

    styles = new Style({
        image:  new Circle({
              radius: 5,
              fill: null,
               stroke: new Stroke({color: 'red', width: 1})
            }),
        text:  new Text({
            text: // this comes from attribute.
        })
    });

This text will come from attribute value. Can I use formatted style text like "${name}" ?

(If I use style function, this function called for every feature. For example if I have 1000 features, createStyleFunction called 1000 times.)

1

There is no other option than using a style/labeling function to label each feature individually.

Even if there would be a syntax as suggested by you, internally a function would be called for every single feature.

See https://openlayers.org/en/latest/examples/vector-labels.html for examples.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.