range.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <div class="map-range">
  3. <div class="fwlxrange">
  4. <div :class="model.xzmj == 0 ? 'pointer' : ''" @click="drawMap">
  5. <el-button plain v-if="model.xzmj == 0" icon="edit-pen" size="mini"
  6. >绘制</el-button
  7. >
  8. <span v-if="model.xzmj != 0">{{ model.xzmj }} m²</span>
  9. </div>
  10. <el-upload
  11. class="upload-demo"
  12. :on-change="handleChange"
  13. :auto-upload="false"
  14. :show-file-list="false"
  15. :file-list="fileList"
  16. >
  17. <el-tooltip
  18. v-if="fileList.length > 0"
  19. :content="fileList[0].name"
  20. placement="bottom-start"
  21. effect="light"
  22. >
  23. <span class="title-item" style="display: inline-block; width: 100%">{{
  24. fileList[0].name
  25. }}</span>
  26. </el-tooltip>
  27. <el-button v-else class="upload-btn" icon="Upload" size="mini"
  28. >导入</el-button
  29. >
  30. </el-upload>
  31. <div class="clear" @click="clearAll">清除</div>
  32. </div>
  33. </div>
  34. </template>
  35. <script>
  36. import { ShapeUpload } from "@/api/ghss/hgxfx.js";
  37. import { ElMessage } from "element-ui";
  38. export default {
  39. components: {},
  40. props: {
  41. //启用的组件,不传为所有
  42. keys: {
  43. type: Array,
  44. default: ["xzq", "hx", "sc", "zbd"],
  45. },
  46. activeTabs: {
  47. type: String,
  48. },
  49. },
  50. data() {
  51. return {
  52. userXZQ: "", //store.state.user.user.dept.district,
  53. fwlist: {
  54. xzq: {
  55. id: 0,
  56. name: "行政区",
  57. icon: "wind-power",
  58. },
  59. hx: {
  60. id: 1,
  61. name: "绘制",
  62. icon: "Share",
  63. },
  64. sc: {
  65. id: 2,
  66. name: "上传",
  67. icon: "Upload-filled",
  68. },
  69. zbd: {
  70. id: 3,
  71. name: "坐标点",
  72. icon: "Location",
  73. },
  74. },
  75. model: {
  76. fwlx: 0,
  77. xzfw: "",
  78. xzmj: 0,
  79. feature: null,
  80. },
  81. handlerDraw: null,
  82. draw: null, //绘制
  83. fileList: [], //文件
  84. };
  85. },
  86. mounted() {
  87. this.model.fwlx = this.fwlist[this.$props.keys[0]].id;
  88. },
  89. methods: {
  90. //切换
  91. onChangeRange(fwlx) {
  92. this.clearAll();
  93. this.model.fwlx = fwlx;
  94. },
  95. //上传文件
  96. handleChange(file, fileList) {
  97. if (fileList.length > 0) {
  98. this.fileList = [fileList[fileList.length - 1]]; //这一步,是展示最后一次选择文件
  99. this.clearAll();
  100. }
  101. const formdata = new FormData();
  102. formdata.append("file", file.raw);
  103. this.addPolygon();
  104. ShapeUpload(formdata).then((res) => {
  105. if (res.success) {
  106. // var layer = myMap.addGeoJson("common_layer", res.data.geojson);
  107. // var url = `${SYS_LAYERS.XZQXZ}/0/query`;
  108. // var geom = layer.getSource().getFeatures()[0].getGeometry();
  109. // 判断绘制范围是否在行政区范围内
  110. let withinRange = true;
  111. // arcMap.SearchWfsData(url, geom, function (fs) {
  112. // if (fs.length) {
  113. // fs.map((res) => {
  114. // let xzqdm = res.get("XZQDM");
  115. // if (!xzqdm.startsWith(this.userXZQ)) {
  116. // withinRange = false;
  117. // }
  118. // });
  119. // } else {
  120. // withinRange = false;
  121. // }
  122. if (withinRange) {
  123. this.model.xzfw = res.data.filepath;
  124. // this.model.feature = layer.getSource().getFeatures()[0];
  125. // this.model.xzmj = new OLTool().Tools.formatArea(
  126. // this.model.feature.getGeometry(),
  127. // true
  128. // );
  129. // myMap.zoomToextent(layer.getSource().getExtent());
  130. } else {
  131. // this.clearAll();
  132. // ElMessage.warning("分析范围超出了权限范围,请重新上传文件!");
  133. }
  134. // });
  135. }
  136. });
  137. },
  138. // 加载GeoJSON数据
  139. addPolygon() {
  140. // let geojson = CX_geojeson;
  141. let polygon = Cesium.GeoJsonDataSource.load(
  142. "/static/data/ghss/导入.geojson"
  143. // { clampToGround: true }
  144. );
  145. polygon.then(function (dataSource) {
  146. // 将数据源添加到Cesium Viewer
  147. viewer.dataSources.add(dataSource);
  148. viewer.zoomTo(dataSource);
  149. // 可以获取实体并进行操作
  150. // var entities = dataSource.entities.values;
  151. // for (var i = 0; i < entities.length; i++) {
  152. // var entity = entities[i];
  153. // // 你可以在这里设置实体的属性,例如位置、颜色等
  154. // }
  155. });
  156. },
  157. //绘制
  158. drawMap() {
  159. if (!window.handlerPolygon) {
  160. common.initHandler("Polygon");
  161. }
  162. common.handlerDrawing("Polygon").then(
  163. (res) => {
  164. console.log(res.positions, "------");
  165. },
  166. (err) => {
  167. console.log(err);
  168. }
  169. );
  170. window.handlerPolygon.activate();
  171. },
  172. clear() {
  173. if (this.handlerDraw != null) {
  174. this.handlerDraw.clear();
  175. viewer.scene.globe.removeAllExcavationRegion();
  176. this.handlerDraw.deactivate();
  177. this.handlerDraw = null;
  178. this.result = null;
  179. }
  180. },
  181. //清除
  182. clearAll() {
  183. this.model.xzfw = "";
  184. this.model.xzmj = 0;
  185. common.clearHandlerDrawing("Polygon");
  186. },
  187. //输出:重置
  188. reset() {
  189. this.model = {
  190. fwlx: this.fwlist[this.$props.keys[0]].id,
  191. xzfw: "",
  192. xzmj: 0,
  193. };
  194. this.fileList = []; //文件
  195. this.clearAll();
  196. },
  197. //输出:获取范围
  198. getRange() {
  199. return this.model;
  200. },
  201. },
  202. // watch(
  203. // () => prop.activeTabs,
  204. // (newValue, oldValue) => {
  205. // this.getXzq();
  206. // }
  207. // );
  208. };
  209. </script>
  210. <style lang="scss" scoped>
  211. .map-range {
  212. width: 100px;
  213. // height: 100px;
  214. color: #fff;
  215. .xz_type {
  216. margin-bottom: 10px;
  217. // display: flex;
  218. // justify-content: space-between;
  219. .keyitem {
  220. width: 100px;
  221. height: 30px;
  222. font-size: 16px;
  223. line-height: 30px;
  224. display: inline-block;
  225. cursor: pointer;
  226. }
  227. }
  228. .fwlxrange {
  229. display: flex;
  230. justify-content: space-between;
  231. text-align: center;
  232. .clear {
  233. width: 80px;
  234. }
  235. }
  236. }
  237. </style>