1

I want to change my text backcolor.

        new ol.style.Style({
        text: new ol.style.Text({
            text: marker_name,
            fill: new ol.style.Fill({
                color: '#fff'
            })
        })   
     })

"fill" property change text color.
I search from OpenLayers v4.0.1 ol.style.text but I did not find propery for this.


You think draw a shape under the text like this

 new ol.style.Style({
        image: new ol.style.RegularShape({
            fill: fill,
            //stroke: stroke,
            // offsetY: -25,
            points: 4,
            radius1: 30,
            radius2:10,
            angle: Math.PI / 4
        }),
        text: new ol.style.Text({
            text: marker_name,
            fill: new ol.style.Fill({
                color: '#fff'
            })
        })

But OpenLayers v4 can't draw rectange in style. For this issue you can look that.

1 Answer 1

1

I don't really understand why OL can't draw rectangle in style so, simply I tried to make rectangle behind text style like:

var style =  new ol.style.Style({
  image: new ol.style.RegularShape({
    fill: new ol.style.Fill({color: 'red'}),
    points: 4,
    radius: 15,
    angle: Math.PI / 4
  }),
  text: new ol.style.Text({
    text: 'abc',
    fill: new ol.style.Fill({
      color: '#fff'
    })
  })
});

codepen here
this example's from OL 'regular shape' example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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