我正在使用react-native-mapbox-gl。我有一个位置数组,我正在循环遍历以在地图上绘制标记。但是有些位置非常靠近彼此,几乎看不见。我想将所有相邻的位置聚集在一起,这样当我单击它时,它会展开并显示所有位于该聚类中的位置。
在mapbox中有< MapboxGL.ShapeSource />可用,但它需要一个url来加载经纬度。但是我有一个包含每个位置经纬度的数组。是否有其他方法可以在mapbox中创建位置聚类?
在mapbox中有< MapboxGL.ShapeSource />可用,但它需要一个url来加载经纬度。但是我有一个包含每个位置经纬度的数组。是否有其他方法可以在mapbox中创建位置聚类?
<Mapbox.MapView
styleURL={Mapbox.StyleURL.Dark}
zoomLevel={15}
centerCoordinate={[locations[0].longitude, locations[0].latitude]}
style={styles.container}
showUserLocation={true}>
{this.renderLocations(locations)}
</Mapbox.MapView>
渲染位置函数循环遍历位置数组并在地图上显示标记
renderLocations(locations) {
return locations.map((loc, locIndex) => {
return (
<Mapbox.PointAnnotation
key={`${locIndex}pointAnnotation`}
id={`${locIndex}pointAnnotation`}
coordinate={[loc.longitude, loc.latitude]}
title={loc.name}>
<Image source={require("../../../assets/images/marker.png")}/>
<Mapbox.Callout title={loc.name} />
</Mapbox.PointAnnotation>
);
});