graphicLayer.startDraw({指定type为curve曲线时,无法实现示例效果排查思路参考

183 篇文章 2 订阅
165 篇文章 0 订阅
本文讲述了开发者在使用Mars3D进行图形层曲线绘制时遇到的问题,涉及到版本更新、库依赖顺序以及本地项目配置。作者通过对比本地和官方示例,发现本地turf库引入顺序错误,最终通过调整引入顺序解决了问题。
摘要由CSDN通过智能技术生成

graphicLayer.startDraw({指定type为curve曲线时,无法实现和示例一样的曲线效果的排查思路参考:

相关代码:
 

  graphicLayer.startDraw({

    type: "curve",

    style: {

      color: "#ff0000",

      width: 3,

    },

  });

相关效果:

示例效果:

问题排查思路:

本地问题代码说明:

1.颜色出来了,证明代码是走通的。

本地开发版本与官网示例版本对比说明:

1.本地的版本时3.7.9,官网时3.7.10,差了版本,升级版本后清空缓存再试试之后,发现依然不行

2.然后对比了turf库的版本,依然保持与官网示例一致的。@turf/turf@6.5.0"

3.排除版本问题后,拉了一份官网的最简项目模板再次测试。

官网的仓库的开源地址:Mars3D 三维可视化平台 | 火星科技 | 地图开发

拉最简项目模板代码的命令:

git clone https://gitee.com/marsgis/mars3d-vue-template.git

4.拉一份在最简项目模板发现无法复现问题,效果正常

在最后的解决方法是: 本地的项目中turf库未正确引入,

安装了但是用的时候没引成功没生效导致的效果不一样

导致的本地的曲线绘制效果与示例的曲线绘制效果不同。

1.在App.vue文件中参考开发教程的顺序重新引用了truf库,由此效果正常了。

  graphicLayer.startDraw({
    type: "curve",
    style: {
      color: "#33e8df",
      width: 3,
    },
  });

2.补充说明:相关依赖js文件的引入顺序参考官网的开发教程

例如: turf库引了之后在引mars3d才可以,需要测试这个引入顺序才行,参考这个顺序使用。

 

<!--引入cesium基础lib-->
<script>
  // window.CESIUM_BASE_URL = "https://unpkg.com/mars3d-cesium@latest/Build/Cesium/" //非必须,如jsp、asp.net等非html框架报错时建议取消注释
</script>
<link href="https://unpkg.com/mars3d-cesium@latest/Build/Cesium/Widgets/widgets.css" rel="stylesheet" type="text/css" />
<script src="https://unpkg.com/mars3d-cesium@latest/Build/Cesium/Cesium.js" type="text/javascript" ></script>
<script src="https://unpkg.com/@turf/turf/turf.min.js" type="text/javascript" ></script>

<!--引入mars3d库lib-->
<link href="https://unpkg.com/mars3d@latest/dist/mars3d.css" rel="stylesheet" type="text/css" />
<script src="https://unpkg.com/mars3d@latest/dist/mars3d.js" type="text/javascript" ></script>

<!--引入mars3d库插件lib(按需引入)-->
<script src="https://unpkg.com/mars3d-space@latest/dist/mars3d-space.js" type="text/javascript" ></script>

 

 

Vue 可以通过 canvas 实现签名功能,具体步骤如下: 1. 在 Vue 模板中添加一个 canvas 标签和两个按钮,一个用于清空签名,一个用于保存签名。 ```html <template> <div> <canvas ref="canvas"></canvas> <button @click="clear">清空</button> <button @click="save">保存</button> </div> </template> ``` 2. 在 Vue 的 mounted 钩子函数中获取 canvas 对象,并设置画笔颜色和线条宽度。 ```javascript mounted() { this.canvas = this.$refs.canvas; this.ctx = this.canvas.getContext('2d'); this.ctx.strokeStyle = '#000'; // 画笔颜色 this.ctx.lineWidth = 2; // 线条宽度 }, ``` 3. 监听鼠标事件,在鼠标移动绘制线条。 ```javascript methods: { startDraw(e) { this.isDrawing = true; this.lastX = e.offsetX; this.lastY = e.offsetY; }, draw(e) { if (!this.isDrawing) return; this.ctx.beginPath(); this.ctx.moveTo(this.lastX, this.lastY); this.ctx.lineTo(e.offsetX, e.offsetY); this.ctx.stroke(); this.lastX = e.offsetX; this.lastY = e.offsetY; }, endDraw() { this.isDrawing = false; } }, ``` 4. 实现清空和保存功能。 ```javascript methods: { clear() { this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height); }, save() { const dataURL = this.canvas.toDataURL(); console.log(dataURL); // 可以将 dataURL 发送到后端进行保存 } }, ``` 完整代码如下: ```html <template> <div> <canvas ref="canvas"></canvas> <button @click="clear">清空</button> <button @click="save">保存</button> </div> </template> <script> export default { data() { return { canvas: null, // canvas 对象 ctx: null, // 画笔对象 isDrawing: false, // 是否正在绘制 lastX: 0, // 上一个点的 x 坐标 lastY: 0 // 上一个点的 y 坐标 }; }, mounted() { this.canvas = this.$refs.canvas; this.ctx = this.canvas.getContext('2d'); this.ctx.strokeStyle = '#000'; // 画笔颜色 this.ctx.lineWidth = 2; // 线条宽度 }, methods: { startDraw(e) { this.isDrawing = true; this.lastX = e.offsetX; this.lastY = e.offsetY; }, draw(e) { if (!this.isDrawing) return; this.ctx.beginPath(); this.ctx.moveTo(this.lastX, this.lastY); this.ctx.lineTo(e.offsetX, e.offsetY); this.ctx.stroke(); this.lastX = e.offsetX; this.lastY = e.offsetY; }, endDraw() { this.isDrawing = false; }, clear() { this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height); }, save() { const dataURL = this.canvas.toDataURL(); console.log(dataURL); // 可以将 dataURL 发送到后端进行保存 } } }; </script> ``` 使用只需要将组件引入到需要的页面即可。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值