0

如下代码所示,我声明了变量AoC,我想给它赋值feature.get(environment.KEY_OF_MVT_FEATURE_1)。我面临的问题是该变量AoC未在函数范围内定义。VectorTileLayer 请让我知道如何AoCVectorTileLayer

代码

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
                  })
                })
        }
      });
4

1 回答 1

0

多种方式:

  1. 您可以创建一个angular service,在其中添加 AoC 并使用getter/setter. 或者
  2. 如果是它的AngularJs代码,那么您也可以将其添加到其中,$rootScope以便您可以在任何地方访问它。
于 2021-11-22T07:44:58.957 回答