range.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. :limit="1"
  17. >
  18. <el-tooltip
  19. v-if="fileList.length > 0"
  20. :content="fileList[0].name"
  21. placement="bottom-start"
  22. effect="light"
  23. >
  24. <span class="title-item" style="display: inline-block; width: 100%">{{
  25. fileList[0].name
  26. }}</span>
  27. </el-tooltip>
  28. <el-button v-else class="upload-btn" icon="Upload" size="mini"
  29. >导入</el-button
  30. >
  31. </el-upload>
  32. <div class="clear" @click="clearAll">清除</div>
  33. </div>
  34. </div>
  35. </template>
  36. <script>
  37. import { ShapeUpload } from "@/api/ghss/hgxfx.js";
  38. import { ElMessage } from "element-ui";
  39. export default {
  40. components: {},
  41. props: {
  42. //启用的组件,不传为所有
  43. keys: {
  44. type: Array,
  45. default: ["xzq", "hx", "sc", "zbd"],
  46. },
  47. activeTabs: {
  48. type: String,
  49. },
  50. type: {
  51. type: String,
  52. },
  53. },
  54. data() {
  55. return {
  56. userXZQ: "", //store.state.user.user.dept.district,
  57. fwlist: {
  58. xzq: {
  59. id: 0,
  60. name: "行政区",
  61. icon: "wind-power",
  62. },
  63. hx: {
  64. id: 1,
  65. name: "绘制",
  66. icon: "Share",
  67. },
  68. sc: {
  69. id: 2,
  70. name: "上传",
  71. icon: "Upload-filled",
  72. },
  73. zbd: {
  74. id: 3,
  75. name: "坐标点",
  76. icon: "Location",
  77. },
  78. },
  79. model: {
  80. fwlx: 0,
  81. xzfw: "",
  82. xzmj: 0,
  83. feature: null,
  84. },
  85. handlerDraw: null,
  86. draw: null, //绘制
  87. fileList: [], //文件
  88. fileDataID: "", //存储上传文件获取到的id
  89. };
  90. },
  91. mounted() {
  92. this.model.fwlx = this.fwlist[this.$props.keys[0]].id;
  93. },
  94. methods: {
  95. //切换
  96. onChangeRange(fwlx) {
  97. this.clearAll();
  98. this.model.fwlx = fwlx;
  99. },
  100. //上传文件
  101. handleChange(file, fileList) {
  102. if (fileList.length > 0) {
  103. this.fileList = [fileList[fileList.length - 1]]; //这一步,是展示最后一次选择文件
  104. this.clearAll();
  105. }
  106. const formdata = new FormData();
  107. formdata.append("file", file.raw);
  108. formdata.append("fromType", 2);
  109. formdata.append("fromRoute", this.$route.path);
  110. // this.addPolygon();
  111. ShapeUpload(formdata).then((res) => {
  112. if (res.success) {
  113. viewer.entities.removeAll();
  114. this.fileDataID = res.data.id;
  115. let geoms = res.data.geom
  116. .substring(
  117. res.data.geom.indexOf("(((") + 3,
  118. res.data.geom.length - 3
  119. )
  120. .split(")),((");
  121. for (let i = 0; i < geoms.length; i++) {
  122. let geom = geoms[i].split(",");
  123. let points = [];
  124. for (let j = 0; j < geom.length; j++) {
  125. points.push(parseFloat(geom[j].split(" ")[0]));
  126. points.push(parseFloat(geom[j].split(" ")[1]));
  127. }
  128. points.push(parseFloat(geom[0].split(" ")[0]));
  129. points.push(parseFloat(geom[0].split(" ")[1]));
  130. viewer.entities.add({
  131. // polyline: new Cesium.PolylineGraphics({
  132. // positions: Cesium.Cartesian3.fromDegreesArray(points),
  133. // width: 3,
  134. // material: Cesium.Color.BLUE.withAlpha(0.9),
  135. // clampToGround: true,
  136. // }),
  137. polygon: {
  138. hierarchy: {
  139. positions: Cesium.Cartesian3.fromDegreesArray(points),
  140. },
  141. material: Cesium.Color.WHITE.withAlpha(0.3),
  142. clampToGround: true,
  143. outline: true,
  144. outlineWidth: 5,
  145. outlineColor: Cesium.Color.BLUE,
  146. },
  147. });
  148. }
  149. viewer.flyTo(viewer.entities);
  150. }
  151. });
  152. },
  153. //上传文件
  154. handleChange1(file, fileList) {
  155. if (fileList.length > 0) {
  156. this.fileList = [fileList[fileList.length - 1]]; //这一步,是展示最后一次选择文件
  157. this.clearAll();
  158. }
  159. const formdata = new FormData();
  160. formdata.append("file", file.raw);
  161. this.addPolygon();
  162. // ShapeUpload(formdata).then((res) => {
  163. // if (res.success) {
  164. // // var layer = myMap.addGeoJson("common_layer", res.data.geojson);
  165. // // var url = `${SYS_LAYERS.XZQXZ}/0/query`;
  166. // // var geom = layer.getSource().getFeatures()[0].getGeometry();
  167. // // 判断绘制范围是否在行政区范围内
  168. // let withinRange = true;
  169. // // arcMap.SearchWfsData(url, geom, function (fs) {
  170. // // if (fs.length) {
  171. // // fs.map((res) => {
  172. // // let xzqdm = res.get("XZQDM");
  173. // // if (!xzqdm.startsWith(this.userXZQ)) {
  174. // // withinRange = false;
  175. // // }
  176. // // });
  177. // // } else {
  178. // // withinRange = false;
  179. // // }
  180. // if (withinRange) {
  181. // this.model.xzfw = res.data.filepath;
  182. // // this.model.feature = layer.getSource().getFeatures()[0];
  183. // // this.model.xzmj = new OLTool().Tools.formatArea(
  184. // // this.model.feature.getGeometry(),
  185. // // true
  186. // // );
  187. // // myMap.zoomToextent(layer.getSource().getExtent());
  188. // } else {
  189. // // this.clearAll();
  190. // // ElMessage.warning("分析范围超出了权限范围,请重新上传文件!");
  191. // }
  192. // // });
  193. // }
  194. // });
  195. },
  196. // 加载GeoJSON数据
  197. addPolygon() {
  198. let geojson =
  199. this.$props.type == "hegxfx"
  200. ? "/static/data/ghss/导入.geojson"
  201. : "static/data/draw.geojson";
  202. let polygon = Cesium.GeoJsonDataSource.load(geojson, {
  203. // clampToGround: true
  204. stroke: Cesium.Color.RED,
  205. fill: Cesium.Color.WHITE.withAlpha(0.3),
  206. strokeWidth: 5,
  207. });
  208. polygon.then(function (dataSource) {
  209. // 将数据源添加到Cesium Viewer
  210. viewer.dataSources.add(dataSource);
  211. viewer.zoomTo(dataSource);
  212. // 可以获取实体并进行操作
  213. // var entities = dataSource.entities.values;
  214. // for (var i = 0; i < entities.length; i++) {
  215. // var entity = entities[i];
  216. // // 你可以在这里设置实体的属性,例如位置、颜色等
  217. // }
  218. });
  219. },
  220. //绘制
  221. drawMap() {
  222. if (!window.handlerPolygon) {
  223. common.initHandler("Polygon");
  224. }
  225. common.handlerDrawing("Polygon").then(
  226. (res) => {
  227. console.log(res.positions, "------");
  228. },
  229. (err) => {
  230. console.log(err);
  231. }
  232. );
  233. window.handlerPolygon.activate();
  234. },
  235. clear() {
  236. if (this.handlerDraw != null) {
  237. this.handlerDraw.clear();
  238. viewer.scene.globe.removeAllExcavationRegion();
  239. this.handlerDraw.deactivate();
  240. this.handlerDraw = null;
  241. this.result = null;
  242. }
  243. },
  244. //清除
  245. clearAll() {
  246. //销毁上传创建的面
  247. viewer.entities.removeAll();
  248. this.model.xzfw = "";
  249. this.model.xzmj = 0;
  250. common.clearHandlerDrawing("Polygon");
  251. },
  252. //输出:重置
  253. reset() {
  254. this.model = {
  255. fwlx: this.fwlist[this.$props.keys[0]].id,
  256. xzfw: "",
  257. xzmj: 0,
  258. };
  259. this.fileList = []; //文件
  260. this.clearAll();
  261. },
  262. //输出:获取范围
  263. getRange() {
  264. return this.model;
  265. },
  266. },
  267. };
  268. </script>
  269. <style lang="scss" scoped>
  270. .map-range {
  271. width: 100px;
  272. // height: 100px;
  273. color: #fff;
  274. .xz_type {
  275. margin-bottom: 10px;
  276. // display: flex;
  277. // justify-content: space-between;
  278. .keyitem {
  279. width: 100px;
  280. height: 30px;
  281. font-size: 16px;
  282. line-height: 30px;
  283. display: inline-block;
  284. cursor: pointer;
  285. }
  286. }
  287. .fwlxrange {
  288. display: flex;
  289. justify-content: space-between;
  290. text-align: center;
  291. .clear {
  292. width: 80px;
  293. }
  294. }
  295. }
  296. </style>