【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)
  })
相关推荐
幻灵尔依21 分钟前
前端编码统一规范
javascript·vue.js·代码规范
欢脱的小猴子22 分钟前
VUE3加载cesium,导入czml的星座后页面卡死BUG 修复
前端·vue.js·bug
高级测试工程师欧阳23 分钟前
CSS 基础概念
前端·css·css3
前端小巷子24 分钟前
JS 实现图片瀑布流布局
前端·javascript·面试
Juchecar31 分钟前
AI教你常识之 npm / pnpm / package.json
前端
薛定谔的猫238 分钟前
前端工程化系列(一):编码规范相关
前端·代码规范·前端工程化
ZKshun41 分钟前
[ 前端性能优化 - 图片压缩 ] WebP格式的的图片性能到底有多优秀?
前端
杜蒙44 分钟前
React Hooks 详解
前端·javascript
南囝coding44 分钟前
Claude Code 从入门到精通:最全配置指南和工具推荐
前端·后端
索马里亚纳海参炒贩1 小时前
useCallback useMemo memo 三个区别和作用
前端·react native