openlayers 根據style設置顯示級別並在字體加背景框

根據圖層的屬性字段設置圖層顯示級別ci

Iconstyle:function(feature,resolution) {
var style = new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(241,242,236,0.8)',
}),
stroke : new ol.style.Stroke({
color : 'red',
width : 2
}),
image:new ol.style.Icon(({
offset: [0, 0],
opacity: 1.0,
rotateWithView: true,
rotation: 0.0,
scale: 1.0,
size: [60, 40],
anchor: [0.1, 0],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
src:feature.get("type")
})),
text: new ol.style.Text({
font:'12px sans-serif',
offsetX:0,
offsetY:-7,
placement:'point',
backgroundStroke:new ol.style.Stroke({
color:'rgba(255,51,0,1)',
width:1
}),
//標籤的背景填充
backgroundFill:new ol.style.Fill({
color:'rgba(255,51,0,1)'
}),
fill: new ol.style.Fill({
color: 'rgba(255,255,255,1)',

})
})
});

if(feature.get('name')){
style.getText().setText(resolution <0.00004291534423828125 ? feature.get('name') : '');  
}

return [style];
},get

相關文章
相關標籤/搜索