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


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

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];
},


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM