0

我需要一些关于地图方法的帮助。我得到了一个带有 geoJson 的部分 somes 数组,在每个数组中都有一些坐标。

例子:

    section:
[0] -> geoJson -> coordinates -> (a lot of coordinates with index)
[1] -> geoJson -> coordinates -> (a lot of coordinates with index)
[2] -> geoJson -> coordinates -> (a lot of coordinates with index)
[3]............
..........

我需要将所有这些组合成一个大数组(制作折线)。而且我对 map 方法很迷茫。

你有什么建议吗?我想使用地图功能。对不起我的英语(不是最好的:))

4

1 回答 1

0

假设您有以下部分数组:

section = [{
  coordinates: [{index: 1, x: 1, y: 1}]
}];

您可以通过使用map函数将其展平以获取坐标,然后使用concat函数将它们合并:

var merged = [].concat.apply([], section.map(x => x.geoJson.coordinates));
于 2019-09-30T19:48:21.073 回答