我正在尝试将有条件样式的文本添加到我放置在地图上的矢量对象。
我有一个服务,创建看起来像这样的“风格”
let myStyle = new Style(
{
fill: new Fill({color: Shade}),
stroke: new Stroke({color: 'black',width:1}),
text: new Text({text:Label})
})
这有效,但我似乎无法弄清楚如何根据分辨率有条件地设置样式和显示/隐藏。
任何帮助是极大的赞赏!
您需要将其设为样式函数,例如:
let myStyle = function(feature, resolution) {
if (resolution < myCondition) {
return new Style(
{
fill: new Fill({color: Shade}),
stroke: new Stroke({color: 'black',width:1}),
text: new Text({text:Label})
});
}
}