marsgis / mars3d

【Mars3D平台 】主仓库,包含所有开源仓库清单导航
http://mars3d.cn
Apache License 2.0
982 stars 137 forks source link

new mars3d.graphic.Popup(options) 中的 timeRender 设置无效 #11

Closed yucheng1207 closed 2 years ago

yucheng1207 commented 2 years ago

使用new mars3d.graphic.Popup(options)创建一个graphic,其中options中的timeRender设置为true,html设置为回调函数,html并不会实时更新(html回调函数只会触发一次) 如下:

...
const showHtml = (event) => {
            console.log('e', event)
            return " 我是layer上绑定的Popup" + new Date().toLocaleTimeString()
}
const graphicPopup = new mars3d.graphic.Popup({
            className: 'mesh_popup',
            id,
            name: EntityType.POPUP,
            position: graphic.center,
            style: {
                html: showHtml,
                closeButton: false,
                horizontalOrigin: mars3d.Cesium.HorizontalOrigin.CENTER,
                verticalOrigin: mars3d.Cesium.VerticalOrigin.BOTTOM,
                offsetY: 4,
                timeRender: true
            } as any
        })
graphicLayer.addGraphic(graphicPopup)
...

但是使用bindPopup功能是没有问题的

muyao1987 commented 2 years ago

参考这个示例内代码编写 : http://mars3d.cn/editor.html?id=control/inside/popup

  // 刷新局部DOM,不影响popup面板的其他控件操作
  graphic.on(mars3d.EventType.postRender, function (event) {
    const container = event.container // popup对应的DOM
    const tdTime = container.querySelector("#tdTime")
    if (tdTime) {
      const date = mars3d.Util.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss S")

      tdTime.innerHTML = date
    }
  })