GeoJSON嵌套对象Mapbox GL JS

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (115)

所以我试图在这个GEOJSON文件中绘制value_max_local。我无法进入文本字段。

我试过minmax.wind_gust_value_1.value_max_local[0],以下表达式的建议......

'text-field': ['number-format', ['get', 'minmax', ['get', 'wind_gust_value_1', ['get', 'value_max_local[0]']]], {'min-fraction-digits':0, 'max-fraction-digits':0.1}],

这是代码...带有一块geojson文件。

map.addLayer({
  'id': 'MxGusts',
  'type': 'symbol',
  'source':'Gusts',
  'layout': {
    'text-field': ['number-format', ['get', 'minmax', ['get', 'wind_gust_value_1', ['get', 'value_max_local[0]']]], {'min-fraction-digits':0, 'max-fraction-digits':0.1}],
    'text-font': [
      "DIN Offc Pro Medium",
      "Arial Unicode MS Bold"
    ],
    'text-size': 13,
  },
  'paint':{
    'text-halo-color':'rgba(255,255,255,0.75)',
    'text-halo-width':1.5,
  },
},firstSymbolId);



"geometry": {
                "type": "Point",
                "coordinates": [
                    -111.38222,
                    47.47333
                ]
            },
            "type": "Feature",
            "properties": {
                "status": "ACTIVE",
                "mnet_id": "1",
                "date_time": "2019-06-12T16:50:00Z",
                "elevation": "3675",
                "name": "Great Falls, Great Falls International Airport",
                "station_info": "http://mesowest.utah.edu/cgi-bin/droman/station_total.cgi?stn=KGTF",
                "restricted_data": "0",
                "stid": "KGTF",
                "elev_dem": "3654.9",
                "longitude": "-111.38222",
                "minmax": {
                    "wind_gust_value_1": {
                        "datetime_min_local": [
                            "2019-06-12T09:50:00"
                        ],
                        "value_min_local": [
                            13
                        ],
                        "dates": [
                            "2019-06-12"
                        ],
                        "value_max_local": [
                            13
                        ],
                        "datetime_max_local": [
                            "2019-06-12T09:50:00"
                        ]
                    }
                },
                "state": "MT",
                "more_observations": "http://mesowest.utah.edu/cgi-bin/droman/meso_base_dyn.cgi?stn=KGTF",
                "latitude": "47.47333",
                "timezone": "America/Denver",
                "id": "205",
                "wind_gust": 13
            }
        },

我没有让text-field正确显示value_max_local字段。

geojson位于:https://api.synopticdata.com/v2/stations/latest ?& token = d8c6aee36a994f90857925cea26934be&withinin = 60&output = geojson&bbox = 1253,35,-110,50&vars = wind_gust&units = english&network = 1,2,5 , 10,14,96,106,65&QC = ON&hfmetars = 0&极大极小= 1&minmaxtype =本地

提问于
用户回答回答于

你的表达不太正确。要提取的值驻留在数组中,因此需要使用at表达式来提取它; 简化:

{
  ...
  properties: {
    foo: {
      bar: [
        10 <-- what you want to access
      ]
    }
  }
}

表达式应如下所示:

[
  'at',
  0, // <-- returns element at index "0" from array "bar"
  [
    'get', 'bar', // <-- returns the array "bar"
    [
      'get', 'foo' // <-- returns the object "foo" from properties
    ]
  ]
]

扫码关注云+社区

领取腾讯云代金券