From 3be817bd5d796fdcc2fb7801d57de6d3d305bf52 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Wed, 23 Aug 2023 09:52:12 +0800 Subject: [PATCH] fix(Polyline): fix ignoring error when uninstall maps. (#326) --- .../hawk-eye-control/src/useHawkEyeControl.tsx | 15 +++++++-------- packages/info-window/src/useInfoWindow.tsx | 14 +++++++------- packages/polyline/src/usePolyline.tsx | 13 ++++++++----- website/src/components/SideMenu/index.tsx | 2 +- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/packages/hawk-eye-control/src/useHawkEyeControl.tsx b/packages/hawk-eye-control/src/useHawkEyeControl.tsx index 0612aac7e..117435b11 100644 --- a/packages/hawk-eye-control/src/useHawkEyeControl.tsx +++ b/packages/hawk-eye-control/src/useHawkEyeControl.tsx @@ -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 { diff --git a/packages/info-window/src/useInfoWindow.tsx b/packages/info-window/src/useInfoWindow.tsx index 909cbd26f..ea8f83c71 100644 --- a/packages/info-window/src/useInfoWindow.tsx +++ b/packages/info-window/src/useInfoWindow.tsx @@ -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) { diff --git a/packages/polyline/src/usePolyline.tsx b/packages/polyline/src/usePolyline.tsx index edd0378e3..ab39e926f 100644 --- a/packages/polyline/src/usePolyline.tsx +++ b/packages/polyline/src/usePolyline.tsx @@ -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); } }; diff --git a/website/src/components/SideMenu/index.tsx b/website/src/components/SideMenu/index.tsx index fcbe87db7..652b6ac6b 100644 --- a/website/src/components/SideMenu/index.tsx +++ b/website/src/components/SideMenu/index.tsx @@ -39,7 +39,7 @@ const Side = styled.div` color: #eaeaea; background-color: #3e3e3e; } - &:global(.active) { + &.active { text-decoration: underline; background: #333; color: #fff;