coordsTool.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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. // debugger
  112. }
  113. });
  114. },
  115. /**
  116. * 坐标拾取 - 撤销
  117. */
  118. undo() {
  119. this.pickCoordsArray.pop();
  120. this.pickCoords = this.pickCoordsArray.join(";\n");
  121. this.pickCoordsLable--;
  122. //移除最后一个元素
  123. let lastPointEntity = jt3d.CommonTools._sketchViewModel._pointEntitys[jt3d.CommonTools._sketchViewModel._pointEntitys.length - 1];
  124. jt3d._entities.remove(lastPointEntity);
  125. jt3d.CommonTools._sketchViewModel._pointEntitys.pop();
  126. },
  127. /**
  128. * 坐标拾取 - 清空
  129. */
  130. empty() {
  131. this.pickCoords = "";
  132. this.pickCoordsArray = [];
  133. this.pickCoordsLable = 1;
  134. jt3d.CommonTools._sketchViewModel.sketchClear();
  135. jt3d.CommonTools._sketchViewModel._clearEvent();
  136. jt3d.CommonTools._sketchViewModel._clearEvent(jt3d.CommonTools._sketchViewModel._sketchEventHandler);
  137. this.position.locationCoords = "";
  138. jt3d._viewer.entities.remove(jt3d.LocateUtil._locationEntity);
  139. for (let i = 0; i < this.pointEntities.length; i++) {
  140. jt3d._viewer.entities.remove(this.pointEntities[i]);
  141. }
  142. this.pointEntities = []; //脏数据,存储entities
  143. },
  144. /**
  145. * 坐标定位
  146. */
  147. Position() {
  148. let _self = this;
  149. let endstring = _self.position.locationCoords.substring(_self.position.locationCoords.length - 1);
  150. if (endstring != ";") {
  151. ElMessage("最后一位请用;结束!");
  152. return false;
  153. }
  154. let coords = _self.position.locationCoords.substr(0, _self.position.locationCoords.length - 1);
  155. let coordArray = coords.split(';');
  156. let pointArray = [];
  157. coordArray.forEach((coordinate, index) => {
  158. let xyArray = coordinate.split(',');
  159. if (xyArray.length != 2 && xyArray.length != 3) {
  160. ElMessage("坐标不是成对出现,请检查!");
  161. throw Error(); //forEach()本身无法跳出循环,所以,这里使用了抛异常的方法来终止它。
  162. } else {
  163. let longitude = xyArray[0];
  164. let latitude = xyArray[1];
  165. if (xyArray[2]) {
  166. let height = xyArray[2];
  167. let point = [Number(longitude), Number(latitude), Number(height)];
  168. pointArray.push(point);
  169. //点标记
  170. jt3d.CommonTools._sketchViewModel._lineLabel = (index + 1).toString();
  171. jt3d.CommonTools._sketchViewModel.sketchDrawFeacture(point, 'drawPoint');
  172. if (index === (coordArray.length - 1)) {
  173. loc();
  174. }
  175. } else {
  176. let terrainAltitude = _self.jt3dSDK.common.getHeigthByPointsMostDetailed(jt3d._viewer, [
  177. [Number(longitude), Number(latitude)]
  178. ]);
  179. terrainAltitude.then(function(updatedPositions) {
  180. let point = [Number(longitude), Number(latitude), Number(updatedPositions[0].height)];
  181. pointArray.push(point);
  182. //点标记
  183. jt3d.CommonTools._sketchViewModel._lineLabel = (index + 1).toString();
  184. jt3d.CommonTools._sketchViewModel.sketchDrawFeacture(point, 'drawPoint');
  185. if (index === (coordArray.length - 1)) {
  186. loc();
  187. }
  188. });
  189. }
  190. }
  191. });
  192. function loc() {
  193. switch (_self.position.locationType) {
  194. case "point":
  195. if (coordArray.length === 1) {
  196. let point = jt3d.PointObject.generatePoint(
  197. pointArray[0]
  198. );
  199. point.then(function(entity) {
  200. _self.flyToEntity(entity);
  201. });
  202. } else {
  203. let line = jt3d.PolylineObject.drawSpecifyColorLine(pointArray, {
  204. color: [255, 0, 0, 0]
  205. });
  206. line.then(function(entity) {
  207. _self.flyToEntity(entity);
  208. });
  209. }
  210. break;
  211. case "polyline":
  212. let line = jt3d.PolylineObject.drawSpecifyColorLine(pointArray, {
  213. color: [255, 255, 0, 0.8]
  214. });
  215. line.then(function(entity) {
  216. _self.flyToEntity(entity);
  217. });
  218. break;
  219. case "polygon":
  220. let polygon = jt3d.PolygonObject.generatePolygonByPoints(pointArray, {
  221. color: [255, 255, 0, 0.8]
  222. });
  223. polygon.then(function(entity) {
  224. _self.flyToEntity(entity);
  225. });
  226. break;
  227. }
  228. }
  229. },
  230. flyToEntity(entity) {
  231. let flyToEntity = jt3d.LocateUtil.flyToEntity(entity, {
  232. duration: 3,
  233. heading: 0,
  234. pitch: -60,
  235. range: 0
  236. });
  237. flyToEntity.then(function(entity11) {
  238. // alert(1111)
  239. });
  240. },
  241. },
  242. mounted() {
  243. }
  244. };
  245. </script>
  246. <style lang="scss" scoped>
  247. .el-radio-group {
  248. height: 32rem;
  249. line-height: 32rem;
  250. flex-wrap: nowrap;
  251. }
  252. ::v-deep .el-radio__label {
  253. font-size: 14rem !important;
  254. padding-left: 8rem !important;
  255. }
  256. .jt-coordsTool {
  257. position: relative;
  258. .iconfont {
  259. padding: 0 10rem;
  260. }
  261. .el-collapse {
  262. --el-collapse-border-color: rgb(0 44 126 / 0%);
  263. --el-collapse-header-text-color: #ffffff;
  264. --el-collapse-header-font-size: 13rem;
  265. --el-collapse-content-bg-color: rgb(0 44 126 / 0%);
  266. --el-collapse-content-font-size: 13rem;
  267. --el-collapse-content-text-color: rgb(216 240 255);
  268. --el-collapse-header-height: 40rem;
  269. --el-collapse-header-bg-color: rgb(30 130 255);
  270. --el-fill-color-blank: rgb(0 44 126 / 68%);
  271. --el-text-color-regular: rgb(216 240 255);
  272. --el-border-color: rgb(35 135 255);
  273. .el-collapse-item__content {
  274. padding: 10rem;
  275. // padding-bottom: 0rem;
  276. }
  277. }
  278. }
  279. ::v-deep .el-collapse-item__content {
  280. padding: 10rem;
  281. // padding-bottom: 0rem;
  282. overflow-y: hidden;
  283. }
  284. ::v-deep .el-collapse-item__header {
  285. background: url(@/assets/images/bg_collapse_title.png) no-repeat;
  286. background-size: 350rem 40rem;
  287. // background-color: rgb(22 90 190);
  288. // background-color: rgb(5 45 100 /60%);
  289. background-color: rgb(30 130 255);
  290. border-bottom: 0;
  291. }
  292. ::v-deep .el-form-item {
  293. margin-bottom: 10rem;
  294. }
  295. ::v-deep .el-radio {
  296. margin-right: 10rem;
  297. }
  298. </style>