index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 = null;
  79. let layers = [];
  80. export default {
  81. name: "ClippingPlanes",
  82. props: {},
  83. data() {
  84. return {
  85. form: {
  86. width: 5,
  87. height: 5,
  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. if (store.state.tempLatData) {
  101. layers = store.state.tempLatData[0];
  102. console.log(layers, "llll");
  103. viewer.flyTo(layers[0]);
  104. this.addEntity();
  105. }
  106. },
  107. methods: {
  108. clickPoint() {
  109. // startClip = true;
  110. if (!box) this.addEntity();
  111. box.show = true;
  112. moveHandler((position) => {
  113. boxPosition = position;
  114. this.setBox();
  115. });
  116. pickPoint(false, (position, handler) => {
  117. pos = position;
  118. // this.form.extrudeDistance = 100 - hei;
  119. // this.changehpr(pos);
  120. box.show = false;
  121. this.analysis();
  122. handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
  123. });
  124. },
  125. changewh() {
  126. this.setBox();
  127. this.analysis();
  128. },
  129. changehpr(pos) {
  130. if (!box || !boxPosition) return;
  131. var hpr = new Cesium.HeadingPitchRoll(
  132. Cesium.Math.toRadians(this.form.heading),
  133. Cesium.Math.toRadians(this.form.pitch),
  134. Cesium.Math.toRadians(this.form.roll)
  135. );
  136. box.orientation = Cesium.Transforms.headingPitchRollQuaternion(
  137. pos || boxPosition,
  138. hpr
  139. );
  140. this.analysis();
  141. },
  142. analysis() {
  143. if (!pos.x) return;
  144. // this.vectorlayerlist.push(obj);
  145. // store.state.sceneLayerlist[obj.title];
  146. // this.layerparams.forEach(laitem => {
  147. // this.addEntity();
  148. this.updateClip();
  149. },
  150. // addEntity() {
  151. // viewer.entities.removeAll();
  152. // let js = 0.0000095;
  153. // // 计算矩形的边界坐标;
  154. // var minX = pos.lon - (this.form.width / 2) * js;
  155. // var maxX = pos.lon + (this.form.width / 2) * js;
  156. // var minY = pos.lat - (this.form.height / 2) * js;
  157. // var maxY = pos.lat + (this.form.height / 2) * js;
  158. // // 创建一个长方形实体
  159. // viewer.entities.add({
  160. // rectangle: {
  161. // coordinates: Cesium.Rectangle.fromDegrees(minX, minY, maxX, maxY),
  162. // material: new Cesium.Color.BLUE.withAlpha(0.5),
  163. // outline: true,
  164. // outlineColor: Cesium.Color.BLACK,
  165. // height: this.form.extrudeDistance,
  166. // },
  167. // });
  168. // },
  169. addEntity() {
  170. box = viewer.entities.add({
  171. // 标识盒
  172. position: Cesium.Cartesian3.fromDegrees(0, 0, 0),
  173. show: false,
  174. box: {
  175. dimensions: new Cesium.Cartesian3(5, 5, 0.001),
  176. fill: false,
  177. outline: true,
  178. outlineColor: Cesium.Color.RED,
  179. outlineWidth: 5.0,
  180. },
  181. });
  182. this.setBox();
  183. this.changehpr();
  184. },
  185. setBox() {
  186. if (!box || !boxPosition) return;
  187. box.box.dimensions = new Cesium.Cartesian3(
  188. this.form.width,
  189. this.form.height,
  190. 0.001
  191. );
  192. box.position = boxPosition;
  193. },
  194. updateClip() {
  195. // layers.setCustomClipPlane(pos[0], pos[1], pos[2]);
  196. layers.forEach((li) => {
  197. li.setCustomClipCross({
  198. position: pos,
  199. dimensions: new Cesium.Cartesian3(
  200. this.form.width,
  201. this.form.height,
  202. this.form.extrudeDistance
  203. ),
  204. heading: this.form.heading,
  205. pitch: this.form.pitch,
  206. roll: this.form.roll,
  207. extrudeDistance: this.form.extrudeDistance,
  208. });
  209. });
  210. },
  211. clear() {
  212. if (box) box.show = false;
  213. layers.forEach((li) => {
  214. li.clearCustomClipBox();
  215. });
  216. // viewer.entities.removeAll();
  217. },
  218. },
  219. watch: {},
  220. };
  221. </script>
  222. <style lang="scss" scoped>
  223. .inputwidth {
  224. width: calc(100% - 10px);
  225. }
  226. </style>