【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)
  })
相关推荐
Yeats_Liao8 分钟前
Go Web 编程快速入门 10 - 数据库集成与ORM:连接池、查询优化与事务管理
前端·数据库·后端·golang
啃火龙果的兔子39 分钟前
前端八股文react篇
前端·react.js·前端框架
打小就很皮...40 分钟前
React 实现 i18next 中英文切换集成
前端·react.js·i18next
拉不动的猪1 小时前
函数组件和异步组件
前端·javascript·面试
淮北4941 小时前
html + css +js
开发语言·前端·javascript·css·html
麦麦大数据1 小时前
F036 vue+flask中医热性药知识图谱可视化系统vue+flask+echarts+mysql
vue.js·python·mysql·flask·可视化·中医中药
你的人类朋友1 小时前
适配器模式:适配就完事了bro!
前端·后端·设计模式
Setsuna_F_Seiei1 小时前
CocosCreator 游戏开发 - 利用 AssetsBundle 技术对小游戏包体积进行优化
前端·cocos creator·游戏开发
黄毛火烧雪下1 小时前
高效的项目构建和优化之前端构建工具
前端
90后的晨仔2 小时前
在 macOS 上轻松获取 GIF 图片总时长:多种实用方法详解
前端