【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)
  })
相关推荐
GISer_Jing4 小时前
前端沙箱开源项目推荐(React/Next/Vue优先)
前端·react.js·开源
云水一下4 小时前
CSS3从零基础到精通(三):动感地带——过渡、动画、变形与响应式
前端·css3
KaMeidebaby5 小时前
卡梅德生物技术快报|Western Blot 实验应用:肺肠轴机制研究全流程技术解析
前端·数据库·人工智能·算法·百度
MageGojo5 小时前
做节日活动页时,如何用 API 快速生成对联内容
javascript·python·节日·对联生成
达达爱吃肉5 小时前
claude 接入deepseek 运行报错
java·服务器·前端
jingling5555 小时前
Flutter | Dio网络请求实战
android·开发语言·前端·flutter
向上的车轮5 小时前
Next.js 入门指南:从零到一构建全栈应用
开发语言·javascript·ecmascript
freeinlife'5 小时前
精准秒表计时器实现---基于js
开发语言·前端·javascript
MaCa .BaKa5 小时前
55-宠物爱心救助领养系统-宠物救助领养系统
java·vue.js·tomcat·maven·springboot·宠物救助领养系统
王文?问5 小时前
ESP32-S3 实战教程:本地语音识别控制 Web 塔防游戏,从固件到前端完整跑通
前端·游戏·语音识别