coordsTool.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <script setup>
  2. /**
  3. * element-plus组件
  4. */
  5. import {
  6. ElMessage
  7. } from 'element-plus';
  8. import {
  9. inject
  10. } from "vue";
  11. const getMapInstance = inject("getMapInstance");
  12. jt3d = getMapInstance();
  13. </script>
  14. <template>
  15. <div class="jt-coordsTool">
  16. <el-collapse v-model="activeName" accordion>
  17. <el-collapse-item name="坐标定位">
  18. <template #title>
  19. <i class='iconfont icon-dituzuobiao' />坐标定位
  20. </template>
  21. <div class="el-collapse-item__content">
  22. <div style="line-height: 2em; table-layout: fixed; word-wrap: break-word; word-break: normal; text-align:justify; text-justify: inter-ideograph;color: #ffffff60;">
  23. 提示: 填写格式:x1,y1,z1;x2,y2,z2;x3,y3,z3;......;标点符号必须采用英文半角。
  24. </div>
  25. <el-form label-width="80rem">
  26. <el-form-item label="定位类型:">
  27. <el-radio-group v-model="position.locationType">
  28. <el-radio label="point">点</el-radio>
  29. <el-radio label="polyline">线</el-radio>
  30. <el-radio label="polygon">多边形</el-radio>
  31. </el-radio-group>
  32. </el-form-item>
  33. </el-form>
  34. <el-input v-model="position.locationCoords" type="textarea" :autosize="{ minRows: 6, maxRows: 6 }" />
  35. <div class="jt-btn" style="margin-top: 10rem;">
  36. <el-button color="rgb(20 136 255)" @click="Position">坐标定位</el-button>
  37. <el-button color="rgb(255 100 100)" @click="empty"><span style="color: #fff;">清除定位</span></el-button>
  38. </div>
  39. </div>
  40. </el-collapse-item>
  41. <el-collapse-item name="坐标拾取">
  42. <template #title>
  43. <i class='iconfont icon-chaxunzuobiaozhi' />坐标拾取
  44. </template>
  45. <div class="el-collapse-item__content">
  46. <div style="line-height: 2em; table-layout: fixed; word-wrap: break-word; word-break: normal; text-align:justify; text-justify: inter-ideograph;color: #ffffff60;">
  47. 提示:点击【坐标拾取】按钮,在地图上点击获取坐标。
  48. </div>
  49. <el-input v-model="pickCoords" type="textarea" :autosize="{ minRows: 6, maxRows: 6 }" />
  50. <div class="jt-btn" style="margin-top: 10rem;">
  51. <el-button color="rgb(20 136 255)" @click="pickUp">坐标拾取</el-button>
  52. <el-button color="rgb(20 136 255)" @click="undo">撤销</el-button>
  53. <el-button color="rgb(255 100 100)" @click="empty"><span style="color: #fff;">清空</span></el-button>
  54. </div>
  55. </div>
  56. </el-collapse-item>
  57. </el-collapse>
  58. </div>
  59. </template>
  60. <script>
  61. let jt3d = undefined;
  62. export default {
  63. props: {
  64. },
  65. watch: {
  66. pickCoordsLable: function(val) {
  67. this.setPickCoordsLable(val);
  68. },
  69. },
  70. /* 数据 */
  71. data() {
  72. return {
  73. activeName: "坐标定位",
  74. position: {
  75. locationType: "point", //定位类型
  76. locationCoords: "", //定位坐标
  77. },
  78. pickCoords: "", //坐标拾取
  79. pickCoordsArray: [],
  80. pickCoordsLable: 1,
  81. pointEntities: []
  82. }
  83. },
  84. /* 方法 */
  85. methods: {
  86. /**
  87. * 设置点的lable
  88. */
  89. setPickCoordsLable(val) {
  90. jt3d.CommonTools._sketchViewModel._lineLabel = val.toString();
  91. },
  92. /**
  93. * 坐标拾取
  94. */
  95. pickUp() {
  96. let _self = this;
  97. //移除左键单击事件
  98. if (jt3d.handlerLeftClick) {
  99. jt3d.handlerLeftClick.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
  100. }
  101. jt3d.CommonTools._sketchViewModel._lineLabel = _self.pickCoordsLable.toString();
  102. jt3d.CommonTools._sketchViewModel.sketchTools('point', {
  103. onComplete(cPoint, gPoint) {
  104. _self.pickCoordsArray.push(gPoint.lng.toFixed(6) + ',' + gPoint.lat.toFixed(6) + ',' + gPoint.height.toFixed(2)) + ";";
  105. _self.pickCoords = _self.pickCoordsArray.join(";\n");
  106. _self.pickCoordsLable++;
  107. //还原左键单击事件
  108. _self.$parent.$parent.$refs.refMap3d.clickEntity(jt3d);
  109. },
  110. onError(message) {
  111. }
  112. });
  113. },
  114. /**
  115. * 坐标拾取 - 撤销
  116. */
  117. undo() {
  118. this.pickCoordsArray.pop();
  119. this.pickCoords = this.pickCoordsArray.join(";\n");
  120. this.pickCoordsLable--;
  121. //移除最后一个元素
  122. let lastPointEntity = jt3d.CommonTools._sketchViewModel._pointEntitys[jt3d.CommonTools._sketchViewModel._pointEntitys.length - 1];
  123. jt3d._entities.remove(lastPointEntity);
  124. jt3d.CommonTools._sketchViewModel._pointEntitys.pop();
  125. },
  126. /**
  127. * 坐标拾取 - 清空
  128. */
  129. empty() {
  130. this.pickCoords = "";
  131. this.pickCoordsArray = [];
  132. this.pickCoordsLable = 1;
  133. jt3d.CommonTools._sketchViewModel.sketchClear();
  134. jt3d.CommonTools._sketchViewModel._clearEvent();
  135. jt3d.CommonTools._sketchViewModel._clearEvent(jt3d.CommonTools._sketchViewModel._sketchEventHandler);
  136. this.position.locationCoords = "";
  137. jt3d._viewer.entities.remove(jt3d.LocateUtil._locationEntity);
  138. for (let i = 0; i < this.pointEntities.length; i++) {
  139. jt3d._viewer.entities.remove(this.pointEntities[i]);
  140. }
  141. this.pointEntities = []; //脏数据,存储entities
  142. },
  143. /**
  144. * 坐标定位
  145. */
  146. Position() {
  147. let _self = this;
  148. let endstring = _self.position.locationCoords.substring(_self.position.locationCoords.length - 1);
  149. if (endstring != ";") {
  150. ElMessage("最后一位请用;结束!");
  151. return false;
  152. }
  153. let coords = _self.position.locationCoords.substr(0, _self.position.locationCoords.length - 1);
  154. let coordArray = coords.split(';');
  155. let pointArray = [];
  156. coordArray.forEach((coordinate, index) => {
  157. let xyArray = coordinate.split(',');
  158. if (xyArray.length != 2 && xyArray.length != 3) {
  159. ElMessage("坐标不是成对出现,请检查!");
  160. throw Error(); //forEach()本身无法跳出循环,所以,这里使用了抛异常的方法来终止它。
  161. } else {
  162. let longitude = xyArray[0];
  163. let latitude = xyArray[1];
  164. if (xyArray[2]) {
  165. let height = xyArray[2];
  166. let point = [Number(longitude), Number(latitude), Number(height)];
  167. pointArray.push(point);
  168. //点标记
  169. jt3d.CommonTools._sketchViewModel._lineLabel = (index + 1).toString();
  170. jt3d.CommonTools._sketchViewModel.sketchDrawFeacture(point, 'drawPoint');
  171. if (index === (coordArray.length - 1)) {
  172. loc();
  173. }
  174. } else {
  175. let terrainAltitude = _self.jt3dSDK.common.getHeigthByPointsMostDetailed(jt3d._viewer, [
  176. [Number(longitude), Number(latitude)]
  177. ]);
  178. terrainAltitude.then(function(updatedPositions) {
  179. let point = [Number(longitude), Number(latitude), Number(updatedPositions[0].height)];
  180. pointArray.push(point);
  181. //点标记
  182. jt3d.CommonTools._sketchViewModel._lineLabel = (index + 1).toString();
  183. jt3d.CommonTools._sketchViewModel.sketchDrawFeacture(point, 'drawPoint');
  184. if (index === (coordArray.length - 1)) {
  185. loc();
  186. }
  187. });
  188. }
  189. }
  190. });
  191. function loc() {
  192. switch (_self.position.locationType) {
  193. case "point":
  194. if (coordArray.length === 1) {
  195. let point = jt3d.PointObject.generatePoint(
  196. pointArray[0]
  197. );
  198. point.then(function(entity) {
  199. _self.flyToEntity(entity);
  200. });
  201. } else {
  202. let line = jt3d.PolylineObject.drawSpecifyColorLine(pointArray, {
  203. color: [255, 0, 0, 0]
  204. });
  205. line.then(function(entity) {
  206. _self.flyToEntity(entity);
  207. });
  208. }
  209. break;
  210. case "polyline":
  211. let line = jt3d.PolylineObject.drawSpecifyColorLine(pointArray, {
  212. color: [255, 255, 0, 0.8]
  213. });
  214. line.then(function(entity) {
  215. _self.flyToEntity(entity);
  216. });
  217. break;
  218. case "polygon":
  219. let polygon = jt3d.PolygonObject.generatePolygonByPoints(pointArray, {
  220. color: [255, 255, 0, 0.8]
  221. });
  222. polygon.then(function(entity) {
  223. _self.flyToEntity(entity);
  224. });
  225. break;
  226. }
  227. }
  228. },
  229. flyToEntity(entity) {
  230. let flyToEntity = jt3d.LocateUtil.flyToEntity(entity, {
  231. duration: 3,
  232. heading: 200,
  233. pitch: -80,
  234. range: 1000
  235. });
  236. flyToEntity.then(function(entity) {
  237. if (entity.point) {
  238. jt3d._viewer.entities.remove(entity);
  239. }
  240. });
  241. },
  242. },
  243. mounted() {
  244. }
  245. };
  246. </script>
  247. <style lang="scss" scoped>
  248. .el-radio-group {
  249. height: 32rem;
  250. line-height: 32rem;
  251. flex-wrap: nowrap;
  252. }
  253. ::v-deep .el-radio__label {
  254. font-size: 14rem !important;
  255. padding-left: 8rem !important;
  256. }
  257. .jt-coordsTool {
  258. position: relative;
  259. .iconfont {
  260. padding: 0 10rem;
  261. }
  262. .el-collapse {
  263. --el-collapse-border-color: rgb(0 44 126 / 0%);
  264. --el-collapse-header-text-color: #ffffff;
  265. --el-collapse-header-font-size: 13rem;
  266. --el-collapse-content-bg-color: rgb(0 44 126 / 0%);
  267. --el-collapse-content-font-size: 13rem;
  268. --el-collapse-content-text-color: rgb(216 240 255);
  269. --el-collapse-header-height: 40rem;
  270. --el-collapse-header-bg-color: rgb(30 130 255);
  271. --el-fill-color-blank: rgb(0 44 126 / 68%);
  272. --el-text-color-regular: rgb(216 240 255);
  273. --el-border-color: rgb(35 135 255);
  274. .el-collapse-item__content {
  275. padding: 10rem;
  276. // padding-bottom: 0rem;
  277. }
  278. }
  279. }
  280. ::v-deep .el-collapse-item__content {
  281. padding: 10rem;
  282. // padding-bottom: 0rem;
  283. overflow-y: hidden;
  284. }
  285. ::v-deep .el-collapse-item__header {
  286. background: url(@/assets/images/bg_collapse_title.png) no-repeat;
  287. background-size: 350rem 40rem;
  288. // background-color: rgb(22 90 190);
  289. // background-color: rgb(5 45 100 /60%);
  290. background-color: rgb(30 130 255);
  291. border-bottom: 0;
  292. }
  293. ::v-deep .el-form-item {
  294. margin-bottom: 10rem;
  295. }
  296. ::v-deep .el-radio {
  297. margin-right: 10rem;
  298. }
  299. </style>