【发布时间】:2015-11-26 14:23:28
【问题描述】:
我在地图上显示了大约 100 000 个要素。在特定的缩放级别,我想在特征上添加标签。这是没有标签的样式:
style: function(feature, resolution) {
var style = [new ol.style.Style({
image: new ol.style.Icon({
src: myImg,
rotation: myRotation
})
})]};
我尝试创建一个函数来创建新样式以添加标签
labelStyleFunction: function(name){
return new ol.style.Style({
text: new ol.style.Text({
text: name,
font: ' 10px Arial',
fill: new ol.style.Fill({
color: 'black'
}),
offsetY: -10,
offsetX: 30
})
});
}
当我达到所需的特定级别时,我尝试了 layer.forEachFeature 和 layer.forEachFeatureInExtent
if(zoom >= 15 && status){
me.getData('clusters100').getSource().getSource().forEachFeatureInExtent(extent,function(feature){
feature.setStyle([
//me.getData('selectedStyle'),
me.labelStyleFunction(feature.get('name'))
]);
});
}
但是由于我猜有大量的功能,两者都让我的应用程序崩溃了...... 所以我想在标签上设置不透明度为 0,然后在缩放 15 处设置不透明度 1,但是:
- 有可能吗?
- 我怎样才能做到这一点?
【问题讨论】: