我现在设置了这个:
fully functional fiddle example,虽然我已经设法缩放到每个多边形特征,但我还想在每个…上显示集中文本标签…在get_fields方法中找到的field_title变量.我不知道如何做到这一点,所有我的谷歌搜索都提出了这篇文章:
http://openlayers.org/en/v3.3.0/examples/vector-labels.html我发现完全混乱,因为我对OL有点新!
解决方法
要向ol.Feature添加文本,您将在功能中存储描述,并将
set a style存储为
style function(将从功能中获取描述并显示):
@H_403_6@field_polygon.set('description',field_title);
field_polygon.setStyle(styleFunction);
function styleFunction() {
return [
new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(255,255,0.4)'
}),stroke: new ol.style.Stroke({
color: '#3399CC',width: 1.25
}),text: new ol.style.Text({
font: '12px Calibri,sans-serif',fill: new ol.style.Fill({ color: '#000' }),stroke: new ol.style.Stroke({
color: '#fff',width: 2
}),// get the text from the feature - `this` is ol.Feature
// and show only under certain resolution
text: map.getView().getZoom() > 12 ? this.get('description') : ''
})
})
];
}