Using OpenLayers 6.13.0, I'm attempting to get my lines layer to have labels that follow the line (ie, parallel to the line, and bending with the line) as per the example at: https://openlayers.org/en/latest/examples/street-labels.html
In order to achieve this, I'm using the ol.style.Text
property placement
set to line
(default is point
). As required by line
placement, the geometry type specified in the geoJSON for this layer is MultiLineString
.
If I specify the placement
as 'point'
, then the labels appear fine, but are simply straight, horizontal and on the centre-point of the line. If I specify the placement
as 'line'
, then I get no label at all. No errors are logged in the javascript console.
My style is defined as per below.
What am I doing wrong here?
var layerStyles = function (feature, resolution) {
return [
new ol.style.Style({stroke: new ol.style.Stroke({color: '#FFFFFF', width: 4.000000})}),
new ol.style.Style({stroke: new ol.style.Stroke({color: '#FF0000', width: 2.000000})}),
new ol.style.Style({text: new ol.style.Text({
text: feature.get('label')['0'],
font: ' 10pt sans-serif',
fill: new ol.style.Fill({color: '#ff0000ff'}),
stroke: new ol.style.Stroke({color: '#ffffffff', width: 3.0}),
placement: 'line'
})})
]
};
overflow: true
or increasemaxAngle
beyond the default - see openlayers.org/en/latest/examples/vector-labels.html