analysis-data.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <script setup>
  2. /**
  3. * element-plus组件
  4. */
  5. import {
  6. ElMessage
  7. } from 'element-plus';
  8. import {
  9. inject
  10. } from "vue";
  11. const getMapInstance = inject("getMapInstance");
  12. jt3d = getMapInstance();
  13. </script>
  14. <template>
  15. <div class="jt-analysisData">
  16. <el-collapse v-model="activeName" accordion>
  17. <el-upload drag :auto-upload=false action="" accept="shp" :on-preview="handlePreview" :on-remove="handleRemove" :on-change="bind">
  18. <i class="el-icon-upload"></i>
  19. <div class="el-upload__text">将shp文件拖到此处,或<em>点击上传</em></div>
  20. <!-- <div class="el-upload__tip" slot="tip">必须是shp文件</div> -->
  21. <span>
  22. <el-icon>
  23. <WarnTriangleFilled />
  24. </el-icon>必须是shp文件
  25. </span>
  26. </el-upload>
  27. <!-- <el-button style="margin-left: 10rem;" size="small" type="success" @click="config">生成GeoJson数据</el-button> -->
  28. </el-collapse>
  29. </div>
  30. </template>
  31. <script>
  32. import {
  33. open
  34. } from 'shapefile'
  35. let jt3d = undefined;
  36. export default {
  37. props: {},
  38. watch: {
  39. },
  40. name: "Config",
  41. data() {
  42. return {
  43. file: {},
  44. filelist: [],
  45. }
  46. },
  47. /* 方法 */
  48. methods: {
  49. /* shp文件解析生成图形 */
  50. config() {
  51. let _this = this
  52. const name = this.file.name
  53. const extension = name.split('.')[1]
  54. console.log(extension)
  55. if ('shp' !== extension) {
  56. this.$alert('文件不是shp文件!请重新选择文件', {
  57. confirmButtonText: '确定'
  58. })
  59. } else {
  60. const reader = new FileReader()
  61. const fileData = this.file.raw
  62. reader.readAsArrayBuffer(fileData)
  63. reader.onload = function(e) {
  64. open(this.result).then(source => source.read().then(function log(result) {
  65. if (result.done) return;
  66. console.log(result)
  67. console.log(result.value);
  68. let promise = Cesium.GeoJsonDataSource.load(result.value, {
  69. clampToGround: true
  70. });
  71. promise.then((dataSource) => {
  72. window["viewer"].dataSources.add(dataSource); // 加载这个geojson资源
  73. dataSource.name = name.split('.')[0];
  74. console.log(dataSource)
  75. const entities = dataSource.entities.values;
  76. for (let index = 0; index < entities.length; index++) {
  77. const entity = entities[index];
  78. entity.polygon.material = Cesium.Color.fromBytes(50, 160, 255, 77)
  79. entity.polygon.outlineWidth = 3;
  80. entity.polygon.outline = false;
  81. entity.polygon.outlineColor = Cesium.Color.RED;
  82. entity.polyline = {
  83. positions: entity.polygon.hierarchy._value.positions,
  84. width: entity.polygon.outlineWidth,
  85. material: Cesium.Color.fromBytes(0, 255, 180, 255),
  86. clampToGround: true
  87. }
  88. }
  89. let options = {};
  90. // 初始化参数默认值
  91. options.duration = Cesium.defaultValue(options.duration, 2);
  92. options.heading = Cesium.defaultValue(options.heading, 0);
  93. options.pitch = Cesium.defaultValue(options.pitch, -60);
  94. options.range = Cesium.defaultValue(options.range, 0.0);
  95. let flyPromise = window["viewer"].flyTo(entities, {
  96. duration: options.duration,
  97. offset: {
  98. heading: Cesium.Math.toRadians(options.heading),
  99. pitch: Cesium.Math.toRadians(options.pitch),
  100. range: options.range
  101. }
  102. });
  103. });
  104. return source.read().then(log);
  105. })).catch(error => console.error(error.stack));
  106. }
  107. }
  108. },
  109. remove() {
  110. },
  111. //移除
  112. handleRemove(file, fileList) {
  113. /* 清除图形 */
  114. console.log(file, fileList);
  115. let list = window["viewer"].dataSources.getByName(file.name.split('.')[0])
  116. // for(let i=0;i<list.length;i++){
  117. // console.log(list.length)
  118. // window["viewer"].dataSources.remove(list[i])
  119. // }
  120. list.forEach(res => {
  121. console.log(res)
  122. window["viewer"].dataSources.remove(res)
  123. })
  124. // window["viewer"].dataSources.remove(window["viewer"].dataSources.getByName(file.name.split('.')[0]))
  125. },
  126. //定位
  127. handlePreview(file) {
  128. console.log(file)
  129. this.file = file;
  130. // this.config();
  131. let list = window["viewer"].dataSources.getByName(file.name.split('.')[0])
  132. list.forEach(res => {
  133. const entities = res.entities.values;
  134. let options = {};
  135. // 初始化参数默认值
  136. options.duration = Cesium.defaultValue(options.duration, 2);
  137. options.heading = Cesium.defaultValue(options.heading, 0);
  138. options.pitch = Cesium.defaultValue(options.pitch, -60);
  139. options.range = Cesium.defaultValue(options.range, 0.0);
  140. let flyPromise = window["viewer"].flyTo(entities, {
  141. duration: options.duration,
  142. offset: {
  143. heading: Cesium.Math.toRadians(options.heading),
  144. pitch: Cesium.Math.toRadians(options.pitch),
  145. range: options.range
  146. }
  147. });
  148. })
  149. },
  150. bind(files, fileList) {
  151. //绑定文件
  152. this.file = fileList[fileList.length - 1]
  153. //console.log(this.file)
  154. this.config();
  155. }
  156. },
  157. mounted() {
  158. }
  159. };
  160. </script>
  161. <style lang="scss" scoped>
  162. .el-upload-dragger .el-upload__text{
  163. font-size: 16rem;
  164. }
  165. .upload_demo {
  166. text-align: center;
  167. margin-top: 50rem;
  168. }
  169. .el-button {
  170. margin-top: 10rem;
  171. }
  172. ::v-deep .el-upload-dragger {
  173. padding: 0rem;
  174. margin-top: 10rem;
  175. color: #606266;
  176. font-size: 12rem;
  177. }
  178. ::v-deep .el-upload-list__item-name {
  179. color: #fff;
  180. margin-left: -21rem;
  181. }
  182. ::v-deep .el-icon svg {
  183. color: #409eff;
  184. font-size: smaller;
  185. }
  186. </style>