首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >GeoJSON嵌套对象Mapbox GL JS

GeoJSON嵌套对象Mapbox GL JS
EN

Stack Overflow用户
提问于 2019-06-13 02:58:32
回答 1查看 600关注 0票数 2

所以我尝试在这个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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-13 03:37:11

你的表情不太正确。要提取的值驻留在数组中,因此需要使用atexpression

来提取它;为了简化,请执行以下操作:

{
  ...
  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
    ]
  ]
]
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56568744

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档