优化地图标记点处理逻辑,增加对标记点数组的有效性检查,确保渲染时数据的正确性,提升代码可维护性和用户体验。
This commit is contained in:
@@ -308,7 +308,7 @@ export const useAMapMarkers = ({
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!map) return;
|
||||
if (!map || !Array.isArray(markers)) return;
|
||||
|
||||
// 清理旧的标记点和聚合点
|
||||
if (clusterInstance.current) {
|
||||
@@ -319,10 +319,12 @@ export const useAMapMarkers = ({
|
||||
markersRef.current = [];
|
||||
|
||||
// 根据配置添加新的标记点
|
||||
if (showCluster) {
|
||||
handleCluster();
|
||||
} else {
|
||||
handleMarkers();
|
||||
if (markers.length > 0) {
|
||||
if (showCluster) {
|
||||
handleCluster();
|
||||
} else {
|
||||
handleMarkers();
|
||||
}
|
||||
}
|
||||
|
||||
return () => {
|
||||
|
||||
Reference in New Issue
Block a user