添加边界线的styleFunction代码如下,完全没问题。
var styleFunction = function(feature, resolution) {
var name=feature.get('name');
var color='rgba(32, 48, 103, 0.3)';
var areaLineStyle = new ol.style.Style({
fill: new ol.style.Fill({ //矢量图层填充颜色,以及透明度
color: color,//feature.get('color')
}),
text:new ol.style.Text({
text:feature.get('name'),
font: '12px bold serif',
fill: new ol.style.Fill({
color: '#000'
}),
stroke: new ol.style.Stroke({
color: '#fff',
width: 2
})
}),
stroke: new ol.style.Stroke({ //边界样式
color: '#55DFF4',
//lineDash: [4],
width: 1.5
})
});
return areaLineStyle;
};
如下图所示,象山县有很多小岛,换句话说象山县这个区县是有很多多边形组成,所以没办法添加区县名。后来同事发现换成3.20的版本就可以了!