Fer*_*dao 2 javascript arrays reactjs
我正在尝试使用 .map() 映射嵌套数组,这样我就可以在地图中显示并精确定位所有伦敦地铁位置。
this.undergroundGeoJson = [
{
'type': 'FeatureCollection',
'crs': { 'type': 'name', 'properties': { 'name':
'urn:ogc:def:crs:OGC:1.3:CRS84' } },
'features': [
{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [-0.278126, 51.5025]
},
'properties': {
'name': 'Acton Town'
}
},
{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [-0.263033174, 51.50883531]
},
'properties': {
'name': 'Acton Central'
}
},
{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [-0.262879534, 51.50856013]
},
'properties': {
'name': 'Acton Central'
}
}
}
]
Run Code Online (Sandbox Code Playgroud)
我需要几何对象中的坐标数组元素。
这是我到目前为止的代码...
@computed
get undergroundLatLongs() {
return this.undergroundGeoJson.map((u) =>
[u.features.geometry.coordinates[0],
u.features.geometry.coordinates[1]]);
}
Run Code Online (Sandbox Code Playgroud)
这是错误日志...
Uncaught TypeError: Cannot read property 'coordinates' of undefined
Run Code Online (Sandbox Code Playgroud)
欢迎任何帮助。
features是一个数组,您需要使用它来访问它index
u.features[i].geometry.coordinates[0]
^^^
Run Code Online (Sandbox Code Playgroud)
u.features[i].geometry.coordinates[0]
^^^
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21678 次 |
| 最近记录: |