错误信息:

Uncaught (in promise) TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.

    at rd.Qc (eval at O_ (getscript?v=3.0&ak=oGYnEyKxK3jkCYQrztGMo9ZskmgeAlae&services=&t=20230614151358:1:81519), <anonymous>:1:8768)

    at rd.initialize (eval at O_ (getscript?v=3.0&ak=oGYnEyKxK3jkCYQrztGMo9ZskmgeAlae&services=&t=20230614151358:1:81519), <anonymous>:1:258)

    at mb.Vc (eval at O_ (getscript?v=3.0&ak=oGYnEyKxK3jkCYQrztGMo9ZskmgeAlae&services=&t=20230614151358:1:81519), <anonymous>:1:16606)

    at Pa.Vc (getscript?v=3.0&ak=oGYnEyKxK3jkCYQrztGMo9ZskmgeAlae&services=&t=20230614151358:1:129982)

    at openWindow (useMap.ts:115:7)

改之前代码:


  const initInfoWindow = async (point: Point) => {
    const opts = {
      width: 400,     // 信息窗口宽度
      height: 0,     // 信息窗口高度
      offset: {
        width: 0,
        height: -30
      },
      title: "", // 信息窗口标题
      enableMessage: true,//设置允许信息窗发送短息
      message: ""
    }
   // 关闭弹窗之后,再次打开此处报错
    const infoWindow = new BMap.InfoWindow(document.getElementById('infoWindow'), opts);  
    infoWindow.setTitle(document.getElementById('infotitle'))
    return infoWindow
  }

改之后代码:

let infoContent = null
  let infoTitle = null
  const initInfoWindow = async (point: Point) => {
    const opts = {
      width: 400,     // 信息窗口宽度
      height: 0,     // 信息窗口高度
      offset: {
        width: 0,
        height: -30
      },
      title: "", // 信息窗口标题
      enableMessage: true,//设置允许信息窗发送短息
      message: ""
    }
    // 2023-07-11 new BMap.Infowindow()第一个参数是 HTML 时,当关闭infoWindow 再次进入的时候,控制台报错。因为关闭infowindow 时动态的infoWindow 和 infotitle 已经删除,在通过getElementById 时获取到的是 null。 此处尝试多种方法都不起效,最后用了一个笨方法,用2个变量保存获取到的 Html 元素。
    let cont = null
    let title = null
    if (document.getElementById('infoWindow')) {
      infoContent = document.getElementById('infoWindow')
      infoTitle = document.getElementById('infotitle')
    }
    cont = infoContent
    title = infoTitle
    const infoWindow = new BMap.InfoWindow(cont, opts);  // 创建信息窗口对象 
    infoWindow.setTitle(title)
    return infoWindow
  }

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