index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <div class="sm-function-module-content">
  3. <el-form :model="form" ref="ruleForm" label-width="100px">
  4. <el-form-item label="裁剪区域宽度:" prop="width">
  5. <el-slider
  6. class="inputwidth"
  7. :min="1"
  8. :max="500"
  9. :step="1"
  10. v-model="form.width"
  11. @input="changewh()"
  12. ></el-slider>
  13. </el-form-item>
  14. <el-form-item label="裁剪区域高度:" prop="height">
  15. <el-slider
  16. class="inputwidth"
  17. :min="1"
  18. :max="500"
  19. :step="1"
  20. v-model="form.height"
  21. @input="changewh()"
  22. ></el-slider>
  23. </el-form-item>
  24. <el-form-item label="绕X轴旋转:" prop="pitch">
  25. <el-slider
  26. class="inputwidth"
  27. :min="0"
  28. :max="360"
  29. :step="1"
  30. v-model="form.pitch"
  31. @input="changehpr()"
  32. ></el-slider>
  33. </el-form-item>
  34. <el-form-item label="绕Y轴旋转:" prop="roll">
  35. <el-slider
  36. class="inputwidth"
  37. :min="0"
  38. :max="360"
  39. :step="1"
  40. v-model="form.roll"
  41. @input="changehpr()"
  42. ></el-slider>
  43. </el-form-item>
  44. <el-form-item label="绕Z轴旋转:" prop="heading">
  45. <el-slider
  46. class="inputwidth"
  47. :min="0"
  48. :max="360"
  49. :step="1"
  50. v-model="form.heading"
  51. @input="changehpr()"
  52. ></el-slider>
  53. </el-form-item>
  54. <el-form-item label="拉伸高度:" prop="extrudeDistance">
  55. <el-slider
  56. class="inputwidth"
  57. :min="0.01"
  58. :max="100"
  59. :step="0.02"
  60. v-model="form.extrudeDistance"
  61. @input="analysis"
  62. ></el-slider>
  63. </el-form-item>
  64. </el-form>
  65. <div class="boxchild">
  66. <el-button type="primary" size="mini" @click="clickPoint"
  67. >点击选择点位</el-button
  68. >
  69. <el-button type="primary" size="mini" @click="clear">清除</el-button>
  70. </div>
  71. </div>
  72. </template>
  73. <script>
  74. import { moveHandler, pickPoint } from "@/utils/MapHelper/help.js";
  75. let pos = {};
  76. let box = null;
  77. let startClip = false;
  78. let boxPosition = {};
  79. let layers = null;
  80. export default {
  81. name: "ClippingPlanes",
  82. props: {},
  83. data() {
  84. return {
  85. form: {
  86. width: 100,
  87. height: 100,
  88. heading: 0,
  89. pitch: 0,
  90. roll: 0,
  91. // 裁剪区域中心点拉伸距离,单位:米,
  92. extrudeDistance: 0.01,
  93. isMoving: false,
  94. },
  95. };
  96. },
  97. computed: {},
  98. beforeDestroy() {},
  99. mounted() {
  100. layers = store.state.tempLatData[0][0];
  101. viewer.flyTo(layers);
  102. this.addEntity();
  103. },
  104. methods: {
  105. clickPoint() {
  106. // startClip = true;
  107. if (!box) this.addEntity();
  108. box.show = true;
  109. moveHandler((position) => {
  110. boxPosition = position;
  111. this.setBox();
  112. });
  113. pickPoint(false, (position, handler) => {
  114. pos = position;
  115. // this.form.extrudeDistance = 100 - hei;
  116. // this.changehpr(pos);
  117. box.show = false;
  118. this.analysis();
  119. handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
  120. });
  121. },
  122. changewh() {
  123. this.setBox();
  124. this.analysis();
  125. },
  126. changehpr(pos) {
  127. if (!box) return;
  128. var hpr = new Cesium.HeadingPitchRoll(
  129. Cesium.Math.toRadians(this.form.heading),
  130. Cesium.Math.toRadians(this.form.pitch),
  131. Cesium.Math.toRadians(this.form.roll)
  132. );
  133. box.orientation = Cesium.Transforms.headingPitchRollQuaternion(
  134. pos || boxPosition,
  135. hpr
  136. );
  137. this.analysis();
  138. },
  139. analysis() {
  140. if (!pos.x) return;
  141. // this.vectorlayerlist.push(obj);
  142. // store.state.sceneLayerlist[obj.title];
  143. // this.layerparams.forEach(laitem => {
  144. // this.addEntity();
  145. this.updateClip();
  146. },
  147. // addEntity() {
  148. // viewer.entities.removeAll();
  149. // let js = 0.0000095;
  150. // // 计算矩形的边界坐标;
  151. // var minX = pos.lon - (this.form.width / 2) * js;
  152. // var maxX = pos.lon + (this.form.width / 2) * js;
  153. // var minY = pos.lat - (this.form.height / 2) * js;
  154. // var maxY = pos.lat + (this.form.height / 2) * js;
  155. // // 创建一个长方形实体
  156. // viewer.entities.add({
  157. // rectangle: {
  158. // coordinates: Cesium.Rectangle.fromDegrees(minX, minY, maxX, maxY),
  159. // material: new Cesium.Color.BLUE.withAlpha(0.5),
  160. // outline: true,
  161. // outlineColor: Cesium.Color.BLACK,
  162. // height: this.form.extrudeDistance,
  163. // },
  164. // });
  165. // },
  166. addEntity() {
  167. box = viewer.entities.add({
  168. // 标识盒
  169. position: Cesium.Cartesian3.fromDegrees(0, 0, 0),
  170. show: false,
  171. box: {
  172. dimensions: new Cesium.Cartesian3(5, 5, 0.1),
  173. fill: false,
  174. outline: true,
  175. outlineColor: Cesium.Color.RED,
  176. outlineWidth: 5.0,
  177. },
  178. });
  179. this.setBox();
  180. this.changehpr();
  181. },
  182. setBox() {
  183. if (!box) return;
  184. box.box.dimensions = new Cesium.Cartesian3(
  185. this.form.width,
  186. this.form.height,
  187. 0.1
  188. );
  189. box.position = boxPosition;
  190. },
  191. updateClip() {
  192. console.log(layers, "llll");
  193. // layers.setCustomClipPlane(pos[0], pos[1], pos[2]);
  194. layers.setCustomClipCross({
  195. position: pos,
  196. dimensions: new Cesium.Cartesian3(
  197. this.form.width,
  198. this.form.height,
  199. this.form.extrudeDistance
  200. ),
  201. heading: this.form.heading,
  202. pitch: this.form.pitch,
  203. roll: this.form.roll,
  204. extrudeDistance: this.form.extrudeDistance,
  205. });
  206. },
  207. clear() {
  208. if (box) box.show = false;
  209. // layers.clearCustomClipBox();
  210. layers.clearCustomClipBox();
  211. // viewer.entities.removeAll();
  212. },
  213. },
  214. watch: {},
  215. };
  216. </script>
  217. <style lang="scss" scoped>
  218. .inputwidth {
  219. width: calc(100% - 10px);
  220. }
  221. </style>