GeoJSON嵌套对象Mapbox GL JS

时间:2019-06-12 18:58:31

标签: mapbox-gl-js

所以我试图在这个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
            }
        },

我没有使文本字段正确显示value_max_local字段。

geojson位于此处:https://api.synopticdata.com/v2/stations/latest?&token=d8c6aee36a994f90857925cea26934be&within=60&output=geojson&bbox=-125,35,-110,50&vars=wind_gust&units=english&network=1,2,5,10,14,96,106,65&qc=on&hfmetars=0&minmax=1&minmaxtype=local

1 个答案:

答案 0 :(得分:0)

您的表达不太正确。您要提取的值位于数组中,因此您需要使用at expression来提取它;简化:

{
  ...
  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
    ]
  ]
]