TerrainCutFillAnalysis.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <div v-show="isCutFill" class="cut_fill_box">
  3. <div class="cut_fill_centent1">
  4. 设计高度(米):
  5. <el-input class="cut_fill_input" v-model="height" placeholder=""></el-input>
  6. <br>
  7. 土石方量(立方米):
  8. <el-input class="cut_fill_input" v-model="result" placeholder=""></el-input>
  9. </div>
  10. <div class="cut_fill_Buttons">
  11. <el-button size="mini" type="primary" @click="draw">绘制</el-button>
  12. <el-button size="mini" type="primary" @click="clear">清除</el-button>
  13. </div>
  14. </div>
  15. </template>
  16. <script>
  17. //这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  18. import CutFillAnalysis from "./CutFillAnalysis.js"
  19. let cutFillAnalysis = null;
  20. export default {
  21. name: "TerrainCutFillAnalysis",
  22. components: {},
  23. data() {
  24. return {
  25. input: '', sharedState: store.state,
  26. height: 300,
  27. result: null,
  28. handler_Cut_fill: new Cesium.DrawHandler(viewer, Cesium.DrawMode.Polygon, 0)
  29. };
  30. },
  31. //监听属性 类似于data概念
  32. computed: {
  33. isCutFill: function () {
  34. return this.sharedState.terrain[4];
  35. },
  36. },
  37. //监控data中的数据变化
  38. watch: {},
  39. //方法集合
  40. methods: {
  41. draw() {
  42. const that = this;
  43. that.clear();
  44. // that.handler_Cut_fill.clear();
  45. // that.handler_Cut_fill.deactivate();
  46. // if (that.handler_Cut_fill.polyline) {
  47. // that.handler_Cut_fill.polyline.show = false;
  48. // }
  49. // if (that.handler_Cut_fill.polyline) {
  50. // that.handler_Cut_fill.polygon.show = false;
  51. // }
  52. // viewer.scene.globe.removeAllExcavationRegion();
  53. var tooltip = createTooltip(viewer._element);
  54. //绘制多边形
  55. that.handler_Cut_fill.activeEvt.addEventListener(function (isActive) {
  56. if (isActive == true) {
  57. viewer.enableCursorStyle = false;
  58. viewer._element.style.cursor = '';
  59. // $('body').removeClass('drawCur').addClass('drawCur');
  60. }
  61. else {
  62. viewer.enableCursorStyle = true;
  63. // $('body').removeClass('drawCur');
  64. }
  65. });
  66. that.handler_Cut_fill.movingEvt.addEventListener(function (windowPosition) {
  67. if (windowPosition.x < 200 && windowPosition.y < 150) {
  68. tooltip.setVisible(false);
  69. return;
  70. }
  71. if (that.handler_Cut_fill.isDrawing) {
  72. tooltip.showAt(windowPosition, '<p>点击确定开挖区域中间点</p><p>右键单击结束绘制,进行开挖</p>');
  73. }
  74. else {
  75. tooltip.showAt(windowPosition, '<p>点击绘制开挖区域第一个点</p>');
  76. }
  77. });
  78. that.handler_Cut_fill.drawEvt.addEventListener(function (result) {
  79. if (!result.object.positions) {
  80. tooltip.showAt(result, '<p>请绘制正确的多边形</p>');
  81. that.handler_Cut_fill.polygon.show = false;
  82. that.handler_Cut_fill.polyline.show = false;
  83. that.handler_Cut_fill.deactivate();
  84. that.handler_Cut_fill.activate();
  85. return;
  86. };
  87. var array = [].concat(result.object.positions);
  88. tooltip.setVisible(false);
  89. var positions = [];
  90. for (var i = 0, len = array.length; i < len; i++) {
  91. var cartographic = Cesium.Cartographic.fromCartesian(array[i]);
  92. var longitude = Cesium.Math.toDegrees(cartographic.longitude);
  93. var latitude = Cesium.Math.toDegrees(cartographic.latitude);
  94. var h = cartographic.height;
  95. if (positions.indexOf(longitude) == -1 && positions.indexOf(latitude) == -1) {
  96. positions.push(longitude);
  97. positions.push(latitude);
  98. positions.push(h);
  99. }
  100. }
  101. viewer.scene.globe.removeAllExcavationRegion();
  102. viewer.scene.globe.addExcavationRegion({
  103. name: 'ggg',
  104. position: positions,
  105. height: Number(that.height),
  106. transparent: false
  107. });
  108. that.handler_Cut_fill.polygon.show = false;
  109. that.handler_Cut_fill.polyline.show = false;
  110. that.handler_Cut_fill.deactivate();
  111. // that.handler_Cut_fill.activate();
  112. });
  113. that.handler_Cut_fill.activate();
  114. },
  115. clear() {
  116. const that = this;
  117. that.handler_Cut_fill.clear();
  118. viewer.scene.globe.removeAllExcavationRegion();
  119. that.result = null;
  120. }
  121. },
  122. beforeCreate() { }, //生命周期 - 创建之前
  123. created() {
  124. const terrainP = new Cesium.CesiumTerrainProvider({
  125. url: 'http://192.168.60.3:8099/iserver/services/3D-local3DCache-SanYaDSMHuanCun/rest/realspace/datas/dsm@dsm',
  126. isSct: true//地形服务源自SuperMap iServer发布时需设置isSct为true
  127. });
  128. // const terrainP = new Cesium.CesiumTerrainProvider({
  129. // url: 'https://www.supermapol.com/realspace/services/3D-stk_terrain/rest/realspace/datas/info/data/path',
  130. // requestWaterMask: true,
  131. // requestVertexNormals: true,
  132. // isSct: false,
  133. // });
  134. // // 设置相机视角
  135. // viewer.scene.camera.setView({
  136. // destination: Cesium.Cartesian3.fromDegrees(88.3648, 29.0946, 90000),
  137. // orientation: {
  138. // heading: 6.10547067016156,
  139. // pitch: -0.8475077031996778,
  140. // roll: 6.2831853016686185
  141. // }
  142. // });
  143. viewer.terrainProvider = terrainP;
  144. viewer.scene.globe.depthTestAgainstTerrain = false;
  145. }, //生命周期 - 创建完成(可以访问当前this实例)
  146. beforeMount() { }, //生命周期 - 挂载之前
  147. mounted() {
  148. cutFillAnalysis = new CutFillAnalysis(
  149. viewer,
  150. 80,
  151. );
  152. }, //生命周期 - 挂在完成
  153. beforeUpdate() { }, //生命周期 - 更新之前
  154. updated() { }, //生命周期 - 更新之后
  155. beforeDestroy() { }, //生命周期 - 销毁之前
  156. destroy() { },//生命周期 - 销毁完成
  157. activated() { }, //若组件实例是 <KeepAlive> 缓存树的一部分,当组件被插入到 DOM 中时调用。
  158. deactivated() { } //若组件实例是 <KeepAlive> 缓存树的一部分,当组件从 DOM 中被移除时调用。
  159. };
  160. </script>
  161. <style lang="scss" scoped>
  162. .cut_fill_centent1 {
  163. width: 100%;
  164. text-align: left;
  165. margin-left: 10%;
  166. margin-top: 5%;
  167. margin-bottom: 6%;
  168. }
  169. .cut_fill_input {
  170. display: inline-block;
  171. width: 50%
  172. }
  173. .cut_fill_input:first-child {
  174. margin-left: 7%;
  175. margin-bottom: 5%;
  176. }
  177. .cut_fill_Buttons {
  178. margin-bottom: 5%;
  179. }
  180. </style>