1. 使用流程演示



2.vue页面源码

// 绘制矩形   对角线方式  drawRectangle11() {this.$message({type: "success",message: "鼠标左键单击开始绘制,右键结束",});// 绘制的时候清除上一个矩形数据this.cleanRectangle();//绘制点let that = this;let viewer = window.map.map3D;let tempEntities = [];let position = [];let tempPoints = [];// 开启深度检测viewer.scene.globe.depthTestAgainstTerrain = true;let handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);//鼠标移动事件handler.setInputAction(function (movement) {},Cesium.ScreenSpaceEventType.MOUSE_MOVE);//左键点击操作handler.setInputAction(function (click) {//调用获取位置信息的接口let ray = viewer.camera.getPickRay(click.position);position = viewer.scene.globe.pick(ray, viewer.scene);tempPoints.push(position);let tempLength = tempPoints.length;//调用绘制点的接口let point = that.drawPoint(tempPoints[tempPoints.length - 1]);tempEntities.push(point);if (tempLength > 1) {let pointline = that.drawPolyline([tempPoints[tempPoints.length - 2],tempPoints[tempPoints.length - 1],]);tempEntities.push(pointline);} else {// tooltip.innerHTML = "请绘制下一个点,右键结束";}}, Cesium.ScreenSpaceEventType.LEFT_CLICK);//右键点击操作handler.setInputAction(function (click) {that.rectanglePoint = [];let point1 = that.cartesianTolngLatAlt(tempPoints[0]);let point2 = that.cartesianTolngLatAlt(tempPoints[1]);let x1 = null;let x2 = null;let y1 = null;let y2 = null;//处理得到的两个点,让不管是从哪个方向绘制都最终得到的是左上(x1,y2) 右下(x2,y1)两个坐标  *****if (point1.lat * 1 < point2.lat * 1) {y1 = point1.lat;y2 = point2.lat;} else {y1 = point2.lat;y2 = point1.lat;}if (point1.lng * 1 > point2.lng * 1) {x1 = point1.lng;x2 = point2.lng;} else {x1 = point2.lng;x2 = point1.lng;}tempPoints = [];handler.destroy(); //关闭事件句柄handler = null;viewer.entities.removeAll();// 绘制矩形let graphical = viewer.entities.add({id: "Rectangle",rectangle: {coordinates: Cesium.Rectangle.fromDegrees(x2, y1, x1, y2), // 最西、最南、最东、最北outline: true,outlineColor: Cesium.Color.WHITE,material: Cesium.Color.BLUE.withAlpha(0.3),outlineWidth: 4,stRotation: Cesium.Math.toRadians(45),// material: stripeMaterial,},});// 更新输入框的内容that.rectanglePoint = [x2, y1, x1, y2];that.rectanglePointShow = `[${x2.toFixed(0)},${y1.toFixed(0)}] - [${x1.toFixed(0)},${y2.toFixed(0)}]`;that.params[2].range[0] = that.rectanglePointShow;that.$message({type: "success",message: `绘图坐标:${that.rectanglePoint}`,});that.getList();}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);},// 清除绘制的矩形cleanRectangle() {var viewer = window.map.map3D;// 删除全部viewer.entities.removeAll();},drawPolyline(positions, config_) {let viewer = window.map.map3D;if (positions.length < 1) return;let config = config_ ? config_ : {};return viewer.entities.add({name: "线几何对象",polyline: {positions: positions,width: config.width ? config.width : 5.0,material: new Cesium.PolylineGlowMaterialProperty({color: config.color? new Cesium.Color.fromCssColorString(config.color): Cesium.Color.GOLD,}),depthFailMaterial: new Cesium.PolylineGlowMaterialProperty({color: config.color? new Cesium.Color.fromCssColorString(config.color): Cesium.Color.GOLD,}),clampToGround: true,},});},drawPoint(position, config) {let viewer = window.map.map3D;let config_ = config ? config : {};return viewer.entities.add({name: "点几何对象",position: position,point: {color: Cesium.Color.SKYBLUE,pixelSize: 10,outlineColor: Cesium.Color.YELLOW,outlineWidth: 3,disableDepthTestDistance: Number.POSITIVE_INFINITY,heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,},});},cartesianTolngLatAlt(cartesianObj) {let viewer = window.map.map3D;const cartesian3 = new Cesium.Cartesian3(cartesianObj.x,cartesianObj.y,cartesianObj.z);const cartographic =viewer.scene.globe.ellipsoid.cartesianToCartographic(cartesian3);const lat = Cesium.Math.toDegrees(cartographic.latitude);const lng = Cesium.Math.toDegrees(cartographic.longitude);const alt = cartographic.height;return { lat, lng, alt };},

