Smashing.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <div v-show="smashingComb">
  3. <div>
  4. <!-- <div class="sm-point media-hidden"></div>
  5. <label class="sm-function-module-sub-section-setting media-hidden">{{
  6. Resource.ObserverInformation
  7. }}</label> -->
  8. <div class="boxchild">
  9. <el-button type="primary" size="mini" @click="createSmashing"
  10. >倾斜压平</el-button
  11. >
  12. <el-button type="primary" size="mini" @click="clear">{{
  13. Resource.clear
  14. }}</el-button>
  15. </div>
  16. </div>
  17. </div>
  18. </template>
  19. <script>
  20. let cutFillAnalysis = null;
  21. export default {
  22. name: "Sm3dSmashing",
  23. props: {},
  24. data() {
  25. return {
  26. inited: false,
  27. sharedState: store.state,
  28. handler_Cut_fill: null,
  29. //存储压平数据名称
  30. flattenNames: [],
  31. handlerTemp: null,
  32. };
  33. },
  34. computed: {
  35. smashingComb: function () {
  36. return this.sharedState.analysis[5];
  37. },
  38. analysisShow: function () {
  39. return this.sharedState.toolBar[6];
  40. },
  41. },
  42. beforeDestroy() {},
  43. mounted() {},
  44. methods: {
  45. //压平测试方法
  46. tempTest() {
  47. let pos = [
  48. 109.61859827027874, 18.321966806715164, -1.2607129544892512,
  49. 109.62636359998885, 18.321805377984234, -1.2572823282163708,
  50. 109.62492348975545, 18.299342421648266, -0.8778970374238814,
  51. 109.62015920613872, 18.29884447877476, -0.8767527547718837,
  52. ];
  53. let aaa = store.state.tempLatData[0];
  54. this.flattenNames = [];
  55. //遍历所有s3m图层,设置压平
  56. for (var i = 0; i < aaa.length; i++) {
  57. let nameStr = "flatten" + new Date().getTime();
  58. aaa[i].addFlattenRegion({
  59. position: pos,
  60. name: nameStr,
  61. });
  62. this.flattenNames.push(nameStr);
  63. }
  64. },
  65. createSmashing() {
  66. //绘制多边形
  67. const that = this;
  68. let tooltip = createTooltip(document.body);
  69. that.clear();
  70. if (that.handler_Cut_fill == null) {
  71. that.handler_Cut_fill = new Cesium.DrawHandler(
  72. viewer,
  73. Cesium.DrawMode.Polygon,
  74. 0
  75. );
  76. }
  77. that.handler_Cut_fill.activeEvt.addEventListener(function (isActive) {
  78. if (isActive == true) {
  79. viewer.enableCursorStyle = false;
  80. viewer._element.style.cursor = "";
  81. } else {
  82. viewer.enableCursorStyle = true;
  83. }
  84. });
  85. that.handler_Cut_fill.movingEvt.addEventListener(function (
  86. windowPosition
  87. ) {
  88. if (windowPosition.x < 200 && windowPosition.y < 150) {
  89. tooltip.setVisible(false);
  90. return;
  91. }
  92. if (that.handler_Cut_fill.isDrawing) {
  93. tooltip.showAt(
  94. windowPosition,
  95. "<p>点击确定压平区域中间点</p><p>右键单击结束绘制,进行压平</p>"
  96. );
  97. } else {
  98. tooltip.showAt(windowPosition, "<p>点击绘制压平区域第一个点</p>");
  99. }
  100. });
  101. that.handler_Cut_fill.drawEvt.addEventListener(function (result) {
  102. if (!result.object.positions) {
  103. tooltip.showAt(result, "<p>请绘制正确的多边形</p>");
  104. that.handler_Cut_fill.polygon.show = false;
  105. that.handler_Cut_fill.polyline.show = false;
  106. that.handler_Cut_fill.deactivate();
  107. that.handler_Cut_fill.activate();
  108. return;
  109. }
  110. var array = [].concat(result.object.positions);
  111. tooltip.setVisible(false);
  112. var positions = [];
  113. for (var i = 0, len = array.length; i < len; i++) {
  114. var cartographic = Cesium.Cartographic.fromCartesian(array[i]);
  115. var longitude = Cesium.Math.toDegrees(cartographic.longitude);
  116. var latitude = Cesium.Math.toDegrees(cartographic.latitude);
  117. var h = cartographic.height;
  118. if (
  119. positions.indexOf(longitude) == -1 &&
  120. positions.indexOf(latitude) == -1
  121. ) {
  122. positions.push(longitude);
  123. positions.push(latitude);
  124. positions.push(h);
  125. }
  126. }
  127. viewer.scene.globe.removeAllExcavationRegion();
  128. let s3mLayers = store.state.tempLatData[0];
  129. //遍历所有s3m图层,设置压平
  130. for (var i = 0; i < s3mLayers.length; i++) {
  131. let nameStr = "flatten" + new Date().getTime(); //创建唯一名称
  132. //倾斜影像压平处理
  133. s3mLayers[i].addFlattenRegion({
  134. position: positions,
  135. name: nameStr,
  136. });
  137. //推送压平实体名称
  138. this.flattenNames.push(nameStr);
  139. }
  140. positions = [];
  141. that.handler_Cut_fill.polygon.show = false;
  142. that.handler_Cut_fill.polyline.show = false;
  143. that.handler_Cut_fill.deactivate();
  144. });
  145. that.handler_Cut_fill.activate();
  146. },
  147. clear() {
  148. const that = this;
  149. if (that.handler_Cut_fill != null) {
  150. that.handler_Cut_fill.clear();
  151. viewer.scene.globe.removeAllExcavationRegion();
  152. that.handler_Cut_fill.deactivate();
  153. that.handler_Cut_fill = null;
  154. that.value = "";
  155. }
  156. if (this.flattenNames.length) {
  157. //图层数据
  158. let layersData = store.state.tempLatData[0];
  159. //遍历所有s3m图层,删除压平
  160. for (var i = 0; i < layersData.length; i++) {
  161. layersData[i].removeFlattenRegion(this.flattenNames[i]);
  162. this.flattenNames.push(nameStr);
  163. }
  164. this.flattenNames = [];
  165. }
  166. },
  167. },
  168. watch: {
  169. smashingComb(val) {
  170. if (!this.inited) {
  171. this.inited = !this.inited;
  172. this.handler_Cut_fill = new Cesium.DrawHandler(
  173. viewer,
  174. Cesium.DrawMode.Polygon,
  175. 0
  176. );
  177. this.handlerTemp = new Cesium.ScreenSpaceEventHandler(
  178. viewer.scene.canvas
  179. );
  180. }
  181. },
  182. },
  183. };
  184. </script>
  185. <style lang="scss" scoped></style>