【Mars3d】点位停止编辑时获取点位空间坐标位置信息等回传给后端

示例地址:

http://mars3d.cn/editor-vue.html?id=graphic/primitive/point

当前问题:

右键编辑点,开始编辑对象--停止编辑。需要保存编辑后的点到数据库,需要对应的停止编辑函数。

复制代码
   {
        text: "停止编辑对象",
        icon: "fa fa-edit",
        show: function (e) {          
          console.log('停止编辑对象,获取对象信息');
          const graphic = e.graphic
          if (!graphic || !graphic.hasEdit) {
            return false
          }
          return graphic.isEditing
        },
        callback: (e) => {
          console.log('停止编辑对象000callback');
          const graphic = e.graphic
          if (!graphic) {
            return false
          }
          if (graphic) {
            graphic.stopEditing()
          }
        }
      },

解决方案:

停止编辑后,能够获取编辑点的坐标、高度、属性信息,回传给后端保存。

1.可以使用下面事件监听。

复制代码
graphicLayer.on(mars3d.EventType.editStop, function (e) {
 
})

2.或参考图上标绘功能,增加其他事件做完整的处理。

复制代码
  // 矢量数据创建完成
  graphicLayer.on(mars3d.EventType.drawCreated, function (e) {
    if (formState.hasEdit || props.customEditor) {
      showEditor(e.graphic)
    }
  })

  // 单击开始编辑
  graphicLayer.on(mars3d.EventType.editStart, (e: any) => {
    setTimeout(() => {
      // 属性面板打开时,点击其他的矢量数据,打开后会被下面的执行关闭
      showEditor(e.graphic)
    }, 150)
  })
  // 修改了矢量数据
  graphicLayer.on([mars3d.EventType.editMovePoint, mars3d.EventType.editStyle, mars3d.EventType.editRemovePoint], function (e) {
    updateWidget("graphic-editor", {
      data: {
        graphic: markRaw(e.graphic)
      }
    })
  })
  // 停止编辑
  graphicLayer.on([mars3d.EventType.editStop, mars3d.EventType.removeGraphic], function (e) {
    setTimeout(() => {
      if (!graphicLayer.isEditing) {
        if (props.customEditor) {
          emit("onStopEditor")
        } else {
          disable("graphic-editor")
        }
      }
    }, 100)
  })
相关推荐
风宇啸天11 分钟前
令牌桶按用户维度限流
前端
safestar201212 分钟前
React 19 深度解析:从并发模式到数据获取的架构革命
前端·javascript·react.js
越努力越幸运50839 分钟前
npm常见问题解决
前端·npm·node.js
Wild~~41 分钟前
electron-vite
前端·javascript·electron
by__csdn1 小时前
Electron+Vite:实现electron + vue3 + ts + pinia + vite高效跨平台开发指南
前端·javascript·vue.js·typescript·electron·node.js·vue
国服第二切图仔1 小时前
Electron 鸿蒙pc开发环境搭建完整保姆级教程(window)
javascript·electron·harmonyos
马达加斯加D1 小时前
C# --- 如何写UT
前端·c#·log4j
yqcoder1 小时前
在 scss 中,&>div 作用
前端·css·scss
小马哥编程1 小时前
这个variables.scss文件中$menuText:#bfcbd9;:export {menuText: $menuText; }的语法符合要求吗
前端·css·scss
宋辰月1 小时前
zustand
前端·javascript·html