reactjs - 将包含数组的数组中的数据映射到组件中
问题描述
我有一些来自 api 的大数据 - https://onet.sci.gsfc.nasa.gov/api/v2.1/events
我想将坐标映射到 React Leaflet 中的一个组件中,该组件在地图上显示一个标记。
<Marker position={[LAT, LON]} />
下面数据中的每个坐标都有一个坐标——coordinates: [LAT, LON]
我的数据
[
{
id: 'EONET_5165',
title: 'Tropical Cyclone Gati',
geometries: [
{
date: '2020-11-21T18:00:00Z',
type: 'Point',
coordinates: [55.5, 10.8],
},
{
date: '2020-11-22T00:00:00Z',
type: 'Point',
coordinates: [53.8, 10.6],
},
{
date: '2020-11-22T06:00:00Z',
type: 'Point',
coordinates: [52.5, 10.3],
},
{
date: '2020-11-22T12:00:00Z',
type: 'Point',
coordinates: [51.5, 10.4],
},
],
},
{
id: 'EONET_4445',
title: 'Tropical Cyclone Susan',
geometries: [
{
date: '2020-11-21T18:00:00Z',
type: 'Point',
coordinates: [55.5, 10.8],
},
{
date: '2020-11-22T00:00:00Z',
type: 'Point',
coordinates: [53.8, 10.6],
},
}
]
我需要映射每个事件并为每个坐标显示一个标记
这是我尝试过的最新方法。它给出了一个错误,因为位置为空。
{events.map((evt) => (
<Marker
position={[
evt.geometries.map((g) => g.coordinates[1]),
evt.geometries.map((g) => g.coordinates[0]),
]}
/>
))}
我也尝试将每个坐标数组映射到,但这导致我将所有 lat 和 long 传递到参数中。
我为这个模糊的问题道歉。
解决方案
可以尝试类似的东西
{events.map((evt) => (
evt.geometries.map(geo=>(
<Marker
position={[
geo.coordinates[1],
geo.coordinates[0]
]}
/>
))
))}
推荐阅读
- gradle - 在 Kotlin Gradle 项目中将外部配置文件放在哪里?
- angular - 是否应该触发所有减速器的 ngrx 操作
- scala - 在 Spark (Scala) 中填写给定日期间隔内的缺失周数
- amazon-web-services - AWS s3 同步重新复制自上次运行以来未更改的文件
- google-sheets - 在行和列范围内计算“单词”。仅当该行中写有另一个特定的“单词”时
- python - 将 python 列表传递给“c”DLL 函数,该函数使用 ctypes 返回数组数据
- ios - Fabric 在 [Fabric isCrashlyticsCollectionEnabled] 上的最新更新 (1.9.0) 后崩溃
- sql-server - SQL AFTER INSERT,UPDATE 如果更新特定列,则触发条件
- java - Kafka FlapmapValues 在传递json数组对象时会不会将记录拆分成多条记录?
- angular - 当我启用另一个开关时如何禁用自动开关以及如何修复错误错误:无效的布尔值: