我有以下代码从.geojson
获取一个功能,并根据.geojson
文件中的值为多边形(在我的情况下为正方形)着色。
var myStyle = function(feature) {
var id = feature.get('featureName');
fill.setColor(id >= 0 && id <= 0.10 ? coloringFunction1(feature): id >= 0.10 && id <= 1.00 ? coloringFunction2(feature):coloringFunction3(feature));
return style;
};
我想显示id
值以及颜色,所以我做了如下所示:
var myStyle = function(feature) {
var id = feature.get('featureName');
fill.setColor(id >= 0 && id <= 0.10 ? coloringFunction1(feature): id >= 0.10 && id <= 1.00 ? coloringFunction2(feature):coloringFunction3(feature));
// To show the text
text: new ol.style.Text({
textAlign: "Center",
textBaseline: "Middle",
font: 'Normal 12px Arial',
text: id,
fill: new ol.style.Fill({
color: 'black'
}),
stroke: new ol.style.Stroke({
color: 'black',
width: 3
}),
})
return style;
};
然而,它根本不起作用。所以我的问题是:如何用它的颜色显示提取的特征值?