Skip to content

Commit

Permalink
fix(Polyline): fix ignoring error when uninstall maps. (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Aug 23, 2023
1 parent acb2c73 commit 3be817b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
15 changes: 7 additions & 8 deletions packages/hawk-eye-control/src/useHawkEyeControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ export function useHawkEyeControl(props = {} as UseHawkEyeControl) {
map.addControl(instance);
setHawkEyeControl(instance);
});

return () => {
if (instance && map) {
map && map.removeControl(instance);
setHawkEyeControl(undefined);
}
};
}
}, [map]);
return () => {
if (hawkEyeControl && map) {
map && map.removeControl(hawkEyeControl);
setHawkEyeControl(undefined);
}
};
}, [map, hawkEyeControl]);

useVisiable(hawkEyeControl! as any, visiable);
return {
Expand Down
14 changes: 7 additions & 7 deletions packages/info-window/src/useInfoWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ export const useInfoWindow = (props = {} as UseInfoWindow) => {
if (isOpen) {
instance.open(map, position || positionCenter);
}
return () => {
if (instance) {
map && map.remove(instance);
setInfoWindow(undefined);
}
};
}
}, [map]);
return () => {
if (infoWindow) {
map && map.remove(infoWindow);
setInfoWindow(undefined);
}
};
}, [map, infoWindow]);

useEffect(() => {
if (infoWindow) {
Expand Down
13 changes: 8 additions & 5 deletions packages/polyline/src/usePolyline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ export function usePolyline(props = {} as UsePolyline) {
}
return () => {
if (polyline) {
if (AMap.v) {
try {
map && map.remove(polyline);
} else {
// 暂不使用这个 API,这个不兼容 v1.4.xx,改用 map.remove API
map && map.removeLayer(polyline);
}
} catch (e) {}
// if (AMap.v) {
// map && map.remove(polyline);
// } else {
// // 暂不使用这个 API,这个不兼容 v1.4.xx,改用 map.remove API
// map && map.removeLayer(polyline);
// }
setPolyline(undefined);
}
};
Expand Down
2 changes: 1 addition & 1 deletion website/src/components/SideMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const Side = styled.div`
color: #eaeaea;
background-color: #3e3e3e;
}
&:global(.active) {
&.active {
text-decoration: underline;
background: #333;
color: #fff;
Expand Down

1 comment on commit 3be817b

@vercel
Copy link

@vercel vercel bot commented on 3be817b Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

react-amap – ./

react-amap-git-master-398188662.vercel.app
react-amap-one.vercel.app
react-amap-398188662.vercel.app

Please sign in to comment.