Smashing.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. createSmashing() {
  46. //绘制多边形
  47. const that = this;
  48. let tooltip = createTooltip(document.body);
  49. that.clear();
  50. if (that.handler_Cut_fill == null) {
  51. that.handler_Cut_fill = new Cesium.DrawHandler(
  52. viewer,
  53. Cesium.DrawMode.Polygon,
  54. 0
  55. );
  56. }
  57. that.handler_Cut_fill.activeEvt.addEventListener(function (isActive) {
  58. if (isActive == true) {
  59. viewer.enableCursorStyle = false;
  60. viewer._element.style.cursor = "";
  61. } else {
  62. viewer.enableCursorStyle = true;
  63. }
  64. });
  65. that.handler_Cut_fill.movingEvt.addEventListener(function (
  66. windowPosition
  67. ) {
  68. if (windowPosition.x < 200 && windowPosition.y < 150) {
  69. tooltip.setVisible(false);
  70. return;
  71. }
  72. if (that.handler_Cut_fill.isDrawing) {
  73. tooltip.showAt(
  74. windowPosition,
  75. "<p>点击确定压平区域中间点</p><p>右键单击结束绘制,进行压平</p>"
  76. );
  77. } else {
  78. tooltip.showAt(windowPosition, "<p>点击绘制压平区域第一个点</p>");
  79. }
  80. });
  81. that.handler_Cut_fill.drawEvt.addEventListener(function (result) {
  82. if (!result.object.positions) {
  83. tooltip.showAt(result, "<p>请绘制正确的多边形</p>");
  84. that.handler_Cut_fill.polygon.show = false;
  85. that.handler_Cut_fill.polyline.show = false;
  86. that.handler_Cut_fill.deactivate();
  87. that.handler_Cut_fill.activate();
  88. return;
  89. }
  90. var array = [].concat(result.object.positions);
  91. tooltip.setVisible(false);
  92. var positions = [];
  93. for (var i = 0, len = array.length; i < len; i++) {
  94. var cartographic = Cesium.Cartographic.fromCartesian(array[i]);
  95. var longitude = Cesium.Math.toDegrees(cartographic.longitude);
  96. var latitude = Cesium.Math.toDegrees(cartographic.latitude);
  97. var h = cartographic.height;
  98. if (
  99. positions.indexOf(longitude) == -1 &&
  100. positions.indexOf(latitude) == -1
  101. ) {
  102. positions.push(longitude);
  103. positions.push(latitude);
  104. positions.push(h);
  105. }
  106. }
  107. viewer.scene.globe.removeAllExcavationRegion();
  108. let s3mLayers = store.state.tempLatData[0];
  109. //遍历所有s3m图层,设置压平
  110. for (var i = 0; i < s3mLayers.length; i++) {
  111. let nameStr = "flatten" + new Date().getTime(); //创建唯一名称
  112. //倾斜影像压平处理
  113. s3mLayers[i].addFlattenRegion({
  114. position: positions,
  115. name: nameStr,
  116. });
  117. //推送压平实体名称
  118. that.flattenNames.push(nameStr);
  119. }
  120. positions = [];
  121. that.handler_Cut_fill.polygon.show = false;
  122. that.handler_Cut_fill.polyline.show = false;
  123. that.handler_Cut_fill.deactivate();
  124. });
  125. that.handler_Cut_fill.activate();
  126. },
  127. clear() {
  128. const that = this;
  129. if (that.handler_Cut_fill != null) {
  130. that.handler_Cut_fill.clear();
  131. viewer.scene.globe.removeAllExcavationRegion();
  132. that.handler_Cut_fill.deactivate();
  133. that.handler_Cut_fill = null;
  134. that.value = "";
  135. }
  136. if (this.flattenNames.length) {
  137. //图层数据
  138. let layersData = store.state.tempLatData[0];
  139. //遍历所有s3m图层,删除压平
  140. for (var i = 0; i < layersData.length; i++) {
  141. layersData[i].removeFlattenRegion(this.flattenNames[i]);
  142. // this.flattenNames.push(nameStr);
  143. }
  144. this.flattenNames = [];
  145. }
  146. },
  147. },
  148. watch: {
  149. smashingComb(val) {
  150. if (!this.inited) {
  151. this.inited = !this.inited;
  152. this.handler_Cut_fill = new Cesium.DrawHandler(
  153. viewer,
  154. Cesium.DrawMode.Polygon,
  155. 0
  156. );
  157. this.handlerTemp = new Cesium.ScreenSpaceEventHandler(
  158. viewer.scene.canvas
  159. );
  160. }
  161. },
  162. },
  163. };
  164. </script>
  165. <style lang="scss" scoped></style>