cesium借助折线的两个端点绘制一个矩形--vue2.0版本 --按照经纬线横纵排列相关推荐

  1. php 画矩形 然后合并,php绘制一个矩形的方法

    php绘制一个矩形的方法 本文实例讲述了php绘制一个矩形的方法.分享给大家供大家参考.具体实现方法如下: 复制代码 代码如下: //1.创建画布 $im = imagecreatetruecolor ...

  2. webgl之绘制一个矩形

    功能:使用webgl绘制一个矩形,这里通过绘制两个三角形来实现一个矩形的绘制 步骤: 1 获取webgl上下文 2 获取着色器字符串 3 创建,加载,编译着色器 4 给着色器的变量赋值 5 绘制图形 ...

  3. 绘制矩形php,PHP_php绘制一个矩形的方法,本文实例讲述了php绘制一个矩 - phpStudy...

    php绘制一个矩形的方法 本文实例讲述了php绘制一个矩形的方法.分享给大家供大家参考.具体实现方法如下: //1.创建画布 $im = imagecreatetruecolor(300,200);/ ...

  4. 绘制矩形php,php绘制一个矩形的方法

    本文实例讲述了php绘制一个矩形的方法.分享给大家供大家参考.具体实现方法如下: //1.创建画布 $im = imagecreatetruecolor(300,200);//新建一个真彩色图像,默认 ...

  5. html页面画一个矩形,使用HTML5 canvas绘制一个矩形的方法

    使用HTML5 canvas绘制一个矩形的方法 发布时间:2020-08-29 11:23:12 来源:亿速云 阅读:102 作者:小新 这篇文章将为大家详细讲解有关使用HTML5 canvas绘制一 ...

  6. 在canvas(画布)上绘制一个矩形盒子并使用按键移动这个盒子

    思路 1.在画布上创建一个2d画笔,并用这个画笔在画布上绘制一个矩形. 2.设置一个边界判断使这个盒子不能移出画布之外,只能在画布中移动. 注意: 不能直接在style中设置canvas的大小 直接设 ...

  7. android canvas drawrect画图,为什么在android中调用canvas.drawRect时只绘制一个矩形?

    我正在尝试使用foreach循环为ArrayList中的每个字符串绘制一个矩形,但它似乎只绘制了最后一个矩形. 我看过类似的问题,但他们遇到的问题包括矩形底部高于顶部并调用drawPaint - 但我 ...

  8. Android中使用画笔和画布绘制一个矩形

    场景 在Android中画笔使用Paint类,画布使用Canvas类来表示. 绘图的基本步骤 首先编写一个继承自View的自定义View类,然后重写其onDraw方法,最后把自定义的view添加到ac ...

  9. 如何使用Inkscape软件绘制一个LOGO

    使用Inkscape软件绘制Logo Logo参考 操作界面修改操作流程 详细制作流程 方法一:创建矩形或正方形进行绘制 方法二:使用钢笔工具进行绘制 制作心得 Logo参考 效果图: 操作界面修改操 ...

最新文章

  1. OpenCV Python教程(1、图像的载入、显示和保存)
  2. 2020年,图机器学习的趋势有哪些?
  3. 世界顶级精英们的人生哲学(转)
  4. JS Event handler example - event capture and bubble
  5. mui + vue 模板
  6. 打印机一直显示正在打印中_中国和桌面3D打印机正在引领3D打印市场
  7. 【经验分享】如何搭建本地MQTT服务器(Windows ),并进行上下行调测
  8. Python的Numpy库下载及安装
  9. 3.3V和1.8V电平双向转换——电平转换芯片
  10. 笔记本电脑开wifi热点小技巧,bat文件实现
  11. 轻量级日志分析PLG平台Loki安装部署及使用(promtail+loki+Grafana)
  12. 冒充云销售的懒虫和毒虫们
  13. C++错误:C4996
  14. android分享截屏到微信,Android 微信分享长图 ScrollView 生成长截图 View变bitmap
  15. 华硕z170a如何开启m2_华硕Z170主板bios如何设置|华硕Z170主板设置bios的方法
  16. opencv读图的坐标系转换问题
  17. (8)C#导入库编译出错:请考虑使用 app.config 将程序集“log4net, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a”
  18. 读《史蒂夫•乔布斯传》(四)
  19. 使用Makefile链接so库文件
  20. 组态王和plc之间如何建立通讯?

热门文章

  1. 如何在WorkNC中载入机床?
  2. 微信摇一摇怎么连接服务器,微信摇一摇电视有什么用 摇一摇电视互动玩法及原理...
  3. 百度站长资源平台自动批量添加站点域名工具(站长站群工具)
  4. 适用于 Web 开发者的 Atom 编辑器插件
  5. python自学看不懂-为什么自学Python看不进去?
  6. 完美契合,实现最大团队工作效率
  7. iOS 推送语音播报(类似支付宝微信的收款提醒)
  8. win7打开方式选择默认程序导致应用程序无法打开
  9. win10 ping命令与telnet命令使用详解
  10. ERP基础知识-EEGLAB学习的理论基础