From db5b5933b21b6b4d2ab23376a42d40c910b658ab Mon Sep 17 00:00:00 2001 From: LiuJiaNan <15703339975@163.com> Date: Thu, 11 Dec 2025 09:14:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96MapSelector?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Map/MapSelector.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/components/Map/MapSelector.js b/components/Map/MapSelector.js index 83c0615..2e21536 100644 --- a/components/Map/MapSelector.js +++ b/components/Map/MapSelector.js @@ -19,6 +19,7 @@ const MapSelector = (props) => { const mapContainerRef = useRef(null); const mapInstanceRef = useRef(null); + const local = useRef(null); const [loading, setLoading] = useState(false); const [currentLongitude, setCurrentLongitude] = useState(longitude || ""); const [currentLatitude, setCurrentLatitude] = useState(latitude || ""); @@ -86,10 +87,10 @@ const MapSelector = (props) => { // 搜索功能 const handleLocalSearch = () => { if (localSearch && mapInstanceRef.current) { - const local = new window.BMapGL.LocalSearch(mapInstanceRef.current, { + local.current = new window.BMapGL.LocalSearch(mapInstanceRef.current, { renderOptions: { map: mapInstanceRef.current }, }); - local.search(localSearch); + local.current.search(localSearch); } }; @@ -97,10 +98,7 @@ const MapSelector = (props) => { const handleLocalClear = () => { setLocalSearch(""); if (mapInstanceRef.current) { - const local = new window.BMapGL.LocalSearch(mapInstanceRef.current, { - renderOptions: { map: mapInstanceRef.current }, - }); - local.search(""); + local.current.search(""); } }; @@ -206,7 +204,7 @@ const MapSelector = (props) => { -