【发布时间】:2020-04-12 06:30:38
【问题描述】:
我们需要使用标记在地图上显示多个坐标。用户单击的标记必须被标记为活动的,并且必须为其他一些功能执行一些操作。
当我在标记的 onPress 方法中更新状态时,所有标记都会闪烁,可能是由于重新渲染。我也添加了唯一键,但它似乎不起作用。
我有一个名为 markers 的数组,用于在地图上呈现标记。
return markers.map(marker => (
<Marker
tracksViewChanges={false}
tracksInfoWindowChanges={false}
animationEnabled={false}
identifier={marker.id}
key={marker.id}
coordinate={{
latitude: marker.location.latitude,
longitude: marker.location.longitude,
}}
onPress={() => {
setActiveMarker(marker.id); // State update using hook
}}>
//Rendering the custom marker image here
{if(activeMarker === marker.id)
(<Icon
width={22}
height={32}
source={require('../../assets/images/marker.png')})
else
(<Icon
width={22}
height={32}
source={require('../../assets/images/activeMarker.png')})
}
/>
</Marker>
));
react-native-map 版本:0.27.1
【问题讨论】:
标签: react-native react-native-maps react-native-map-clustering