折线setMap(null) 和 setVisible(false) 不起作用谷歌地图反应

问题描述

您好,我正在尝试删除或隐藏上一条折线。然而,它没有。这是我的代码:


import React,{ useEffect,useState } from 'react';
import decodePolyline from 'decode-google-map-polyline';

const Polyline = ({ line,map,maps}) => {
const [deliveryPolyLine,setDeliveryPolyLine] = useState([]);

  let initialPolyLine = new maps.Polyline({
    path: decodePolyline(line),geodesic: true,strokeColor: '#00a1e1',strokeOpacity: 1.0,strokeWeight: 4
  });

  function renderPolylines(){
      initialPolyLine.setMap(map)
}

  useEffect(() => {
    setDeliveryPolyLine([...deliveryPolyLine,initialPolyLine])
  },[line]);

  useEffect(() => {
    for(var i = 0; i < deliveryPolyLine.length - 1; i++){
      console.log(deliveryPolyLine[i])
      deliveryPolyLine[i].setMap(null);
      // deliveryPolyLine[i] = null;
      deliveryPolyLine[i].setVisible(false);
    }
  },[line,deliveryPolyLine])

    return (
        <div>
        {renderPolylines()}
        </div>
    )
};

export default Polyline;;

我已成功设置折线的 map property to nullvisible property to false,但它仍在我的地图上。我究竟做错了什么?我对此很陌生。非常感谢帮助

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...