MapHolder.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. <template>
  2. <div id="map2DViewer">
  3. <CaseAuditPopup v-show="auditPopupShow" ref="auditRef" />
  4. <LabelCasePopup v-show="labelDetailsPopupShow" ref="labelRef" />
  5. <BasemapChange />
  6. </div>
  7. </template>
  8. <script>
  9. import publicFun from "@/utils/publicFunction.js";
  10. import transformCoord from "@/utils/coordinate";
  11. import { get } from "@/utils/request";
  12. import { streetLocation, townData } from "@/config/common";
  13. import CaseAuditPopup from "@/components/popup/CaseAuditPopup.vue";
  14. import LabelCasePopup from "@/components/popup/LabelCasePopup.vue";
  15. import BasemapChange from "@/components/map/BasemapChange.vue";
  16. export default {
  17. name: "MapHolder",
  18. components: { CaseAuditPopup, LabelCasePopup, BasemapChange },
  19. data() {
  20. return {
  21. town: "祝桥镇,南汇新城镇,川沙新镇,老港镇,惠南镇,航头镇,泥城镇,书院镇,新场镇,大团镇,唐镇,曹路镇,宣桥镇,张江镇,合庆镇,周浦镇,康桥镇,三林镇,高桥镇,高东镇,金桥镇,北蔡镇,万祥镇,高行镇",
  22. auditPopupShow: false,
  23. labelDetailsPopupShow: false,
  24. auditPopupStatus: "normal",
  25. popup: null,
  26. labelPopup: null,
  27. // 疑点审计
  28. currentCid: null,
  29. currentHtml: null,
  30. currentProperties: null,
  31. // 标记疑点
  32. currentLabelCid: null,
  33. currentLabelHtml: null,
  34. tableObj: {},
  35. // 疑点审计的保存后的疑点状态集合
  36. caseStatusMap: new Map()
  37. };
  38. },
  39. created() {},
  40. mounted() {
  41. // 监听全局事件总线中的卷帘对比事件(JLControl)
  42. this.$bus.$off("JLControl");
  43. this.$bus.$on("JLControl", () => {
  44. this.JLControl();
  45. });
  46. // 监听全局事件总线中的卷帘对比重绘事件(reJLControl)
  47. this.$bus.$off("reJLControl");
  48. this.$bus.$on("reJLControl", () => {
  49. this.reJLControl();
  50. });
  51. this.$bus.$off("caseAuditEvent");
  52. this.$bus.$on("caseAuditEvent", () => {
  53. this.caseAuditEvent();
  54. });
  55. //地图初始化
  56. this.mapInit();
  57. this.$store.state.mapMethodsCollection.set("RENDER", {
  58. addPolygonLayer: this.addPolygonLayer,
  59. setView: this.setView,
  60. deletePolygonLayer: this.deletePolygonLayer,
  61. addSinglePolygon: this.addSinglePolygon,
  62. deleteSinglePolygon: this.deleteSinglePolygon,
  63. deleteGroupFromMap: this.deleteGroupFromMap,
  64. drawGeometry: this.drawGeometry,
  65. deleteGeometry: this.deleteGeometry
  66. });
  67. },
  68. beforeDestroyed() {
  69. // 当容器销毁时,需要停止监听该事件
  70. this.$bus.$off("JLControl");
  71. // 疑点审计
  72. this.$bus.$off("caseAuditEvent");
  73. map2DViewer.map.closePopup();
  74. },
  75. computed: {
  76. // 监听底部菜单栏的状态
  77. getLabelCaseBtnStatus() {
  78. //疑点审计 1,0
  79. let _index = this.$store.state.bottomMenuIndexs.index;
  80. let _subIndex = this.$store.state.bottomMenuIndexs.subIndex;
  81. return { index: _index, subIndex: _subIndex };
  82. },
  83. // 监听当前菜单
  84. getCurrentMenu() {
  85. return this.$store.state.navSelect;
  86. }
  87. },
  88. watch: {
  89. getLabelCaseBtnStatus(val) {
  90. // console.log(val, "标记疑点");
  91. if (val.index === 1 && val.subIndex === 1) {
  92. // 删除地图上所有弹窗
  93. this.$store.state.attrTableShow = false;
  94. this.$store.state.updateCasePopupShow = false;
  95. // 删除地图上的所有标记
  96. if (map2DViewer.myLabels) {
  97. for (let i in map2DViewer.myLabels) {
  98. // console.log(i, "图层名");
  99. this.deleteGeometry(map2DViewer.myLabels[i]);
  100. map2DViewer.myLabels[i] = null;
  101. }
  102. }
  103. this.initDraw();
  104. } else {
  105. this.stopLabelCase();
  106. if (this.labelPopup) {
  107. map2DViewer.map.closePopup();
  108. this.labelPopup = null;
  109. }
  110. }
  111. },
  112. "$store.state.navSelect": {
  113. handler(val) {
  114. if (val.index !== "3") {
  115. if (map2DViewer.map.hasLayer(map2DViewer.jlMap)) {
  116. map2DViewer.map.removeControl(map2DViewer.jlControl);
  117. map2DViewer.map.removeLayer(map2DViewer.jlMap);
  118. delete map2DViewer.jlMap;
  119. map2DViewer.jlControl = null;
  120. }
  121. this.$store.state.bottomMenuIndexs.index = -1;
  122. this.$store.state.bottomMenuIndexs.subIndex = -1;
  123. this.$store.commit("changeJlActiveState", false);
  124. }
  125. // 切换页面时判断是否需要显示区域图
  126. this.$nextTick(() => {
  127. this.getJSonData();
  128. });
  129. }
  130. // immediate: true
  131. }
  132. },
  133. methods: {
  134. // 开始标记疑点事件
  135. startLabelCase() {
  136. map2DViewer.setDrawTool({ action: "start" });
  137. },
  138. // 停止标记疑点事件
  139. stopLabelCase() {
  140. if (map2DViewer.measureTool) {
  141. map2DViewer.setDrawTool({
  142. action: "remove"
  143. });
  144. }
  145. },
  146. reStartLabelCase() {
  147. this.stopLabelCase();
  148. this.initDraw();
  149. },
  150. // 常规图层弹窗
  151. createAuditDiv(str, properties) {
  152. // 根据ref获取组件的dom元素
  153. this.currentHtml = this.$refs.auditRef.$el.innerHTML;
  154. this.$refs.auditRef.tableObj = properties;
  155. if (this.currentHtml) {
  156. let div = document.createElement("div");
  157. div.id = str + "_id";
  158. div.className = "case-audit";
  159. // 动态创建div后赋值模板样式
  160. div.innerHTML = this.currentHtml;
  161. $(() => {
  162. if (properties) {
  163. $(`#${str}_id .center-table-item-normal .leftcell`).each((index, domEle) => {
  164. $(`#${str}_id .center-table-item-normal .leftcell`).eq(index).text(Object.keys(properties)[index]);
  165. });
  166. $(`#${str}_id .center-table-item-normal .rightcell`).each((index, domEle) => {
  167. $(`#${str}_id .center-table-item-normal .rightcell`).eq(index).text(Object.values(properties)[index]);
  168. });
  169. }
  170. if ($(`#${str}_id .center-table-item-special select`)) {
  171. if (this.caseStatusMap.has(str)) {
  172. $(`#${str}_id .center-table-item-special select`).val(this.caseStatusMap.get(str));
  173. }
  174. }
  175. // 法律法规点击事件
  176. if ($(`#${str}_id a`)) {
  177. $(`#${str}_id a`).click(e => {
  178. console.log(e, "显示疑点相关的弹窗");
  179. this.$store.state.lawPopupShow = true;
  180. });
  181. }
  182. // input添加点击事件
  183. if ($(`#${str}_id input`)[1]) {
  184. $(`#${str}_id input`).click(e => {
  185. switch (e.target.defaultValue) {
  186. case "取消":
  187. this.cancelBtnEvent();
  188. break;
  189. case "确认":
  190. this.confirmBtnEvent(str);
  191. break;
  192. }
  193. });
  194. }
  195. });
  196. return div;
  197. }
  198. },
  199. /**
  200. * 标记疑点完成时保存描述信息的弹窗
  201. * @str -- id
  202. * @coord -- 坐标信息
  203. * @data -- 其余数据
  204. * @geoType -- 几何体类型
  205. */
  206. createLabelDiv(str, coord, data, geoType) {
  207. console.log(str, coord, data, geoType, "createLabelDiv");
  208. console.log(str, "label - str");
  209. this.currentLabelHtml = this.$refs.labelRef.$el.innerHTML;
  210. if (this.currentLabelHtml) {
  211. let div = document.createElement("div");
  212. div.id = `${str}_id`;
  213. div.className = "label-case";
  214. // 动态创建div后赋值模板样式
  215. div.innerHTML = this.currentLabelHtml;
  216. $(() => {
  217. console.log($(`#${str}_id textarea`).val(), "textarea");
  218. $(`#${str}_id`).css("height", "100%");
  219. $(`#${str}_id input`).click(e => {
  220. console.log(e.target.defaultValue);
  221. switch (e.target.defaultValue) {
  222. case "取消":
  223. this.cancelBtnEvent();
  224. break;
  225. case "保存":
  226. this.saveBtnEvent(str, data, geoType);
  227. // console.log(str, coord, data);
  228. break;
  229. }
  230. });
  231. });
  232. return div;
  233. }
  234. },
  235. modifyBtnEvent() {
  236. console.log("用户点击了地图中的修改按钮!");
  237. },
  238. confirmBtnEvent(str) {
  239. // isTrue
  240. let selectVal = $(`#${str}_id .center-table-item-special select`).val();
  241. this.caseStatusMap.set(str, selectVal);
  242. let obj = {
  243. c_date_time: this.$dayjs().valueOf(),
  244. c_boolean: selectVal === "isTrue" ? true : false,
  245. // 修改人员名称
  246. c_editor_name: localStorage.getItem("USER_NAME"),
  247. // 修改人员ID
  248. c_editorid: localStorage.getItem("USER_ID")
  249. };
  250. let modifyParams = new FormData();
  251. modifyParams = {
  252. columnId: 47,
  253. modelId: 49,
  254. content: JSON.stringify(obj)
  255. };
  256. this.$Post(this.urlsCollection.updateContent, modifyParams).then(res => {
  257. if (res.code === 200) {
  258. this.$message.success("数据修改成功");
  259. map2DViewer.map.closePopup();
  260. }
  261. });
  262. },
  263. cancelBtnEvent() {
  264. map2DViewer.map.closePopup();
  265. this.labelPopup = null;
  266. this.popup = null;
  267. },
  268. /**
  269. * 点击保存事件时保存点数据
  270. * @str
  271. * @data -- 绘制几何体时获取的数据;
  272. * @geoType 几何体类型 类型: 0 点;1 线;2 面;3 矩形;4 圆形;5 其他;
  273. */
  274. saveBtnEvent(str, data, geoType) {
  275. if (localStorage.getItem("USER_ID")) {
  276. let title = $(`#${str}_id select`).val();
  277. let des = $(`#${str}_id textarea`).val();
  278. let coordinates = [data.points];
  279. let geometry = publicFun.generateGeoJSON(title, des, geoType, coordinates);
  280. let params = new FormData();
  281. params = {
  282. geojson: JSON.stringify(geometry),
  283. type: geoType,
  284. userId: Number(localStorage.getItem("USER_ID")),
  285. sourceId: 0
  286. };
  287. this.$Post(this.urlsCollection.addConllection, params).then(
  288. res => {
  289. if (res.code == 200) {
  290. console.log(res, "添加标记成功");
  291. map2DViewer.map.closePopup();
  292. // 根据用户获取标记
  293. let paramData = new FormData();
  294. paramData = {
  295. userId: Number(localStorage.getItem("USER_ID")),
  296. sourceId: 0,
  297. pageSize: 10
  298. };
  299. this.$Post(this.urlsCollection.selectByUser, paramData).then(userRes => {
  300. if (userRes.code === 200) {
  301. // console.log(userRes, "获取我的标记疑点数据");
  302. if (userRes.content.length > 0) {
  303. this.$store.state.myLabelPointsArr = [];
  304. this.$store.state.myLabelPointsArr = userRes.content.map(v => {
  305. return {
  306. id: v.id,
  307. geojson: v.geojson,
  308. type: v.type
  309. };
  310. });
  311. }
  312. }
  313. // 更新时调用一次搜索接口
  314. });
  315. }
  316. // 保存后需要删除地图上的标记
  317. this.reStartLabelCase();
  318. },
  319. error => {
  320. console.log("标记疑点保存失败!", error);
  321. this.reStartLabelCase();
  322. }
  323. );
  324. }
  325. },
  326. // 卷帘对比
  327. JLControl() {
  328. if (!map2DViewer.map.hasLayer(map2DViewer.jlMap)) {
  329. map2DViewer.jlMap = L.tileLayer(
  330. "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d"
  331. ).addTo(map2DViewer.map);
  332. map2DViewer.jlControl = L.control.sideBySide(map2DViewer.map, map2DViewer.jlMap).addTo(map2DViewer.map);
  333. } else if (map2DViewer.map.hasLayer(map2DViewer.jlMap)) {
  334. map2DViewer.map.removeControl(map2DViewer.jlControl);
  335. map2DViewer.map.removeLayer(map2DViewer.jlMap);
  336. delete map2DViewer.jlMap;
  337. map2DViewer.jlControl = null;
  338. }
  339. },
  340. // 卷帘对比重绘
  341. reJLControl() {
  342. if (map2DViewer.map.hasLayer(map2DViewer.jlMap)) {
  343. map2DViewer.map.removeControl(map2DViewer.jlControl);
  344. map2DViewer.map.removeLayer(map2DViewer.jlMap);
  345. delete map2DViewer.jlMap;
  346. map2DViewer.jlControl = null;
  347. this.JLControl();
  348. }
  349. },
  350. // 疑点审计
  351. caseAuditEvent() {
  352. // 每次点击按钮后重绘弹窗
  353. if (this.currentHtml && this.currentCid) {
  354. setTimeout(() => {
  355. this.popup.setContent(this.createAuditDiv(this.currentCid, this.currentProperties));
  356. // .openOn(map2DViewer.map);
  357. }, 300);
  358. }
  359. },
  360. // 初始化引入绘制工具
  361. initDraw() {
  362. if (!map2DViewer.measureTool) {
  363. // 引入疑点标记绘制方法
  364. map2DViewer.drawToolFire = data => {
  365. // 纬经度
  366. if (data && data.points.length >= 1) {
  367. let geoType = null;
  368. // 类型: 0 点;1 线;2 面;3 矩形;4 圆形;5 其他;
  369. if (data.points.length === 1 && data.area === 0) {
  370. geoType = 0;
  371. }
  372. if (data.points.length === 2 && data.distance > 0) {
  373. geoType = 4;
  374. }
  375. if (data.points.length > 2 && data.area === 0) {
  376. geoType = 1;
  377. }
  378. if (data.points.length > 2 && data.area != 0 && data.area != "") {
  379. geoType = 2;
  380. }
  381. let coord = data.points[data.points.length - 1];
  382. if (coord && coord.length >= 2) {
  383. let newCoord = { lat: coord[0], lng: coord[1] };
  384. this.labelDetailsPopupShow = true;
  385. this.labelPopup = L.popup({ maxWidth: 700, maxHeight: 600 })
  386. .setLatLng(newCoord)
  387. .setContent(this.createLabelDiv("label", coord, data, geoType))
  388. .openOn(map2DViewer.map);
  389. this.labelDetailsPopupShow = false;
  390. }
  391. }
  392. };
  393. map2DViewer.setDrawTool({
  394. action: "add",
  395. offset: [150, 50],
  396. background: "#fff",
  397. color: "red",
  398. font_size: "14px",
  399. closeButton: true,
  400. iconUrl: "../../static/plugins/draw-plugin/images/marker-icon.png"
  401. });
  402. }
  403. },
  404. mapInit: function () {
  405. // var crs = new L.Proj.CRS(
  406. // "EPSG:2401",
  407. // "+proj=tmerc +lat_0=0 +lon_0=121.2751921 +k=1 +x_0=0 +y_0=-3457147.81 +ellps=krass +units=m +no_defs",
  408. // {
  409. // resolutions: [
  410. // 529.1666666666666, 264.5833333333333, 132.29166666666666, 52.916666666666664, 26.458333333333332,
  411. // 13.229166666666666, 5.291666666666666, 2.645833333333333, 1.3229166666666665, 0.5291666666666666,
  412. // 0.2645833333333333, 0.13229166666666664
  413. // ],
  414. // origin: [-66000, 75000],
  415. // bounds: L.bounds([-65000, -76000], [75000, 72000])
  416. // }
  417. // );
  418. map2DViewer.map = L.map("map2DViewer", {
  419. // crs: crs,
  420. // center: [31.074472887639914, 121.72521988031804],
  421. // zoom: 1,
  422. // minZoom: 1,
  423. // maxZoom: 12
  424. attributionControl: false,
  425. zoomControl: false,
  426. minZoom: 10,
  427. maxZoom: 16
  428. }).setView(systemConfig.mapViewer.center, systemConfig.mapViewer.zoom);
  429. //添加默认图层
  430. let guid = publicFun.buildGuid("baseLayer");
  431. let layer = L.esri
  432. .tiledMapLayer({
  433. url:
  434. // systemConfig.mapService +
  435. // "?servertype=Street_Purplish_Blue&token=" +
  436. // systemConfig.token,
  437. // url: "http://aimap.pudong.sh:5236/maps/rest/services/basemap-shanghai-gem-blue-sh2000/mapserver",
  438. // tileSize: 512
  439. systemConfig.blueBlackMap
  440. })
  441. .addTo(map2DViewer.map);
  442. // layer.setStyle({opacity:0,fillOpacity:0})
  443. map2DViewer.layers["darkmap"] = layer;
  444. // 加载天地图
  445. let imageryLayer = L.tileLayer(systemConfig.imageryLayer);
  446. map2DViewer.layers["imagery"] = imageryLayer;
  447. },
  448. // 传入街道参数,重新渲染区域图层
  449. getJSonDataToStreet(url, param) {
  450. // 先删除历史图层
  451. if (map2DViewer.map.hasLayer(map2DViewer.groups["浦东新区_polygon"])) {
  452. map2DViewer.groups["浦东新区_label"].remove();
  453. map2DViewer.groups["浦东新区_polygon"].remove();
  454. }
  455. // 请求并渲染新的区域图层
  456. get("./static/json/simplified_pdgeojson.json", "").then(geoJson => {
  457. // 存放所有的面数据
  458. map2DViewer.groups["浦东新区_polygon"] = L.featureGroup();
  459. map2DViewer.groups["浦东新区_label"] = L.featureGroup();
  460. map2DViewer.groups["浦东新区_polygon"].addTo(map2DViewer.map);
  461. map2DViewer.groups["浦东新区_label"].addTo(map2DViewer.map);
  462. geoJson.features.map(feature => {
  463. if (this.town.indexOf(feature.properties.NAME.replace("镇", "")) > -1) {
  464. this.renderPolygon(feature);
  465. }
  466. });
  467. });
  468. },
  469. // 可视化单一的镇域面
  470. getSingleJsonData(name) {},
  471. // 默认获取浦东新区全区的图层数据
  472. getJSonData() {
  473. if (!map2DViewer.map) {
  474. this.mapInit();
  475. } else if (
  476. // 切换到首页和疑点筛查页且图层不存在时重新渲染区域图
  477. (this.$ifMenu("1", "") || this.$ifMenu("2", "")) &&
  478. !map2DViewer.map.hasLayer(map2DViewer.groups["浦东新区_polygon"])
  479. ) {
  480. this.getJSonDataToStreet("", "");
  481. } else if (
  482. !(this.$ifMenu("1", "") || this.$ifMenu("2", "")) &&
  483. map2DViewer.map.hasLayer(map2DViewer.groups["浦东新区_polygon"])
  484. ) {
  485. // 当前页不是首页和疑点筛查页时移除区域图且图层存在时
  486. map2DViewer.groups["浦东新区_label"].remove();
  487. map2DViewer.groups["浦东新区_polygon"].remove();
  488. }
  489. },
  490. setView: function (coord, zoom) {
  491. // console.log(coord, "位置");
  492. let center = L.latLng(coord[0], coord[1]);
  493. map2DViewer.map.setView(center, zoom);
  494. },
  495. renderPolygon: function (feature) {
  496. let center = turf.center(feature.geometry);
  497. // let itemvalue = JSON.parse((Math.random() * 1000).toFixed(0));
  498. let name = feature.properties.NAME;
  499. let polygonData = JSON.parse(JSON.stringify(feature));
  500. let coordinates = polygonData.geometry.coordinates[0];
  501. // 几何体
  502. let polygon = L.polygon(this.latLngsToReverse(coordinates), {
  503. color: "#87d8fd",
  504. weight: 3,
  505. fillColor: this.getColor(name),
  506. opacity: 1,
  507. fillOpacity: 0.4
  508. }).addTo(map2DViewer.groups["浦东新区_polygon"]);
  509. center = JSON.parse(JSON.stringify(center)).geometry.coordinates;
  510. center.reverse();
  511. // 坐标
  512. townLocationMap.set(name, center);
  513. townPolygonMap.set(name, polygon);
  514. let wmarker = L.circleMarker(center, {
  515. radius: 10,
  516. weight: 1,
  517. fillOpacity: 0,
  518. color: "#e6d273"
  519. });
  520. wmarker.bindLabel(feature.properties.NAME, {
  521. noHide: true,
  522. clickable: true,
  523. offset: [-25, 10]
  524. });
  525. wmarker.addTo(map2DViewer.groups["浦东新区_label"]);
  526. let circle1 = L.circleMarker(center, {
  527. radius: 8,
  528. weight: 1,
  529. fillOpacity: 0,
  530. color: "#e6d273"
  531. }).addTo(map2DViewer.groups["浦东新区_polygon"]);
  532. let circle2 = L.circleMarker(center, {
  533. radius: 5,
  534. weight: 1,
  535. fillOpacity: 1,
  536. color: "#e6d273"
  537. }).addTo(map2DViewer.groups["浦东新区_polygon"]);
  538. },
  539. latLngsToReverse: function (latlngsAry) {
  540. var tempLatlngsAry = JSON.parse(JSON.stringify(latlngsAry));
  541. if (typeof tempLatlngsAry[0] != "object") {
  542. return tempLatlngsAry.reverse();
  543. } else {
  544. for (var i = 0, l = tempLatlngsAry.length; i < l; i++) {
  545. tempLatlngsAry[i] = this.latLngsToReverse(tempLatlngsAry[i]);
  546. }
  547. }
  548. return tempLatlngsAry;
  549. },
  550. getColor(name) {
  551. if (townData.A.indexOf(name) > -1) {
  552. return "#e565ff";
  553. } else if (townData.B.indexOf(name) > -1) {
  554. return "#0055ff";
  555. } else if (townData.C.indexOf(name) > -1) {
  556. return "#00ffd5";
  557. }
  558. },
  559. addSinglePolygon(geometry, cid, color, uniqueId) {
  560. let uniqueIdList = [];
  561. if (this.$store.state.selectSelectDataMap["singlePolygon"][uniqueId]) {
  562. uniqueIdList = this.$store.state.selectSelectDataMap["singlePolygon"][uniqueId];
  563. }
  564. let singlePolygonItem = {
  565. uniqueId: uniqueId,
  566. geometry: geometry,
  567. cid: cid
  568. };
  569. uniqueIdList.push(singlePolygonItem);
  570. this.$store.state.selectSelectDataMap["singlePolygon"][uniqueId] = uniqueIdList;
  571. let coordinates = "";
  572. if (uniqueId === "一般耕地_47") {
  573. let coord = JSON.parse(geometry).geometry.coordinates[0];
  574. coordinates = coord.map(v => {
  575. return [v[1], v[0]];
  576. });
  577. } else {
  578. coordinates = JSON.parse(geometry).geometry.coordinates[0];
  579. coordinates = coordinates.map(v => {
  580. let data = transformCoord.shcj_to_wgs84(v[1], [v[0]]);
  581. data = [data[1], data[0]];
  582. return data;
  583. });
  584. }
  585. // if(){
  586. // }
  587. let properties = JSON.parse(geometry).properties;
  588. // 纬经度
  589. // [22474.568725585938, -16689.47381591797]
  590. // x,y转换
  591. let polygon = L.polygon(coordinates, {
  592. color: color,
  593. weight: 3,
  594. fillColor: color,
  595. opacity: 1,
  596. fillOpacity: 0.4
  597. }).addTo(map2DViewer.analysisGroups[uniqueId]);
  598. polygon.on("click", e => {
  599. this.auditPopupShow = true;
  600. this.popup = L.popup({ maxWidth: 700, maxHeight: 600 })
  601. .setLatLng(e.latlng)
  602. .setContent(this.createAuditDiv(cid, properties));
  603. this.auditPopupShow = false;
  604. this.popup.openOn(map2DViewer.map);
  605. this.currentCid = cid;
  606. this.currentProperties = properties;
  607. });
  608. },
  609. // 综合分析 - 图层绘制面
  610. addPolygonLayer(data, cid, color) {
  611. data.map(feature => {
  612. let polygonData = JSON.parse(JSON.stringify(feature));
  613. let coordinates = polygonData.geometry.coordinates[0];
  614. let infos = polygonData.properties;
  615. let polygon = L.polygon(coordinates, {
  616. color: color,
  617. weight: 3,
  618. fillColor: color,
  619. opacity: 1,
  620. fillOpacity: 0.4
  621. }).addTo(map2DViewer.map);
  622. map2DViewer.polygons[`${cid}_layer`].push(polygon);
  623. polygon.infos = infos;
  624. polygon.on("click", e => {
  625. // console.log(e, "polygon");
  626. this.auditPopupShow = true;
  627. // console.log(e.latlng, "获取当前弹窗坐标111");
  628. this.popup = L.popup({ maxWidth: 700, maxHeight: 600 }).setLatLng(e.latlng).setContent(this.createAuditDiv(cid));
  629. // .openOn(map2DViewer.map);
  630. this.auditPopupShow = false;
  631. this.popup.openOn(map2DViewer.map);
  632. this.currentCid = cid;
  633. });
  634. });
  635. },
  636. deleteSinglePolygon(polygon) {
  637. map2DViewer.map.removeLayer(polygon);
  638. },
  639. // 综合分析 - 图层显示
  640. deleteGroupFromMap(uniqueId) {
  641. if (map2DViewer.analysisGroups[uniqueId]) {
  642. map2DViewer.map.removeLayer(map2DViewer.analysisGroups[uniqueId]);
  643. }
  644. },
  645. //综合分析 - 标记疑点 - 删除面
  646. deletePolygonLayer(layer) {
  647. console.log(layer, "layer");
  648. map2DViewer.polygons[layer].forEach(polygon => {
  649. map2DViewer.map.removeLayer(polygon);
  650. });
  651. },
  652. drawPoints(data) {
  653. this.setView(data.coord, 16);
  654. if (!map2DViewer.myLabels[`label_${data.id}`]) {
  655. // console.log("开始绘制点", data);
  656. let point = L.marker(data.coord, {
  657. opacity: 1
  658. }).addTo(map2DViewer.map);
  659. map2DViewer.myLabels[`label_${data.id}`] = point;
  660. }
  661. },
  662. drawLine(data, color) {
  663. if (!map2DViewer.myLabels[`label_${data.id}`]) {
  664. // console.log("开始绘制线", data);
  665. let coordinates = JSON.parse(data.geojson).geometry.coordinates[0];
  666. let polyline = L.polyline(coordinates, {
  667. color: color,
  668. weight: 3,
  669. fillOpacity: color,
  670. opacity: 1,
  671. fillOpacity: 0.4
  672. }).addTo(map2DViewer.map);
  673. // zoom the map to the polyline
  674. map2DViewer.map.fitBounds(polyline.getBounds());
  675. map2DViewer.myLabels[`label_${data.id}`] = polyline;
  676. } else {
  677. map2DViewer.map.fitBounds(map2DViewer.myLabels[`label_${data.id}`].getBounds());
  678. }
  679. },
  680. drawPolygon(data, color) {
  681. if (!map2DViewer.myLabels[`label_${data.id}`]) {
  682. console.log("开始绘制面", data);
  683. let coordinates = JSON.parse(data.geojson).geometry.coordinates[0];
  684. let polygon = L.polygon(coordinates, {
  685. color: color,
  686. weight: 3,
  687. fillOpacity: color,
  688. opacity: 1,
  689. fillOpacity: 0.4
  690. }).addTo(map2DViewer.map);
  691. map2DViewer.map.fitBounds(polygon.getBounds());
  692. map2DViewer.myLabels[`label_${data.id}`] = polygon;
  693. } else {
  694. map2DViewer.map.fitBounds(map2DViewer.myLabels[`label_${data.id}`].getBounds());
  695. }
  696. },
  697. drawCircle(data, color) {
  698. if (!map2DViewer.myLabels[`label_${data.id}`]) {
  699. console.log("开始绘制圆", data);
  700. let coordinates = JSON.parse(data.geojson).geometry.coordinates[0];
  701. // console.log(coordinates);
  702. if ((coordinates.length = 2)) {
  703. let from = turf.point(coordinates[0].reverse());
  704. let to = turf.point(coordinates[1].reverse());
  705. let options = { units: "kilometers" };
  706. let distance = turf.distance(from, to, options);
  707. (distance = parseFloat(distance * 1000).toFixed(6)), console.log(distance, "圆的半径");
  708. let circle = L.circle(coordinates[0].reverse(), {
  709. color: color,
  710. weight: 3,
  711. fillOpacity: color,
  712. opacity: 1,
  713. fillOpacity: 0.4,
  714. radius: Number(distance)
  715. }).addTo(map2DViewer.map);
  716. console.log(circle);
  717. map2DViewer.map.fitBounds(circle.getBounds());
  718. map2DViewer.myLabels[`label_${data.id}`] = circle;
  719. }
  720. } else {
  721. map2DViewer.map.fitBounds(map2DViewer.myLabels[`label_${data.id}`].getBounds());
  722. }
  723. },
  724. /**
  725. * 综合分析 -- 我的标记 -- 绘制单一几何体方法
  726. * @type 判断需要绘制的几何体类型
  727. */
  728. drawGeometry(type, data) {
  729. let color = "#ff0000";
  730. switch (type) {
  731. case "点":
  732. this.drawPoints(data);
  733. break;
  734. case "线":
  735. this.drawLine(data, color);
  736. break;
  737. case "面":
  738. this.drawPolygon(data, color);
  739. break;
  740. case "圆":
  741. this.drawCircle(data, color);
  742. break;
  743. }
  744. },
  745. deleteGeometry(geometry) {
  746. if (geometry) {
  747. console.log(geometry, "移除");
  748. geometry.removeFrom(map2DViewer.map);
  749. }
  750. }
  751. }
  752. };
  753. </script>
  754. <style lang="less" scoped>
  755. #map2DViewer {
  756. position: absolute;
  757. width: 100%;
  758. height: calc(100% - 60px);
  759. background-color: #003452;
  760. z-index: 1;
  761. top: 60px;
  762. left: 0px;
  763. }
  764. </style>