如下代码所示,我声明了变量AoC
,我想给它赋值feature.get(environment.KEY_OF_MVT_FEATURE_1)
。我面临的问题是该变量AoC
未在函数范围内定义。VectorTileLayer
请让我知道如何AoC
在VectorTileLayer
代码:
AoC //declaration
public visualisePolygonsAsMVTTilesOnMapWithColorsForAverageHeightsForZone(zoneToken){
return new VectorTileLayer({
source: new VectorTileSource({
format: new MVT(),
url: environment.LocalHostForVectorTileSourceAsMVTTileForZXYWS + zoneToken + "/{z}/{x}/{y}",
}),
opacity: .4,
style: function (feature){
console.log("MVTTileAsFeature:",feature)
this.test = feature
let fillColor
let strokeColor
let text = ""
this.AoC = feature.get(environment.KEY_OF_MVT_FEATURE_1)//<===============
if (feature.get(environment.KEY_OF_MVT_FEATURE_IS_TREATMENT) == true) {
if (feature.get(environment.KEY_OF_MVT_FEATURE_1) >= 0 && feature.get(environment.KEY_OF_MVT_FEATURE_1) <= 12.5){
text = feature.get(environment.KEY_OF_MVT_FEATURE_1) + "%"
fillColor = '#ff0000'
strokeColor = '#000000'
} else if (feature.get(environment.KEY_OF_MVT_FEATURE_1) > 12.5 && feature.get(environment.KEY_OF_MVT_FEATURE_1) <= 15) {
text = feature.get(environment.KEY_OF_MVT_FEATURE_1) + "%"
fillColor = '#fd4900'
strokeColor = '#000000'
} else if (feature.get(environment.KEY_OF_MVT_FEATURE_1) > 15 && feature.get(environment.KEY_OF_MVT_FEATURE_1) <= 27.5) {
text = feature.get(environment.KEY_OF_MVT_FEATURE_1) + "%"
fillColor = '#f66d00'
strokeColor = '#000000'
} else if (feature.get(environment.KEY_OF_MVT_FEATURE_1) > 27.5 && feature.get(environment.KEY_OF_MVT_FEATURE_1) <= 40) {
text = feature.get(environment.KEY_OF_MVT_FEATURE_1) + "%"
fillColor = '#e98b00'
strokeColor = '#000000'
}
}
return new Style({
fill: new Fill({
color: fillColor
}),
stroke: new Stroke({
color: strokeColor,
lineDash: [1],
width:1,
}),
text: new Text({
font: 'Normal 9px Arial',
text: ''+text,
fill: new Fill({
color: '#000000'
}),
stroke: new Stroke({
color: '#000000',
width: 0
}),
// offsetX: -45,
// offsetY: 0,
// rotation: 0
})
})
}
});